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 cfg
->includenameupper
, cfg
->includenameupper
, banner
, cfg
->modulename
46 if ((cfg
->options
& OPTION_RELLINKLIB
) || (cfg
->options
& OPTION_DUPBASE
))
49 "#if !defined(__%s_LIBBASE)\n"
50 "# if !defined(__NOLIBBASE__) && !defined(__%s_NOLIBBASE__)\n"
51 "# define __%s_LIBBASE __aros_getbase_%s()\n"
53 "# define __%s_LIBBASE %s\n"
57 cfg
->includenameupper
, cfg
->includenameupper
,
58 cfg
->includenameupper
, cfg
->libbase
,
59 cfg
->includenameupper
, cfg
->libbase
64 "#if !defined(__%s_LIBBASE)\n"
65 "# define __%s_LIBBASE %s\n"
68 cfg
->includenameupper
,
69 cfg
->includenameupper
, cfg
->libbase
77 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
79 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
81 char isvararg
= 0, *varargname
= NULL
, *lastname
;
85 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
87 cfg
->includenameupper
,
92 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
94 struct functionarg
*arglistit
= funclistit
->arguments
;
96 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
98 lastname
= getargname(arglistit
);
99 assert(lastname
!= NULL
);
101 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
104 varargname
= strdup(funclistit
->name
);
105 varargname
[strlen(funclistit
->name
)-1] = '\0';
106 if (arglistit
&& strncmp(arglistit
->arg
, "RAWARG",6) == 0)
109 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
112 /* TagList has to be changed to Tags at the end of the functionname */
113 varargname
= strdup(funclistit
->name
);
114 varargname
[strlen(funclistit
->name
)-4] = 's';
115 varargname
[strlen(funclistit
->name
)-3] = '\0';
117 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
118 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
122 varargname
= strdup(funclistit
->name
);
123 varargname
[strlen(funclistit
->name
)-4] = '\0';
125 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
128 varargname
= malloc(strlen(funclistit
->name
));
129 strcpy(varargname
, &funclistit
->name
[1]);
131 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "RAWARG", 6) == 0))
134 varargname
= malloc(strlen(funclistit
->name
));
135 strcpy(varargname
, &funclistit
->name
[1]);
141 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
142 p
= arglistit
->arg
+ 5;
143 while (isspace(*p
)) p
++;
146 if (strncmp(p
, "struct", 6)==0)
149 while (isspace(*p
)) p
++;
150 if (strncmp(p
, "TagItem", 7) == 0)
153 while (isspace(*p
)) p
++;
158 varargname
= malloc(strlen(funclistit
->name
) + 5);
159 strcpy(varargname
, funclistit
->name
);
160 strcat(varargname
, "Tags");
167 writedefineregister(out
, funclistit
, cfg
, isvararg
);
168 if (!funclistit
->novararg
&& isvararg
)
170 writedefinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
173 writealiases(out
, funclistit
, cfg
);
177 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
179 cfg
->includenameupper
,
181 cfg
->includenameupper
190 "#endif /* DEFINES_%s_H*/\n",
191 cfg
->includenameupper
197 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
199 struct functionarg
*arglistit
;
200 int count
, isvoid
, nquad
= 0, narg
= 0;
203 isvoid
= strcmp(funclistit
->type
, "void") == 0
204 || strcmp(funclistit
->type
, "VOID") == 0;
208 "#define __%s_WB(__%s",
209 funclistit
->name
, cfg
->libbase
211 for (arglistit
= funclistit
->arguments
, count
= 1;
213 arglistit
= arglistit
->next
, count
++
216 fprintf(out
, ", __arg%d", count
);
217 if (strchr(arglistit
->reg
, '/') != NULL
) {
227 " AROS_LIBREQ(%s,%d)\\\n",
228 cfg
->libbase
, funclistit
->version
233 " AROS_LC%d%s%s(%s, %s, \\\n",
234 funclistit
->argcount
, funclistit
->unusedlibbase
? "I" : "",
235 (isvoid
) ? "NR" : "",
236 funclistit
->type
, funclistit
->name
239 for (arglistit
= funclistit
->arguments
, count
= 1;
241 arglistit
= arglistit
->next
, count
++
244 type
= getargtype(arglistit
);
245 assert(type
!= NULL
);
247 " AROS_LCA(%s,(__arg%d),%s), \\\n",
248 type
, count
, arglistit
->reg
257 " AROS_LC%dQUAD%d%s(%s, %s,\\\n",
258 narg
, nquad
, (isvoid
) ? "NR" : "",
259 funclistit
->type
, funclistit
->name
263 " AROS_LCQUAD%d%s(%s, %s,\\\n",
264 nquad
, (isvoid
) ? "NR" : "",
265 funclistit
->type
, funclistit
->name
269 for (arglistit
= funclistit
->arguments
, count
= 1;
271 arglistit
= arglistit
->next
, count
++
274 char *quad2
= strchr(arglistit
->reg
, '/');
276 arglistit
->reg
[2] = 0;
277 type
= getargtype(arglistit
);
278 assert(type
!= NULL
);
283 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
284 type
, count
, arglistit
->reg
, quad2
+1
289 " AROS_LCA(%s, (__arg%d), %s), \\\n",
290 type
, count
, arglistit
->reg
297 " %s, (__%s), %u, %s);\\\n})\n\n",
298 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
301 fprintf(out
, "#define %s(", funclistit
->name
);
302 for (arglistit
= funclistit
->arguments
, count
= 1;
304 arglistit
= arglistit
->next
, count
++
307 if (arglistit
!= funclistit
->arguments
)
309 fprintf(out
, "arg%d", count
);
311 fprintf(out
, ") \\\n __%s_WB(__%s_LIBBASE",
312 funclistit
->name
, cfg
->includenameupper
314 for (arglistit
= funclistit
->arguments
, count
= 1;
316 arglistit
= arglistit
->next
, count
++
318 fprintf(out
, ", (arg%d)", count
);
323 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
325 struct functionarg
*arglistit
= funclistit
->arguments
;
328 isvoid
= strcmp(funclistit
->type
, "void") == 0
329 || strcmp(funclistit
->type
, "VOID") == 0;
337 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
339 cfg
->includenameupper
, varargname
341 for (arglistit
= funclistit
->arguments
, count
= 1;
342 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
343 arglistit
= arglistit
->next
, count
++
346 fprintf(out
, "arg%d, ", count
);
352 for (arglistit
= funclistit
->arguments
, count
= 1;
354 arglistit
= arglistit
->next
, count
++
357 if (arglistit
->next
== NULL
)
359 fprintf(out
, " const IPTR %s_args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) };\\\n", funclistit
->name
);
366 for (arglistit
= funclistit
->arguments
, count
= 1;
368 arglistit
= arglistit
->next
, count
++
371 if (arglistit
!= funclistit
->arguments
)
374 if (arglistit
->next
== NULL
)
376 type
= getargtype(arglistit
);
377 assert(type
!= NULL
);
378 fprintf(out
, "(%s)(%s_args)", type
, funclistit
->name
);
382 fprintf(out
, "(arg%d)", count
);
387 "#endif /* !NO_INLINE_STDARG */\n"
390 else if (isvararg
== 2)
393 struct functionarg
*lastarg
;
396 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
397 "static inline %s __%s_WB(%s __%s",
398 cfg
->includenameupper
,
399 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
401 for (arglistit
= funclistit
->arguments
;
402 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
403 arglistit
= arglistit
->next
406 fprintf(out
, ", %s", arglistit
->arg
);
409 fprintf(out
, ", ...)\n");
416 " va_start(args, %s);\n"
417 " retval = __%s_WB(__%s, ",
420 funclistit
->name
, cfg
->libbase
422 for (arglistit
= funclistit
->arguments
;
423 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
424 arglistit
= arglistit
->next
427 fprintf(out
, "%s, ", getargname(arglistit
));
437 for (arglistit
= funclistit
->arguments
, count
= 1;
438 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
439 arglistit
= arglistit
->next
, count
++
442 fprintf(out
, "arg%d, ", count
);
448 fprintf(out
, "(%s)__%s_LIBBASE, ",
449 cfg
->libbasetypeptrextern
,
450 cfg
->includenameupper
);
451 for (arglistit
= funclistit
->arguments
, count
= 1;
452 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
453 arglistit
= arglistit
->next
, count
++
456 fprintf(out
, "(arg%d), ", count
);
460 "#endif /* !NO_INLINE_STDARG */\n"
463 else if (isvararg
== 3)
468 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
469 "static inline %s __inline_%s_%s(%s __%s",
470 cfg
->includenameupper
,
471 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
473 for (arglistit
= funclistit
->arguments
, count
= 0;
474 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
475 arglistit
= arglistit
->next
478 char *type
= getargtype(arglistit
);
480 fprintf(out
, ", %s __arg%d", type
, ++count
);
482 fprintf(out
, ", ...)\n");
486 fprintf(out
, " %s retval;\n\n", funclistit
->type
);
489 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
492 isvoid
? "" : "retval = ",
496 for (arglistit
= funclistit
->arguments
, count
= 1;
497 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
498 arglistit
= arglistit
->next
, count
++
501 fprintf(out
, ", __arg%d", count
);
505 ", AROS_SLOWSTACKFORMAT_ARG(__arg%d));\n"
506 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
513 isvoid
? "" : " retval",
516 for (arglistit
= funclistit
->arguments
, count
= 1;
517 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
518 arglistit
= arglistit
->next
, count
++
521 fprintf(out
, "arg%d, ", count
);
526 cfg
->basename
, varargname
528 fprintf(out
, "(%s)__%s_LIBBASE, ",
529 cfg
->libbasetypeptrextern
,
530 cfg
->includenameupper
);
531 for (arglistit
= funclistit
->arguments
, count
= 1;
532 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
533 arglistit
= arglistit
->next
, count
++
536 fprintf(out
, "(arg%d), ", count
);
540 "#endif /* !NO_INLINE_STDARG */\n"
546 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
548 struct stringlist
*aliasesit
;
550 for (aliasesit
= funclistit
->aliases
;
552 aliasesit
= aliasesit
->next
555 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);