2 Copyright © 1995-2011, 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
->modulename
);
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
->modulenameupper
, cfg
->modulenameupper
, banner
, cfg
->modulename
50 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
52 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
56 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
63 if (funclistit
->libcall
!= STACK
)
65 writedefineregister(out
, funclistit
, cfg
);
66 if (!funclistit
->novararg
)
67 writedefinevararg(out
, funclistit
, cfg
);
69 else /* libcall == STACK */
71 writedefinestack(out
, funclistit
, cfg
);
74 writealiases(out
, funclistit
, cfg
);
78 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
91 "#endif /* DEFINES_%s_H*/\n",
99 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
101 struct functionarg
*arglistit
;
105 isvoid
= strcmp(funclistit
->type
, "void") == 0
106 || strcmp(funclistit
->type
, "VOID") == 0;
110 "#define __%s_WB(__%s",
111 funclistit
->name
, cfg
->libbase
113 for (arglistit
= funclistit
->arguments
, count
= 1;
115 arglistit
= arglistit
->next
, count
++
118 fprintf(out
, ", __arg%d", count
);
123 if (cfg
->options
& OPTION_AUTOINIT
) {
125 " AROS_LIBREQ(%s,%d)\\\n",
126 cfg
->libbase
, funclistit
->version
129 if (funclistit
->arguments
== NULL
130 || strchr(funclistit
->arguments
->reg
, '/') == NULL
134 " AROS_LC%d%s(%s, %s, \\\n",
135 funclistit
->argcount
, (isvoid
) ? "NR" : "",
136 funclistit
->type
, funclistit
->name
139 for (arglistit
= funclistit
->arguments
, count
= 1;
141 arglistit
= arglistit
->next
, count
++
144 type
= getargtype(arglistit
);
145 assert(type
!= NULL
);
147 " AROS_LCA(%s,(__arg%d),%s), \\\n",
148 type
, count
, arglistit
->reg
156 " AROS_LCQUAD%d%s(%s, %s, \\\n",
157 funclistit
->argcount
, (isvoid
) ? "NR" : "",
158 funclistit
->type
, funclistit
->name
161 for (arglistit
= funclistit
->arguments
, count
= 1;
163 arglistit
= arglistit
->next
, count
++
166 if (strlen(arglistit
->reg
) != 5)
168 fprintf(stderr
, "Internal error: ../.. register format expected\n");
171 arglistit
->reg
[2] = 0;
173 type
= getargtype(arglistit
);
174 assert(type
!= NULL
);
177 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
178 type
, count
, arglistit
->reg
, arglistit
->reg
+3
180 arglistit
->reg
[2] = '/';
185 " %s, (__%s), %u, %s);\\\n})\n\n",
186 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
189 fprintf(out
, "#define %s(", funclistit
->name
);
190 for (arglistit
= funclistit
->arguments
, count
= 1;
192 arglistit
= arglistit
->next
, count
++
195 if (arglistit
!= funclistit
->arguments
)
197 fprintf(out
, "arg%d", count
);
199 fprintf(out
, ") \\\n __%s_WB(%s", funclistit
->name
, cfg
->libbase
);
200 for (arglistit
= funclistit
->arguments
, count
= 1;
202 arglistit
= arglistit
->next
, count
++
204 fprintf(out
, ", (arg%d)", count
);
209 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
211 struct functionarg
*arglistit
= funclistit
->arguments
;
212 char isvararg
= 0, *varargname
, *lastname
;
214 /* Go to last argument */
215 if (arglistit
== NULL
)
218 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
220 lastname
= getargname(arglistit
);
221 assert(lastname
!= NULL
);
223 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
226 varargname
= strdup(funclistit
->name
);
227 varargname
[strlen(funclistit
->name
)-1] = '\0';
229 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
232 /* TagList has to be changed in Tags at the end of the functionname */
233 varargname
= strdup(funclistit
->name
);
234 varargname
[strlen(funclistit
->name
)-4] = 's';
235 varargname
[strlen(funclistit
->name
)-3] = '\0';
237 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
238 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
242 varargname
= strdup(funclistit
->name
);
243 varargname
[strlen(funclistit
->name
)-4] = '\0';
245 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
248 varargname
= malloc(strlen(funclistit
->name
));
249 strcpy(varargname
, &funclistit
->name
[1]);
255 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
256 p
= arglistit
->arg
+ 5;
257 while (isspace(*p
)) p
++;
260 if (strncmp(p
, "struct", 6)==0)
263 while (isspace(*p
)) p
++;
264 if (strncmp(p
, "TagItem", 7) == 0)
267 while (isspace(*p
)) p
++;
272 varargname
= malloc(strlen(funclistit
->name
) + 5);
273 strcpy(varargname
, funclistit
->name
);
274 strcat(varargname
, "Tags");
286 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
288 cfg
->modulenameupper
, varargname
290 for (arglistit
= funclistit
->arguments
, count
= 1;
291 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
292 arglistit
= arglistit
->next
, count
++
295 fprintf(out
, "arg%d, ", count
);
300 " IPTR __args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }; \\\n"
304 for (arglistit
= funclistit
->arguments
, count
= 1;
306 arglistit
= arglistit
->next
, count
++
309 if (arglistit
!= funclistit
->arguments
)
312 if (arglistit
->next
== NULL
)
314 type
= getargtype(arglistit
);
315 assert(type
!= NULL
);
316 fprintf(out
, "(%s)__args", type
);
320 fprintf(out
, "(arg%d)", count
);
325 "#endif /* !NO_INLINE_STDARG */\n"
330 else if (isvararg
== 2)
333 struct functionarg
*lastarg
;
336 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
337 "static inline %s __%s_WB(%s __%s",
338 cfg
->modulenameupper
,
339 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
341 for (arglistit
= funclistit
->arguments
;
342 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
343 arglistit
= arglistit
->next
346 fprintf(out
, ", %s", arglistit
->arg
);
349 fprintf(out
, ", ...)\n");
356 " va_start(args, %s);\n"
357 " retval = __%s_WB(__%s, ",
360 funclistit
->name
, cfg
->libbase
362 for (arglistit
= funclistit
->arguments
;
363 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
364 arglistit
= arglistit
->next
367 fprintf(out
, "%s, ", getargname(arglistit
));
377 for (arglistit
= funclistit
->arguments
, count
= 1;
378 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
379 arglistit
= arglistit
->next
, count
++
382 fprintf(out
, "arg%d, ", count
);
386 varargname
, cfg
->libbase
388 for (arglistit
= funclistit
->arguments
, count
= 1;
389 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
390 arglistit
= arglistit
->next
, count
++
393 fprintf(out
, "(arg%d), ", count
);
397 "#endif /* !NO_INLINE_STDARG */\n"
405 writedefinestack(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
407 struct functionarg
*arglistit
;
409 /* Only if no peropener or pertask base */
410 if (cfg
->options
& OPTION_DUPBASE
)
413 fprintf(out
, "#define %s ((%s (*)(", funclistit
->name
, funclistit
->type
);
414 for (arglistit
= funclistit
->arguments
;
416 arglistit
= arglistit
->next
419 fprintf(out
, "%s", arglistit
->arg
);
420 if (arglistit
->next
!= NULL
)
423 fprintf(out
, "))__AROS_GETVECADDR(%s,%d))\n", cfg
->libbase
, funclistit
->lvo
);
427 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
429 struct stringlist
*aliasesit
;
431 for (aliasesit
= funclistit
->aliases
;
433 aliasesit
= aliasesit
->next
436 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);