2 Copyright © 1995-2012, 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
;
102 int count
, isvoid
, nquad
= 0, narg
= 0;
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
);
119 if (strchr(arglistit
->reg
, '/') != NULL
) {
129 " AROS_LIBREQ(%s,%d)\\\n",
130 cfg
->libbase
, funclistit
->version
135 " AROS_LC%d%s%s(%s, %s, \\\n",
136 funclistit
->argcount
, funclistit
->unusedlibbase
? "I" : "",
137 (isvoid
) ? "NR" : "",
138 funclistit
->type
, funclistit
->name
141 for (arglistit
= funclistit
->arguments
, count
= 1;
143 arglistit
= arglistit
->next
, count
++
146 type
= getargtype(arglistit
);
147 assert(type
!= NULL
);
149 " AROS_LCA(%s,(__arg%d),%s), \\\n",
150 type
, count
, arglistit
->reg
159 " AROS_LC%dQUAD%d%s(%s, %s,\\\n",
160 narg
, nquad
, (isvoid
) ? "NR" : "",
161 funclistit
->type
, funclistit
->name
165 " AROS_LCQUAD%d%s(%s, %s,\\\n",
166 nquad
, (isvoid
) ? "NR" : "",
167 funclistit
->type
, funclistit
->name
171 for (arglistit
= funclistit
->arguments
, count
= 1;
173 arglistit
= arglistit
->next
, count
++
176 char *quad2
= strchr(arglistit
->reg
, '/');
178 arglistit
->reg
[2] = 0;
179 type
= getargtype(arglistit
);
180 assert(type
!= NULL
);
185 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
186 type
, count
, arglistit
->reg
, quad2
+1
191 " AROS_LCA(%s, (__arg%d), %s), \\\n",
192 type
, count
, arglistit
->reg
199 " %s, (__%s), %u, %s);\\\n})\n\n",
200 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
203 fprintf(out
, "#define %s(", funclistit
->name
);
204 for (arglistit
= funclistit
->arguments
, count
= 1;
206 arglistit
= arglistit
->next
, count
++
209 if (arglistit
!= funclistit
->arguments
)
211 fprintf(out
, "arg%d", count
);
213 fprintf(out
, ") \\\n __%s_WB(__aros_getbase_%s()",
214 funclistit
->name
, cfg
->libbase
216 for (arglistit
= funclistit
->arguments
, count
= 1;
218 arglistit
= arglistit
->next
, count
++
220 fprintf(out
, ", (arg%d)", count
);
225 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
227 struct functionarg
*arglistit
= funclistit
->arguments
;
228 char isvararg
= 0, *varargname
, *lastname
;
230 /* Go to last argument */
231 if (arglistit
== NULL
)
234 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
236 lastname
= getargname(arglistit
);
237 assert(lastname
!= NULL
);
239 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
242 varargname
= strdup(funclistit
->name
);
243 varargname
[strlen(funclistit
->name
)-1] = '\0';
245 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
248 /* TagList has to be changed in Tags at the end of the functionname */
249 varargname
= strdup(funclistit
->name
);
250 varargname
[strlen(funclistit
->name
)-4] = 's';
251 varargname
[strlen(funclistit
->name
)-3] = '\0';
253 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
254 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
258 varargname
= strdup(funclistit
->name
);
259 varargname
[strlen(funclistit
->name
)-4] = '\0';
261 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
264 varargname
= malloc(strlen(funclistit
->name
));
265 strcpy(varargname
, &funclistit
->name
[1]);
271 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
272 p
= arglistit
->arg
+ 5;
273 while (isspace(*p
)) p
++;
276 if (strncmp(p
, "struct", 6)==0)
279 while (isspace(*p
)) p
++;
280 if (strncmp(p
, "TagItem", 7) == 0)
283 while (isspace(*p
)) p
++;
288 varargname
= malloc(strlen(funclistit
->name
) + 5);
289 strcpy(varargname
, funclistit
->name
);
290 strcat(varargname
, "Tags");
302 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
304 cfg
->modulenameupper
, varargname
306 for (arglistit
= funclistit
->arguments
, count
= 1;
307 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
308 arglistit
= arglistit
->next
, count
++
311 fprintf(out
, "arg%d, ", count
);
319 for (arglistit
= funclistit
->arguments
, count
= 1;
321 arglistit
= arglistit
->next
, count
++
324 if (arglistit
!= funclistit
->arguments
)
327 if (arglistit
->next
== NULL
)
329 type
= getargtype(arglistit
);
330 assert(type
!= NULL
);
331 fprintf(out
, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
335 fprintf(out
, "(arg%d)", count
);
340 "#endif /* !NO_INLINE_STDARG */\n"
345 else if (isvararg
== 2)
348 struct functionarg
*lastarg
;
351 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
352 "static inline %s __%s_WB(%s __%s",
353 cfg
->modulenameupper
,
354 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
356 for (arglistit
= funclistit
->arguments
;
357 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
358 arglistit
= arglistit
->next
361 fprintf(out
, ", %s", arglistit
->arg
);
364 fprintf(out
, ", ...)\n");
371 " va_start(args, %s);\n"
372 " retval = __%s_WB(__%s, ",
375 funclistit
->name
, cfg
->libbase
377 for (arglistit
= funclistit
->arguments
;
378 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
379 arglistit
= arglistit
->next
382 fprintf(out
, "%s, ", getargname(arglistit
));
392 for (arglistit
= funclistit
->arguments
, count
= 1;
393 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
394 arglistit
= arglistit
->next
, count
++
397 fprintf(out
, "arg%d, ", count
);
401 varargname
, cfg
->libbase
403 for (arglistit
= funclistit
->arguments
, count
= 1;
404 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
405 arglistit
= arglistit
->next
, count
++
408 fprintf(out
, "(arg%d), ", count
);
412 "#endif /* !NO_INLINE_STDARG */\n"
420 writedefinestack(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
422 struct functionarg
*arglistit
;
424 /* Only if no peropener or pertask base */
425 if (cfg
->options
& OPTION_DUPBASE
)
428 fprintf(out
, "#define %s ((%s (*)(", funclistit
->name
, funclistit
->type
);
429 for (arglistit
= funclistit
->arguments
;
431 arglistit
= arglistit
->next
434 fprintf(out
, "%s", arglistit
->arg
);
435 if (arglistit
->next
!= NULL
)
438 fprintf(out
, "))__AROS_GETVECADDR(__aros_getbase_%s(),%d))\n",
439 cfg
->libbase
, funclistit
->lvo
444 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
446 struct stringlist
*aliasesit
;
448 for (aliasesit
= funclistit
->aliases
;
450 aliasesit
= aliasesit
->next
453 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);