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
*, int is_rel
);
10 static void writedefinevararg(FILE *, struct functionhead
*, struct config
*);
11 static void writealiases(FILE *, struct functionhead
*, struct config
*);
13 void writeincdefines(struct config
*cfg
, int is_rel
)
16 char line
[256], *banner
;
17 struct functionhead
*funclistit
;
19 snprintf(line
, 255, "%s/defines/%s%s.h", cfg
->gendir
, cfg
->modulename
, is_rel
? "_rel" : "");
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
, is_rel
);
66 if (!funclistit
->novararg
)
67 writedefinevararg(out
, funclistit
, cfg
);
69 else /* libcall == STACK */
71 writedefinestack(out
, funclistit
, cfg
, is_rel
);
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
, int is_rel
)
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(%s%s%s", funclistit
->name
,
214 is_rel
? "*(void **)((void *)__aros_getbase() + __aros_rellib_offset_" : ""
216 , is_rel
? ")" : "");
217 for (arglistit
= funclistit
->arguments
, count
= 1;
219 arglistit
= arglistit
->next
, count
++
221 fprintf(out
, ", (arg%d)", count
);
226 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
228 struct functionarg
*arglistit
= funclistit
->arguments
;
229 char isvararg
= 0, *varargname
, *lastname
;
231 /* Go to last argument */
232 if (arglistit
== NULL
)
235 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
237 lastname
= getargname(arglistit
);
238 assert(lastname
!= NULL
);
240 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
243 varargname
= strdup(funclistit
->name
);
244 varargname
[strlen(funclistit
->name
)-1] = '\0';
246 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
249 /* TagList has to be changed in Tags at the end of the functionname */
250 varargname
= strdup(funclistit
->name
);
251 varargname
[strlen(funclistit
->name
)-4] = 's';
252 varargname
[strlen(funclistit
->name
)-3] = '\0';
254 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
255 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
259 varargname
= strdup(funclistit
->name
);
260 varargname
[strlen(funclistit
->name
)-4] = '\0';
262 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
265 varargname
= malloc(strlen(funclistit
->name
));
266 strcpy(varargname
, &funclistit
->name
[1]);
272 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
273 p
= arglistit
->arg
+ 5;
274 while (isspace(*p
)) p
++;
277 if (strncmp(p
, "struct", 6)==0)
280 while (isspace(*p
)) p
++;
281 if (strncmp(p
, "TagItem", 7) == 0)
284 while (isspace(*p
)) p
++;
289 varargname
= malloc(strlen(funclistit
->name
) + 5);
290 strcpy(varargname
, funclistit
->name
);
291 strcat(varargname
, "Tags");
303 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
305 cfg
->modulenameupper
, varargname
307 for (arglistit
= funclistit
->arguments
, count
= 1;
308 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
309 arglistit
= arglistit
->next
, count
++
312 fprintf(out
, "arg%d, ", count
);
320 for (arglistit
= funclistit
->arguments
, count
= 1;
322 arglistit
= arglistit
->next
, count
++
325 if (arglistit
!= funclistit
->arguments
)
328 if (arglistit
->next
== NULL
)
330 type
= getargtype(arglistit
);
331 assert(type
!= NULL
);
332 fprintf(out
, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
336 fprintf(out
, "(arg%d)", count
);
341 "#endif /* !NO_INLINE_STDARG */\n"
346 else if (isvararg
== 2)
349 struct functionarg
*lastarg
;
352 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
353 "static inline %s __%s_WB(%s __%s",
354 cfg
->modulenameupper
,
355 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
357 for (arglistit
= funclistit
->arguments
;
358 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
359 arglistit
= arglistit
->next
362 fprintf(out
, ", %s", arglistit
->arg
);
365 fprintf(out
, ", ...)\n");
372 " va_start(args, %s);\n"
373 " retval = __%s_WB(__%s, ",
376 funclistit
->name
, cfg
->libbase
378 for (arglistit
= funclistit
->arguments
;
379 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
380 arglistit
= arglistit
->next
383 fprintf(out
, "%s, ", getargname(arglistit
));
393 for (arglistit
= funclistit
->arguments
, count
= 1;
394 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
395 arglistit
= arglistit
->next
, count
++
398 fprintf(out
, "arg%d, ", count
);
402 varargname
, cfg
->libbase
404 for (arglistit
= funclistit
->arguments
, count
= 1;
405 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
406 arglistit
= arglistit
->next
, count
++
409 fprintf(out
, "(arg%d), ", count
);
413 "#endif /* !NO_INLINE_STDARG */\n"
421 writedefinestack(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, int is_rel
)
423 struct functionarg
*arglistit
;
425 /* Only if no peropener or pertask base */
426 if (cfg
->options
& OPTION_DUPBASE
)
429 fprintf(out
, "#define %s ((%s (*)(", funclistit
->name
, funclistit
->type
);
430 for (arglistit
= funclistit
->arguments
;
432 arglistit
= arglistit
->next
435 fprintf(out
, "%s", arglistit
->arg
);
436 if (arglistit
->next
!= NULL
)
439 fprintf(out
, "))__AROS_GETVECADDR(%s%s%s,%d))\n",
440 is_rel
? "*(void **)((void *)__aros_getbase() + __aros_rellib_offset_" : "",
447 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
449 struct stringlist
*aliasesit
;
451 for (aliasesit
= funclistit
->aliases
;
453 aliasesit
= aliasesit
->next
456 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);