2 Copyright © 1995-2017, 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"
44 "#if !defined(__%s_LIBBASE)\n"
45 "# if !defined(__NOLIBBASE__) && !defined(__%s_NOLIBBASE__)\n"
46 "# define __%s_LIBBASE __aros_getbase_%s()\n"
48 "# define __%s_LIBBASE %s\n"
54 cfg
->includenameupper
, cfg
->includenameupper
, banner
, cfg
->modulename
,
55 cfg
->includenameupper
, cfg
->includenameupper
,
56 cfg
->includenameupper
, cfg
->libbase
,
57 cfg
->includenameupper
, cfg
->libbase
61 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
63 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
65 char isvararg
= 0, *varargname
= NULL
, *lastname
;
69 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
71 cfg
->includenameupper
,
76 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
78 struct functionarg
*arglistit
= funclistit
->arguments
;
80 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
82 lastname
= getargname(arglistit
);
83 assert(lastname
!= NULL
);
85 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
88 varargname
= strdup(funclistit
->name
);
89 varargname
[strlen(funclistit
->name
)-1] = '\0';
90 if (arglistit
&& strncmp(arglistit
->arg
, "RAWARG",6) == 0)
93 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
96 /* TagList has to be changed to Tags at the end of the functionname */
97 varargname
= strdup(funclistit
->name
);
98 varargname
[strlen(funclistit
->name
)-4] = 's';
99 varargname
[strlen(funclistit
->name
)-3] = '\0';
101 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
102 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
106 varargname
= strdup(funclistit
->name
);
107 varargname
[strlen(funclistit
->name
)-4] = '\0';
109 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
112 varargname
= malloc(strlen(funclistit
->name
));
113 strcpy(varargname
, &funclistit
->name
[1]);
115 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "RAWARG", 6) == 0))
118 varargname
= malloc(strlen(funclistit
->name
));
119 strcpy(varargname
, &funclistit
->name
[1]);
125 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
126 p
= arglistit
->arg
+ 5;
127 while (isspace(*p
)) p
++;
130 if (strncmp(p
, "struct", 6)==0)
133 while (isspace(*p
)) p
++;
134 if (strncmp(p
, "TagItem", 7) == 0)
137 while (isspace(*p
)) p
++;
142 varargname
= malloc(strlen(funclistit
->name
) + 5);
143 strcpy(varargname
, funclistit
->name
);
144 strcat(varargname
, "Tags");
151 writedefineregister(out
, funclistit
, cfg
, isvararg
);
152 if (!funclistit
->novararg
&& isvararg
)
154 writedefinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
157 writealiases(out
, funclistit
, cfg
);
161 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
163 cfg
->includenameupper
,
165 cfg
->includenameupper
174 "#endif /* DEFINES_%s_H*/\n",
175 cfg
->includenameupper
181 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
183 struct functionarg
*arglistit
;
184 int count
, isvoid
, nquad
= 0, narg
= 0;
187 isvoid
= strcmp(funclistit
->type
, "void") == 0
188 || strcmp(funclistit
->type
, "VOID") == 0;
192 "#define __%s_WB(__%s",
193 funclistit
->name
, cfg
->libbase
195 for (arglistit
= funclistit
->arguments
, count
= 1;
197 arglistit
= arglistit
->next
, count
++
200 fprintf(out
, ", __arg%d", count
);
201 if (strchr(arglistit
->reg
, '/') != NULL
) {
211 " AROS_LIBREQ(%s,%d)\\\n",
212 cfg
->libbase
, funclistit
->version
217 " AROS_LC%d%s%s(%s, %s, \\\n",
218 funclistit
->argcount
, funclistit
->unusedlibbase
? "I" : "",
219 (isvoid
) ? "NR" : "",
220 funclistit
->type
, funclistit
->name
223 for (arglistit
= funclistit
->arguments
, count
= 1;
225 arglistit
= arglistit
->next
, count
++
228 type
= getargtype(arglistit
);
229 assert(type
!= NULL
);
231 " AROS_LCA(%s,(__arg%d),%s), \\\n",
232 type
, count
, arglistit
->reg
241 " AROS_LC%dQUAD%d%s(%s, %s,\\\n",
242 narg
, nquad
, (isvoid
) ? "NR" : "",
243 funclistit
->type
, funclistit
->name
247 " AROS_LCQUAD%d%s(%s, %s,\\\n",
248 nquad
, (isvoid
) ? "NR" : "",
249 funclistit
->type
, funclistit
->name
253 for (arglistit
= funclistit
->arguments
, count
= 1;
255 arglistit
= arglistit
->next
, count
++
258 char *quad2
= strchr(arglistit
->reg
, '/');
260 arglistit
->reg
[2] = 0;
261 type
= getargtype(arglistit
);
262 assert(type
!= NULL
);
267 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
268 type
, count
, arglistit
->reg
, quad2
+1
273 " AROS_LCA(%s, (__arg%d), %s), \\\n",
274 type
, count
, arglistit
->reg
281 " %s, (__%s), %u, %s);\\\n})\n\n",
282 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
285 fprintf(out
, "#define %s(", funclistit
->name
);
286 for (arglistit
= funclistit
->arguments
, count
= 1;
288 arglistit
= arglistit
->next
, count
++
291 if (arglistit
!= funclistit
->arguments
)
293 fprintf(out
, "arg%d", count
);
295 fprintf(out
, ") \\\n __%s_WB(__%s_LIBBASE",
296 funclistit
->name
, cfg
->includenameupper
298 for (arglistit
= funclistit
->arguments
, count
= 1;
300 arglistit
= arglistit
->next
, count
++
302 fprintf(out
, ", (arg%d)", count
);
307 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
309 struct functionarg
*arglistit
= funclistit
->arguments
;
312 isvoid
= strcmp(funclistit
->type
, "void") == 0
313 || strcmp(funclistit
->type
, "VOID") == 0;
321 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
323 cfg
->includenameupper
, varargname
325 for (arglistit
= funclistit
->arguments
, count
= 1;
326 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
327 arglistit
= arglistit
->next
, count
++
330 fprintf(out
, "arg%d, ", count
);
338 for (arglistit
= funclistit
->arguments
, count
= 1;
340 arglistit
= arglistit
->next
, count
++
343 if (arglistit
!= funclistit
->arguments
)
346 if (arglistit
->next
== NULL
)
348 type
= getargtype(arglistit
);
349 assert(type
!= NULL
);
350 fprintf(out
, "(%s)(const IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
354 fprintf(out
, "(arg%d)", count
);
359 "#endif /* !NO_INLINE_STDARG */\n"
362 else if (isvararg
== 2)
365 struct functionarg
*lastarg
;
368 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
369 "static inline %s __%s_WB(%s __%s",
370 cfg
->includenameupper
,
371 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
373 for (arglistit
= funclistit
->arguments
;
374 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
375 arglistit
= arglistit
->next
378 fprintf(out
, ", %s", arglistit
->arg
);
381 fprintf(out
, ", ...)\n");
388 " va_start(args, %s);\n"
389 " retval = __%s_WB(__%s, ",
392 funclistit
->name
, cfg
->libbase
394 for (arglistit
= funclistit
->arguments
;
395 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
396 arglistit
= arglistit
->next
399 fprintf(out
, "%s, ", getargname(arglistit
));
409 for (arglistit
= funclistit
->arguments
, count
= 1;
410 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
411 arglistit
= arglistit
->next
, count
++
414 fprintf(out
, "arg%d, ", count
);
418 varargname
, cfg
->libbase
420 fprintf(out
, "(%s)__%s_LIBBASE, ",
421 cfg
->libbasetypeptrextern
,
422 cfg
->includenameupper
);
423 for (arglistit
= funclistit
->arguments
, count
= 1;
424 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
425 arglistit
= arglistit
->next
, count
++
428 fprintf(out
, "(arg%d), ", count
);
432 "#endif /* !NO_INLINE_STDARG */\n"
435 else if (isvararg
== 3)
440 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
441 "static inline %s __inline_%s_%s(%s __%s",
442 cfg
->includenameupper
,
443 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
445 for (arglistit
= funclistit
->arguments
, count
= 0;
446 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
447 arglistit
= arglistit
->next
450 char *type
= getargtype(arglistit
);
452 fprintf(out
, ", %s __arg%d", type
, ++count
);
454 fprintf(out
, ", ...)\n");
458 fprintf(out
, " %s retval;\n\n", funclistit
->type
);
461 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
464 isvoid
? "" : "retval = ",
468 for (arglistit
= funclistit
->arguments
, count
= 1;
469 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
470 arglistit
= arglistit
->next
, count
++
473 fprintf(out
, ", __arg%d", count
);
477 ", AROS_SLOWSTACKFORMAT_ARG(__arg%d));\n"
478 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
485 isvoid
? "" : " retval",
488 for (arglistit
= funclistit
->arguments
, count
= 1;
489 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
490 arglistit
= arglistit
->next
, count
++
493 fprintf(out
, "arg%d, ", count
);
498 cfg
->basename
, varargname
500 fprintf(out
, "(%s)__%s_LIBBASE, ",
501 cfg
->libbasetypeptrextern
,
502 cfg
->includenameupper
);
503 for (arglistit
= funclistit
->arguments
, count
= 1;
504 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
505 arglistit
= arglistit
->next
, count
++
508 fprintf(out
, "(arg%d), ", count
);
512 "#endif /* !NO_INLINE_STDARG */\n"
518 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
520 struct stringlist
*aliasesit
;
522 for (aliasesit
= funclistit
->aliases
;
524 aliasesit
= aliasesit
->next
527 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);