2 Copyright © 1995-2016, 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
*, char);
10 static void writedefinevararg(FILE *, struct functionhead
*, struct config
*, char, char *);
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
)
54 char isvararg
= 0, *varargname
= NULL
, *lastname
;
58 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
60 cfg
->includenameupper
,
65 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
67 struct functionarg
*arglistit
= funclistit
->arguments
;
69 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
71 lastname
= getargname(arglistit
);
72 assert(lastname
!= NULL
);
74 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
77 varargname
= strdup(funclistit
->name
);
78 varargname
[strlen(funclistit
->name
)-1] = '\0';
79 if (arglistit
&& strncmp(arglistit
->arg
, "RAWARG",6) == 0)
82 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
85 /* TagList has to be changed to Tags at the end of the functionname */
86 varargname
= strdup(funclistit
->name
);
87 varargname
[strlen(funclistit
->name
)-4] = 's';
88 varargname
[strlen(funclistit
->name
)-3] = '\0';
90 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
91 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
95 varargname
= strdup(funclistit
->name
);
96 varargname
[strlen(funclistit
->name
)-4] = '\0';
98 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
101 varargname
= malloc(strlen(funclistit
->name
));
102 strcpy(varargname
, &funclistit
->name
[1]);
104 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "RAWARG", 6) == 0))
107 varargname
= malloc(strlen(funclistit
->name
));
108 strcpy(varargname
, &funclistit
->name
[1]);
114 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
115 p
= arglistit
->arg
+ 5;
116 while (isspace(*p
)) p
++;
119 if (strncmp(p
, "struct", 6)==0)
122 while (isspace(*p
)) p
++;
123 if (strncmp(p
, "TagItem", 7) == 0)
126 while (isspace(*p
)) p
++;
131 varargname
= malloc(strlen(funclistit
->name
) + 5);
132 strcpy(varargname
, funclistit
->name
);
133 strcat(varargname
, "Tags");
140 writedefineregister(out
, funclistit
, cfg
, isvararg
);
141 if (!funclistit
->novararg
&& isvararg
)
143 writedefinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
146 writealiases(out
, funclistit
, cfg
);
150 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
152 cfg
->includenameupper
,
154 cfg
->includenameupper
163 "#endif /* DEFINES_%s_H*/\n",
164 cfg
->includenameupper
170 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
172 struct functionarg
*arglistit
;
173 int count
, isvoid
, nquad
= 0, narg
= 0;
176 isvoid
= strcmp(funclistit
->type
, "void") == 0
177 || strcmp(funclistit
->type
, "VOID") == 0;
181 "#define __%s_WB(__%s",
182 funclistit
->name
, cfg
->libbase
184 for (arglistit
= funclistit
->arguments
, count
= 1;
186 arglistit
= arglistit
->next
, count
++
189 fprintf(out
, ", __arg%d", count
);
190 if (strchr(arglistit
->reg
, '/') != NULL
) {
200 " AROS_LIBREQ(%s,%d)\\\n",
201 cfg
->libbase
, funclistit
->version
206 " AROS_LC%d%s%s(%s, %s, \\\n",
207 funclistit
->argcount
, funclistit
->unusedlibbase
? "I" : "",
208 (isvoid
) ? "NR" : "",
209 funclistit
->type
, funclistit
->name
212 for (arglistit
= funclistit
->arguments
, count
= 1;
214 arglistit
= arglistit
->next
, count
++
217 type
= getargtype(arglistit
);
218 assert(type
!= NULL
);
220 " AROS_LCA(%s%s,(__arg%d),%s), \\\n",
221 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
222 type
, count
, arglistit
->reg
231 " AROS_LC%dQUAD%d%s(%s, %s,\\\n",
232 narg
, nquad
, (isvoid
) ? "NR" : "",
233 funclistit
->type
, funclistit
->name
237 " AROS_LCQUAD%d%s(%s, %s,\\\n",
238 nquad
, (isvoid
) ? "NR" : "",
239 funclistit
->type
, funclistit
->name
243 for (arglistit
= funclistit
->arguments
, count
= 1;
245 arglistit
= arglistit
->next
, count
++
248 char *quad2
= strchr(arglistit
->reg
, '/');
250 arglistit
->reg
[2] = 0;
251 type
= getargtype(arglistit
);
252 assert(type
!= NULL
);
257 " AROS_LCAQUAD(%s%s, (__arg%d), %s, %s), \\\n",
258 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
259 type
, count
, arglistit
->reg
, quad2
+1
264 " AROS_LCA(%s%s, (__arg%d), %s), \\\n",
265 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
266 type
, count
, arglistit
->reg
273 " %s, (__%s), %u, %s);\\\n})\n\n",
274 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
277 fprintf(out
, "#define %s(", funclistit
->name
);
278 for (arglistit
= funclistit
->arguments
, count
= 1;
280 arglistit
= arglistit
->next
, count
++
283 if (arglistit
!= funclistit
->arguments
)
285 fprintf(out
, "arg%d", count
);
287 fprintf(out
, ") \\\n __%s_WB(__aros_getbase_%s()",
288 funclistit
->name
, cfg
->libbase
290 for (arglistit
= funclistit
->arguments
, count
= 1;
292 arglistit
= arglistit
->next
, count
++
294 fprintf(out
, ", (arg%d)", count
);
299 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
301 struct functionarg
*arglistit
= funclistit
->arguments
;
304 isvoid
= strcmp(funclistit
->type
, "void") == 0
305 || strcmp(funclistit
->type
, "VOID") == 0;
313 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
315 cfg
->includenameupper
, varargname
317 for (arglistit
= funclistit
->arguments
, count
= 1;
318 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
319 arglistit
= arglistit
->next
, count
++
322 fprintf(out
, "arg%d, ", count
);
330 for (arglistit
= funclistit
->arguments
, count
= 1;
332 arglistit
= arglistit
->next
, count
++
335 if (arglistit
!= funclistit
->arguments
)
338 if (arglistit
->next
== NULL
)
340 type
= getargtype(arglistit
);
341 assert(type
!= NULL
);
342 fprintf(out
, "(const %s)(const IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
346 fprintf(out
, "(arg%d)", count
);
351 "#endif /* !NO_INLINE_STDARG */\n"
354 else if (isvararg
== 2)
357 struct functionarg
*lastarg
;
360 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
361 "static inline %s __%s_WB(%s __%s",
362 cfg
->includenameupper
,
363 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
365 for (arglistit
= funclistit
->arguments
;
366 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
367 arglistit
= arglistit
->next
370 fprintf(out
, ", %s", arglistit
->arg
);
373 fprintf(out
, ", ...)\n");
380 " va_start(args, %s);\n"
381 " retval = __%s_WB(__%s, ",
384 funclistit
->name
, cfg
->libbase
386 for (arglistit
= funclistit
->arguments
;
387 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
388 arglistit
= arglistit
->next
391 fprintf(out
, "%s, ", getargname(arglistit
));
401 for (arglistit
= funclistit
->arguments
, count
= 1;
402 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
403 arglistit
= arglistit
->next
, count
++
406 fprintf(out
, "arg%d, ", count
);
410 varargname
, cfg
->libbase
412 for (arglistit
= funclistit
->arguments
, count
= 1;
413 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
414 arglistit
= arglistit
->next
, count
++
417 fprintf(out
, "(arg%d), ", count
);
421 "#endif /* !NO_INLINE_STDARG */\n"
424 else if (isvararg
== 3)
429 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
430 "static inline %s __inline_%s_%s(%s __%s",
431 cfg
->includenameupper
,
432 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
434 for (arglistit
= funclistit
->arguments
, count
= 0;
435 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
436 arglistit
= arglistit
->next
439 char *type
= getargtype(arglistit
);
441 fprintf(out
, ", %s __arg%d", type
, ++count
);
443 fprintf(out
, ", ...)\n");
447 fprintf(out
, " %s retval;\n\n", funclistit
->type
);
450 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
453 isvoid
? "" : "retval = ",
457 for (arglistit
= funclistit
->arguments
, count
= 1;
458 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
459 arglistit
= arglistit
->next
, count
++
462 fprintf(out
, ", __arg%d", count
);
466 ", AROS_SLOWSTACKFORMAT_ARG(__arg%d));\n"
467 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
474 isvoid
? "" : " retval",
477 for (arglistit
= funclistit
->arguments
, count
= 1;
478 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
479 arglistit
= arglistit
->next
, count
++
482 fprintf(out
, "arg%d, ", count
);
486 " __inline_%s_%s((%s)(%s), ",
487 cfg
->basename
, varargname
,
488 cfg
->libbasetypeptrextern
,
491 for (arglistit
= funclistit
->arguments
, count
= 1;
492 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
493 arglistit
= arglistit
->next
, count
++
496 fprintf(out
, "(arg%d), ", count
);
500 "#endif /* !NO_INLINE_STDARG */\n"
506 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
508 struct stringlist
*aliasesit
;
510 for (aliasesit
= funclistit
->aliases
;
512 aliasesit
= aliasesit
->next
515 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);