2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Function to write inline/modulename.h. Part of genmodule.
9 static void writeinlineregister(FILE *, struct functionhead
*, struct config
*);
10 static void writeinlinevararg(FILE *, struct functionhead
*, struct config
*);
11 static void writealiases(FILE *, struct functionhead
*, struct config
*);
13 void writeincinline(struct config
*cfg
)
16 char line
[256], *banner
;
17 struct functionhead
*funclistit
;
19 snprintf(line
, 255, "%s/inline/%s.h", cfg
->gendir
, cfg
->modulename
);
20 out
= fopen(line
, "w");
28 banner
= getBanner(cfg
);
30 "#ifndef INLINE_%s_H\n"
31 "#define INLINE_%s_H\n"
36 " Desc: Inline function 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"
44 cfg
->modulenameupper
, cfg
->modulenameupper
, banner
, cfg
->modulename
48 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
50 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
54 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
61 if (funclistit
->libcall
!= STACK
)
63 writeinlineregister(out
, funclistit
, cfg
);
64 if (!funclistit
->novararg
)
65 writeinlinevararg(out
, funclistit
, cfg
);
67 else /* libcall == STACK */
69 /* This is the same as in defines */
70 writedefinestack(out
, funclistit
, cfg
);
73 writealiases(out
, funclistit
, cfg
);
77 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
88 "#endif /* INLINE_%s_H*/\n",
96 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
98 struct functionarg
*arglistit
;
103 isvoid
= strcmp(funclistit
->type
, "void") == 0
104 || strcmp(funclistit
->type
, "VOID") == 0;
108 "static inline %s __inline_%s_%s(",
109 funclistit
->type
, cfg
->basename
, funclistit
->name
111 for (arglistit
= funclistit
->arguments
, count
= 1;
113 arglistit
= arglistit
->next
, count
++
116 type
= getargtype(arglistit
);
117 fprintf(out
, "%s __arg%d, ", type
, count
);
118 if (strchr(arglistit
->reg
, '/') != NULL
) {
130 " AROS_LIBREQ(%s, %d)\n",
131 cfg
->libbase
, funclistit
->version
136 " %sAROS_LC%d%s(%s, %s,\n",
137 (isvoid
) ? "" : "return ",
138 funclistit
->argcount
, (isvoid
) ? "NR" : "",
139 funclistit
->type
, funclistit
->name
142 for (arglistit
= funclistit
->arguments
, count
= 1;
144 arglistit
= arglistit
->next
, count
++
147 type
= getargtype(arglistit
);
148 assert(type
!= NULL
);
150 " AROS_LCA(%s,(__arg%d),%s),\n",
151 type
, count
, arglistit
->reg
156 else /* nquad != 0 */
160 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
161 (isvoid
) ? "" : "return ", narg
,
162 nquad
, (isvoid
) ? "NR" : "",
163 funclistit
->type
, funclistit
->name
167 " %sAROS_LCQUAD%d%s(%s, %s,\n",
168 (isvoid
) ? "" : "return ",
169 nquad
, (isvoid
) ? "NR" : "",
170 funclistit
->type
, funclistit
->name
174 for (arglistit
= funclistit
->arguments
, count
= 1;
176 arglistit
= arglistit
->next
, count
++
179 char *quad2
= strchr(arglistit
->reg
, '/');
181 arglistit
->reg
[2] = 0;
182 type
= getargtype(arglistit
);
183 assert(type
!= NULL
);
188 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
189 type
, count
, arglistit
->reg
, quad2
+1
194 " AROS_LCA(%s, (__arg%d), %s), \\\n",
195 type
, count
, arglistit
->reg
202 " %s, (__%s), %u, %s"
205 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
208 fprintf(out
, "#define %s(", funclistit
->name
);
209 for (arglistit
= funclistit
->arguments
, count
= 1;
211 arglistit
= arglistit
->next
, count
++
214 if (arglistit
!= funclistit
->arguments
)
216 fprintf(out
, "arg%d", count
);
218 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
219 for (arglistit
= funclistit
->arguments
, count
= 1;
221 arglistit
= arglistit
->next
, count
++
223 fprintf(out
, "(arg%d), ", count
);
224 fprintf(out
, "__aros_getbase_%s())\n", cfg
->libbase
);
228 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
230 struct functionarg
*arglistit
= funclistit
->arguments
;
231 char isvararg
= 0, *varargname
, *lastname
;
233 /* Go to last argument */
234 if (arglistit
== NULL
)
237 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
239 lastname
= getargname(arglistit
);
240 assert(lastname
!= NULL
);
242 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
245 varargname
= strdup(funclistit
->name
);
246 varargname
[strlen(funclistit
->name
)-1] = '\0';
248 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
251 /* TagList has to be changed in Tags at the end of the functionname */
252 varargname
= strdup(funclistit
->name
);
253 varargname
[strlen(funclistit
->name
)-4] = 's';
254 varargname
[strlen(funclistit
->name
)-3] = '\0';
256 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
257 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
261 varargname
= strdup(funclistit
->name
);
262 varargname
[strlen(funclistit
->name
)-4] = '\0';
264 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
267 varargname
= malloc(strlen(funclistit
->name
));
268 strcpy(varargname
, &funclistit
->name
[1]);
275 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
276 p
= arglistit
->arg
+ 5;
277 while (isspace(*p
)) p
++;
280 if (strncmp(p
, "struct", 6)==0)
283 while (isspace(*p
)) p
++;
284 if (strncmp(p
, "TagItem", 7) == 0)
287 while (isspace(*p
)) p
++;
292 varargname
= malloc(strlen(funclistit
->name
) + 5);
293 strcpy(varargname
, funclistit
->name
);
294 strcat(varargname
, "Tags");
305 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
307 cfg
->modulenameupper
, varargname
309 for (arglistit
= funclistit
->arguments
, count
= 1;
310 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
311 arglistit
= arglistit
->next
, count
++
314 fprintf(out
, "arg%d, ", count
);
322 for (arglistit
= funclistit
->arguments
, count
= 1;
324 arglistit
= arglistit
->next
, count
++
327 if (arglistit
!= funclistit
->arguments
)
330 if (arglistit
->next
== NULL
)
332 type
= getargtype(arglistit
);
333 assert(type
!= NULL
);
334 fprintf(out
, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
338 fprintf(out
, "(arg%d)", count
);
343 "#endif /* !NO_INLINE_STDARG */\n"
348 else if (isvararg
== 2)
353 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
354 "static inline %s __inline_%s_%s(%s __%s",
355 cfg
->modulenameupper
,
356 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
358 for (arglistit
= funclistit
->arguments
, count
= 0;
359 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
360 arglistit
= arglistit
->next
363 char *type
= getargtype(arglistit
);
365 fprintf(out
, ", %s __arg%d", type
, ++count
);
367 fprintf(out
, ", ...)\n");
374 " va_start(__args, __arg%d);\n"
375 " retval = __inline_%s_%s(",
378 cfg
->basename
, funclistit
->name
380 for (arglistit
= funclistit
->arguments
, count
= 1;
381 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
382 arglistit
= arglistit
->next
, count
++
385 fprintf(out
, "__arg%d, ", count
);
397 for (arglistit
= funclistit
->arguments
, count
= 1;
398 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
399 arglistit
= arglistit
->next
, count
++
402 fprintf(out
, "arg%d, ", count
);
406 " __inline_%s_%s(%s, ",
407 cfg
->basename
, varargname
, cfg
->libbase
409 for (arglistit
= funclistit
->arguments
, count
= 1;
410 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
411 arglistit
= arglistit
->next
, count
++
414 fprintf(out
, "(arg%d), ", count
);
418 "#endif /* !NO_INLINE_STDARG */\n"
426 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
428 struct stringlist
*aliasesit
;
430 for (aliasesit
= funclistit
->aliases
;
432 aliasesit
= aliasesit
->next
435 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);