2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
5 Function to write defines/modulename.h. Part of genmodule.
9 static void writedefineregister(FILE *, struct functionhead
*, struct config
*);
10 static void writedefinevararg(FILE *, struct functionhead
*, struct config
*);
11 static void writealiases(FILE *, struct functionhead
*, struct config
*);
13 void writeincdefines(struct config
*cfg
)
16 char line
[256], *banner
;
17 struct functionhead
*funclistit
;
19 snprintf(line
, 255, "%s/defines/%s.h", cfg
->gendir
, cfg
->includename
);
20 out
= fopen(line
, "w");
28 banner
= getBanner(cfg
);
30 "#ifndef DEFINES_%s_H\n"
31 "#define DEFINES_%s_H\n"
36 " Desc: Defines for %s\n"
39 "#include <aros/libcall.h>\n"
40 "#include <exec/types.h>\n"
41 "#include <aros/symbolsets.h>\n"
42 "#include <aros/preprocessor/variadic/cast2iptr.hpp>\n"
46 cfg
->includenameupper
, cfg
->includenameupper
, banner
, cfg
->modulename
50 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
52 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
56 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
58 cfg
->includenameupper
,
63 writedefineregister(out
, funclistit
, cfg
);
64 if (!funclistit
->novararg
)
65 writedefinevararg(out
, funclistit
, cfg
);
67 writealiases(out
, funclistit
, cfg
);
71 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
73 cfg
->includenameupper
,
84 "#endif /* DEFINES_%s_H*/\n",
92 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
94 struct functionarg
*arglistit
;
95 int count
, isvoid
, nquad
= 0, narg
= 0;
98 isvoid
= strcmp(funclistit
->type
, "void") == 0
99 || strcmp(funclistit
->type
, "VOID") == 0;
103 "#define __%s_WB(__%s",
104 funclistit
->name
, cfg
->libbase
106 for (arglistit
= funclistit
->arguments
, count
= 1;
108 arglistit
= arglistit
->next
, count
++
111 fprintf(out
, ", __arg%d", count
);
112 if (strchr(arglistit
->reg
, '/') != NULL
) {
122 " AROS_LIBREQ(%s,%d)\\\n",
123 cfg
->libbase
, funclistit
->version
128 " AROS_LC%d%s%s(%s, %s, \\\n",
129 funclistit
->argcount
, funclistit
->unusedlibbase
? "I" : "",
130 (isvoid
) ? "NR" : "",
131 funclistit
->type
, funclistit
->name
134 for (arglistit
= funclistit
->arguments
, count
= 1;
136 arglistit
= arglistit
->next
, count
++
139 type
= getargtype(arglistit
);
140 assert(type
!= NULL
);
142 " AROS_LCA(%s,(__arg%d),%s), \\\n",
143 type
, count
, arglistit
->reg
152 " AROS_LC%dQUAD%d%s(%s, %s,\\\n",
153 narg
, nquad
, (isvoid
) ? "NR" : "",
154 funclistit
->type
, funclistit
->name
158 " AROS_LCQUAD%d%s(%s, %s,\\\n",
159 nquad
, (isvoid
) ? "NR" : "",
160 funclistit
->type
, funclistit
->name
164 for (arglistit
= funclistit
->arguments
, count
= 1;
166 arglistit
= arglistit
->next
, count
++
169 char *quad2
= strchr(arglistit
->reg
, '/');
171 arglistit
->reg
[2] = 0;
172 type
= getargtype(arglistit
);
173 assert(type
!= NULL
);
178 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
179 type
, count
, arglistit
->reg
, quad2
+1
184 " AROS_LCA(%s, (__arg%d), %s), \\\n",
185 type
, count
, arglistit
->reg
192 " %s, (__%s), %u, %s);\\\n})\n\n",
193 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
196 fprintf(out
, "#define %s(", funclistit
->name
);
197 for (arglistit
= funclistit
->arguments
, count
= 1;
199 arglistit
= arglistit
->next
, count
++
202 if (arglistit
!= funclistit
->arguments
)
204 fprintf(out
, "arg%d", count
);
206 fprintf(out
, ") \\\n __%s_WB(__aros_getbase_%s()",
207 funclistit
->name
, cfg
->libbase
209 for (arglistit
= funclistit
->arguments
, count
= 1;
211 arglistit
= arglistit
->next
, count
++
213 fprintf(out
, ", (arg%d)", count
);
218 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
220 struct functionarg
*arglistit
= funclistit
->arguments
;
221 char isvararg
= 0, *varargname
, *lastname
;
223 /* Go to last argument */
224 if (arglistit
== NULL
)
227 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
229 lastname
= getargname(arglistit
);
230 assert(lastname
!= NULL
);
232 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
235 varargname
= strdup(funclistit
->name
);
236 varargname
[strlen(funclistit
->name
)-1] = '\0';
238 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
241 /* TagList has to be changed in Tags at the end of the functionname */
242 varargname
= strdup(funclistit
->name
);
243 varargname
[strlen(funclistit
->name
)-4] = 's';
244 varargname
[strlen(funclistit
->name
)-3] = '\0';
246 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
247 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
251 varargname
= strdup(funclistit
->name
);
252 varargname
[strlen(funclistit
->name
)-4] = '\0';
254 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
257 varargname
= malloc(strlen(funclistit
->name
));
258 strcpy(varargname
, &funclistit
->name
[1]);
264 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
265 p
= arglistit
->arg
+ 5;
266 while (isspace(*p
)) p
++;
269 if (strncmp(p
, "struct", 6)==0)
272 while (isspace(*p
)) p
++;
273 if (strncmp(p
, "TagItem", 7) == 0)
276 while (isspace(*p
)) p
++;
281 varargname
= malloc(strlen(funclistit
->name
) + 5);
282 strcpy(varargname
, funclistit
->name
);
283 strcat(varargname
, "Tags");
295 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
297 cfg
->includenameupper
, varargname
299 for (arglistit
= funclistit
->arguments
, count
= 1;
300 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
301 arglistit
= arglistit
->next
, count
++
304 fprintf(out
, "arg%d, ", count
);
312 for (arglistit
= funclistit
->arguments
, count
= 1;
314 arglistit
= arglistit
->next
, count
++
317 if (arglistit
!= funclistit
->arguments
)
320 if (arglistit
->next
== NULL
)
322 type
= getargtype(arglistit
);
323 assert(type
!= NULL
);
324 fprintf(out
, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
328 fprintf(out
, "(arg%d)", count
);
333 "#endif /* !NO_INLINE_STDARG */\n"
338 else if (isvararg
== 2)
341 struct functionarg
*lastarg
;
344 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
345 "static inline %s __%s_WB(%s __%s",
346 cfg
->includenameupper
,
347 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
349 for (arglistit
= funclistit
->arguments
;
350 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
351 arglistit
= arglistit
->next
354 fprintf(out
, ", %s", arglistit
->arg
);
357 fprintf(out
, ", ...)\n");
364 " va_start(args, %s);\n"
365 " retval = __%s_WB(__%s, ",
368 funclistit
->name
, cfg
->libbase
370 for (arglistit
= funclistit
->arguments
;
371 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
372 arglistit
= arglistit
->next
375 fprintf(out
, "%s, ", getargname(arglistit
));
385 for (arglistit
= funclistit
->arguments
, count
= 1;
386 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
387 arglistit
= arglistit
->next
, count
++
390 fprintf(out
, "arg%d, ", count
);
394 varargname
, cfg
->libbase
396 for (arglistit
= funclistit
->arguments
, count
= 1;
397 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
398 arglistit
= arglistit
->next
, count
++
401 fprintf(out
, "(arg%d), ", count
);
405 "#endif /* !NO_INLINE_STDARG */\n"
413 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
415 struct stringlist
*aliasesit
;
417 for (aliasesit
= funclistit
->aliases
;
419 aliasesit
= aliasesit
->next
422 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);