2 Copyright © 1995-2009, 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 writedefinestack(FILE *, struct functionhead
*, struct config
*);
12 static void writealiases(FILE *, struct functionhead
*, struct config
*);
14 void writeincdefines(struct config
*cfg
)
17 char line
[256], *banner
;
18 struct functionhead
*funclistit
;
20 snprintf(line
, 255, "%s/defines/%s.h", cfg
->gendir
, cfg
->modulename
);
21 out
= fopen(line
, "w");
29 banner
= getBanner(cfg
);
31 "#ifndef DEFINES_%s_H\n"
32 "#define DEFINES_%s_H\n"
37 " Desc: Defines for %s\n"
40 "#include <aros/libcall.h>\n"
41 "#include <exec/types.h>\n"
42 "#include <aros/preprocessor/variadic/cast2iptr.hpp>\n"
44 cfg
->modulenameupper
, cfg
->modulenameupper
, banner
, cfg
->modulename
48 if (cfg
->command
!=DUMMY
)
50 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
52 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
54 if (funclistit
->libcall
!= STACK
)
56 writedefineregister(out
, funclistit
, cfg
);
57 if (!funclistit
->novararg
)
58 writedefinevararg(out
, funclistit
, cfg
);
60 else /* libcall == STACK */
62 writedefinestack(out
, funclistit
, cfg
);
65 writealiases(out
, funclistit
, cfg
);
71 "#endif /* DEFINES_%s_H*/\n",
79 writedefineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
81 struct functionarg
*arglistit
;
85 isvoid
= strcmp(funclistit
->type
, "void") == 0
86 || strcmp(funclistit
->type
, "VOID") == 0;
90 "#define __%s_WB(__%s",
91 funclistit
->name
, cfg
->libbase
93 for (arglistit
= funclistit
->arguments
, count
= 1;
95 arglistit
= arglistit
->next
, count
++
98 fprintf(out
, ", __arg%d", count
);
102 " AROS_LC%d%s(%s, %s, \\\n",
103 funclistit
->argcount
, (isvoid
) ? "NR" : "",
104 funclistit
->type
, funclistit
->name
107 for (arglistit
= funclistit
->arguments
, count
= 1;
109 arglistit
= arglistit
->next
, count
++
112 type
= getargtype(arglistit
);
113 assert(type
!= NULL
);
115 " AROS_LCA(%s,(__arg%d),%s), \\\n",
116 type
, count
, arglistit
->reg
121 " %s, (__%s), %u, %s)\n\n",
122 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
125 fprintf(out
, "#define %s(", funclistit
->name
);
126 for (arglistit
= funclistit
->arguments
, count
= 1;
128 arglistit
= arglistit
->next
, count
++
131 if (arglistit
!= funclistit
->arguments
)
133 fprintf(out
, "arg%d", count
);
135 fprintf(out
, ") \\\n __%s_WB(%s", funclistit
->name
, cfg
->libbase
);
136 for (arglistit
= funclistit
->arguments
, count
= 1;
138 arglistit
= arglistit
->next
, count
++
140 fprintf(out
, ", (arg%d)", count
);
145 writedefinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
147 struct functionarg
*arglistit
= funclistit
->arguments
;
148 char isvararg
= 0, *varargname
, *lastname
;
150 /* Go to last argument */
151 if (arglistit
== NULL
)
154 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
156 lastname
= getargname(arglistit
);
157 assert(lastname
!= NULL
);
159 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
162 varargname
= strdup(funclistit
->name
);
163 varargname
[strlen(funclistit
->name
)-1] = '\0';
165 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
168 /* TagList has to be changed in Tags at the end of the functionname */
169 varargname
= strdup(funclistit
->name
);
170 varargname
[strlen(funclistit
->name
)-4] = 's';
171 varargname
[strlen(funclistit
->name
)-3] = '\0';
173 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
174 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
178 varargname
= strdup(funclistit
->name
);
179 varargname
[strlen(funclistit
->name
)-4] = '\0';
185 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
186 p
= arglistit
->arg
+ 5;
187 while (isspace(*p
)) p
++;
190 if (strncmp(p
, "struct", 6)==0)
193 while (isspace(*p
)) p
++;
194 if (strncmp(p
, "TagItem", 7) == 0)
197 while (isspace(*p
)) p
++;
202 varargname
= malloc(strlen(funclistit
->name
) + 5);
203 strcpy(varargname
, funclistit
->name
);
204 strcat(varargname
, "Tags");
215 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
217 cfg
->modulenameupper
, varargname
219 for (arglistit
= funclistit
->arguments
, count
= 1;
220 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
221 arglistit
= arglistit
->next
, count
++
224 fprintf(out
, "arg%d, ", count
);
229 " IPTR __args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }; \\\n"
233 for (arglistit
= funclistit
->arguments
, count
= 1;
235 arglistit
= arglistit
->next
, count
++
238 if (arglistit
!= funclistit
->arguments
)
241 if (arglistit
->next
== NULL
)
243 type
= getargtype(arglistit
);
244 assert(type
!= NULL
);
245 fprintf(out
, "(%s)__args", type
);
249 fprintf(out
, "(arg%d)", count
);
254 "#endif /* !NO_INLINE_STDARG */\n"
262 writedefinestack(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
264 struct functionarg
*arglistit
;
266 fprintf(out
, "#define %s ((%s (*)(", funclistit
->name
, funclistit
->type
);
267 for (arglistit
= funclistit
->arguments
;
269 arglistit
= arglistit
->next
272 fprintf(out
, "%s", arglistit
->arg
);
273 if (arglistit
->next
!= NULL
)
276 fprintf(out
, "))__AROS_GETVECADDR(%s,%d))\n", cfg
->libbase
, funclistit
->lvo
);
280 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
282 struct stringlist
*aliasesit
;
284 for (aliasesit
= funclistit
->aliases
;
286 aliasesit
= aliasesit
->next
289 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);