2 Copyright © 1995-2014, 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"
46 cfg
->includenameupper
, cfg
->includenameupper
, banner
, cfg
->modulename
50 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
52 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
54 char isvararg
= 0, *varargname
= NULL
, *lastname
;
58 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
60 cfg
->includenameupper
,
65 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
67 struct functionarg
*arglistit
= funclistit
->arguments
;
69 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
71 lastname
= getargname(arglistit
);
72 assert(lastname
!= NULL
);
74 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
77 varargname
= strdup(funclistit
->name
);
78 varargname
[strlen(funclistit
->name
)-1] = '\0';
80 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
83 /* TagList has to be changed in Tags at the end of the functionname */
84 varargname
= strdup(funclistit
->name
);
85 varargname
[strlen(funclistit
->name
)-4] = 's';
86 varargname
[strlen(funclistit
->name
)-3] = '\0';
88 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
89 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
93 varargname
= strdup(funclistit
->name
);
94 varargname
[strlen(funclistit
->name
)-4] = '\0';
96 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
99 varargname
= malloc(strlen(funclistit
->name
));
100 strcpy(varargname
, &funclistit
->name
[1]);
106 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
107 p
= arglistit
->arg
+ 5;
108 while (isspace(*p
)) p
++;
111 if (strncmp(p
, "struct", 6)==0)
114 while (isspace(*p
)) p
++;
115 if (strncmp(p
, "TagItem", 7) == 0)
118 while (isspace(*p
)) p
++;
123 varargname
= malloc(strlen(funclistit
->name
) + 5);
124 strcpy(varargname
, funclistit
->name
);
125 strcat(varargname
, "Tags");
132 writedefineregister(out
, funclistit
, cfg
, isvararg
);
133 if (!funclistit
->novararg
&& isvararg
)
135 writedefinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
138 writealiases(out
, funclistit
, cfg
);
142 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
144 cfg
->includenameupper
,
146 cfg
->includenameupper
155 "#endif /* DEFINES_%s_H*/\n",
156 cfg
->includenameupper
162 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
164 struct functionarg
*arglistit
;
165 int count
, isvoid
, nquad
= 0, narg
= 0;
168 isvoid
= strcmp(funclistit
->type
, "void") == 0
169 || strcmp(funclistit
->type
, "VOID") == 0;
173 "#define __%s_WB(__%s",
174 funclistit
->name
, cfg
->libbase
176 for (arglistit
= funclistit
->arguments
, count
= 1;
178 arglistit
= arglistit
->next
, count
++
181 fprintf(out
, ", __arg%d", count
);
182 if (strchr(arglistit
->reg
, '/') != NULL
) {
192 " AROS_LIBREQ(%s,%d)\\\n",
193 cfg
->libbase
, funclistit
->version
198 " AROS_LC%d%s%s(%s, %s, \\\n",
199 funclistit
->argcount
, funclistit
->unusedlibbase
? "I" : "",
200 (isvoid
) ? "NR" : "",
201 funclistit
->type
, funclistit
->name
204 for (arglistit
= funclistit
->arguments
, count
= 1;
206 arglistit
= arglistit
->next
, count
++
209 type
= getargtype(arglistit
);
210 assert(type
!= NULL
);
212 " AROS_LCA(%s%s,(__arg%d),%s), \\\n",
213 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
214 type
, count
, arglistit
->reg
223 " AROS_LC%dQUAD%d%s(%s, %s,\\\n",
224 narg
, nquad
, (isvoid
) ? "NR" : "",
225 funclistit
->type
, funclistit
->name
229 " AROS_LCQUAD%d%s(%s, %s,\\\n",
230 nquad
, (isvoid
) ? "NR" : "",
231 funclistit
->type
, funclistit
->name
235 for (arglistit
= funclistit
->arguments
, count
= 1;
237 arglistit
= arglistit
->next
, count
++
240 char *quad2
= strchr(arglistit
->reg
, '/');
242 arglistit
->reg
[2] = 0;
243 type
= getargtype(arglistit
);
244 assert(type
!= NULL
);
249 " AROS_LCAQUAD(%s%s, (__arg%d), %s, %s), \\\n",
250 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
251 type
, count
, arglistit
->reg
, quad2
+1
256 " AROS_LCA(%s%s, (__arg%d), %s), \\\n",
257 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
258 type
, count
, arglistit
->reg
265 " %s, (__%s), %u, %s);\\\n})\n\n",
266 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
269 fprintf(out
, "#define %s(", funclistit
->name
);
270 for (arglistit
= funclistit
->arguments
, count
= 1;
272 arglistit
= arglistit
->next
, count
++
275 if (arglistit
!= funclistit
->arguments
)
277 fprintf(out
, "arg%d", count
);
279 fprintf(out
, ") \\\n __%s_WB(__aros_getbase_%s()",
280 funclistit
->name
, cfg
->libbase
282 for (arglistit
= funclistit
->arguments
, count
= 1;
284 arglistit
= arglistit
->next
, count
++
286 fprintf(out
, ", (arg%d)", count
);
291 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
293 struct functionarg
*arglistit
= funclistit
->arguments
;
301 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
303 cfg
->includenameupper
, varargname
305 for (arglistit
= funclistit
->arguments
, count
= 1;
306 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
307 arglistit
= arglistit
->next
, count
++
310 fprintf(out
, "arg%d, ", count
);
318 for (arglistit
= funclistit
->arguments
, count
= 1;
320 arglistit
= arglistit
->next
, count
++
323 if (arglistit
!= funclistit
->arguments
)
326 if (arglistit
->next
== NULL
)
328 type
= getargtype(arglistit
);
329 assert(type
!= NULL
);
330 fprintf(out
, "(const %s)(const IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
334 fprintf(out
, "(arg%d)", count
);
339 "#endif /* !NO_INLINE_STDARG */\n"
342 else if (isvararg
== 2)
345 struct functionarg
*lastarg
;
348 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
349 "static inline %s __%s_WB(%s __%s",
350 cfg
->includenameupper
,
351 funclistit
->type
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
353 for (arglistit
= funclistit
->arguments
;
354 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
355 arglistit
= arglistit
->next
358 fprintf(out
, ", %s", arglistit
->arg
);
361 fprintf(out
, ", ...)\n");
368 " va_start(args, %s);\n"
369 " retval = __%s_WB(__%s, ",
372 funclistit
->name
, cfg
->libbase
374 for (arglistit
= funclistit
->arguments
;
375 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
376 arglistit
= arglistit
->next
379 fprintf(out
, "%s, ", getargname(arglistit
));
389 for (arglistit
= funclistit
->arguments
, count
= 1;
390 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
391 arglistit
= arglistit
->next
, count
++
394 fprintf(out
, "arg%d, ", count
);
398 varargname
, cfg
->libbase
400 for (arglistit
= funclistit
->arguments
, count
= 1;
401 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
402 arglistit
= arglistit
->next
, count
++
405 fprintf(out
, "(arg%d), ", count
);
409 "#endif /* !NO_INLINE_STDARG */\n"
415 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
417 struct stringlist
*aliasesit
;
419 for (aliasesit
= funclistit
->aliases
;
421 aliasesit
= aliasesit
->next
424 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);