2 Copyright © 1995-2016, 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
*, char);
10 static void writeinlinevararg(FILE *, struct functionhead
*, struct config
*, char, char *);
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
->includename
);
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(s) 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
->includenameupper
, cfg
->includenameupper
, banner
, cfg
->modulename
48 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
50 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
52 char isvararg
= 0, *varargname
= NULL
, *lastname
;
56 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
58 cfg
->includenameupper
,
63 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
65 struct functionarg
*arglistit
= funclistit
->arguments
;
67 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
69 lastname
= getargname(arglistit
);
70 assert(lastname
!= NULL
);
72 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
75 varargname
= strdup(funclistit
->name
);
76 varargname
[strlen(funclistit
->name
)-1] = '\0';
77 if (arglistit
&& strncmp(arglistit
->arg
, "RAWARG", 6) == 0)
80 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
83 /* TagList has to be changed to 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]);
102 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "RAWARG", 6) == 0))
105 varargname
= malloc(strlen(funclistit
->name
));
106 strcpy(varargname
, &funclistit
->name
[1]);
113 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
114 p
= arglistit
->arg
+ 5;
115 while (isspace(*p
)) p
++;
118 if (strncmp(p
, "struct", 6)==0)
121 while (isspace(*p
)) p
++;
122 if (strncmp(p
, "TagItem", 7) == 0)
125 while (isspace(*p
)) p
++;
130 varargname
= malloc(strlen(funclistit
->name
) + 5);
131 strcpy(varargname
, funclistit
->name
);
132 strcat(varargname
, "Tags");
139 writeinlineregister(out
, funclistit
, cfg
, isvararg
);
140 if (!funclistit
->novararg
&& isvararg
)
142 writeinlinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
146 writealiases(out
, funclistit
, cfg
);
150 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
152 cfg
->includenameupper
,
154 cfg
->includenameupper
161 "#endif /* INLINE_%s_H*/\n",
162 cfg
->includenameupper
168 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
170 struct functionarg
*arglistit
;
175 isvoid
= strcmp(funclistit
->type
, "void") == 0
176 || strcmp(funclistit
->type
, "VOID") == 0;
180 "static inline %s __inline_%s_%s(",
181 funclistit
->type
, cfg
->basename
, funclistit
->name
183 for (arglistit
= funclistit
->arguments
, count
= 1;
185 arglistit
= arglistit
->next
, count
++
188 type
= getargtype(arglistit
);
189 fprintf(out
, "%s%s __arg%d, ",
190 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
192 if (strchr(arglistit
->reg
, '/') != NULL
) {
204 " AROS_LIBREQ(%s, %d)\n",
205 cfg
->libbase
, funclistit
->version
210 " %sAROS_LC%d%s(%s, %s,\n",
211 (isvoid
) ? "" : "return ",
212 funclistit
->argcount
, (isvoid
) ? "NR" : "",
213 funclistit
->type
, funclistit
->name
216 for (arglistit
= funclistit
->arguments
, count
= 1;
218 arglistit
= arglistit
->next
, count
++
221 type
= getargtype(arglistit
);
222 assert(type
!= NULL
);
224 " AROS_LCA(%s%s,(__arg%d),%s),\n",
225 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
226 type
, count
, arglistit
->reg
231 else /* nquad != 0 */
235 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
236 (isvoid
) ? "" : "return ", narg
,
237 nquad
, (isvoid
) ? "NR" : "",
238 funclistit
->type
, funclistit
->name
242 " %sAROS_LCQUAD%d%s(%s, %s,\n",
243 (isvoid
) ? "" : "return ",
244 nquad
, (isvoid
) ? "NR" : "",
245 funclistit
->type
, funclistit
->name
249 for (arglistit
= funclistit
->arguments
, count
= 1;
251 arglistit
= arglistit
->next
, count
++
254 char *quad2
= strchr(arglistit
->reg
, '/');
256 arglistit
->reg
[2] = 0;
257 type
= getargtype(arglistit
);
258 assert(type
!= NULL
);
263 " AROS_LCAQUAD(%s%s, (__arg%d), %s, %s), \\\n",
264 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
265 type
, count
, arglistit
->reg
, quad2
+1
270 " AROS_LCA(%s%s, (__arg%d), %s), \\\n",
271 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
272 type
, count
, arglistit
->reg
279 " %s, (__%s), %u, %s"
282 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
285 fprintf(out
, "#define %s(", funclistit
->name
);
286 for (arglistit
= funclistit
->arguments
, count
= 1;
288 arglistit
= arglistit
->next
, count
++
291 if (arglistit
!= funclistit
->arguments
)
293 fprintf(out
, "arg%d", count
);
295 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
296 for (arglistit
= funclistit
->arguments
, count
= 1;
298 arglistit
= arglistit
->next
, count
++
300 fprintf(out
, "(arg%d), ", count
);
301 fprintf(out
, "__aros_getbase_%s())\n", cfg
->libbase
);
305 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
307 struct functionarg
*arglistit
= funclistit
->arguments
;
310 isvoid
= strcmp(funclistit
->type
, "void") == 0
311 || strcmp(funclistit
->type
, "VOID") == 0;
319 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
321 cfg
->includenameupper
, varargname
323 for (arglistit
= funclistit
->arguments
, count
= 1;
324 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
325 arglistit
= arglistit
->next
, count
++
328 fprintf(out
, "arg%d, ", count
);
334 for (arglistit
= funclistit
->arguments
, count
= 1;
336 arglistit
= arglistit
->next
, count
++
339 if (arglistit
->next
== NULL
)
341 fprintf(out
, " const IPTR %s_args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) };\\\n", funclistit
->name
);
348 for (arglistit
= funclistit
->arguments
, count
= 1;
350 arglistit
= arglistit
->next
, count
++
353 if (arglistit
!= funclistit
->arguments
)
356 if (arglistit
->next
== NULL
)
358 type
= getargtype(arglistit
);
359 assert(type
!= NULL
);
360 fprintf(out
, "(const %s)(%s_args)", type
, funclistit
->name
);
364 fprintf(out
, "(arg%d)", count
);
369 "#endif /* !NO_INLINE_STDARG */\n"
372 else if (isvararg
== 2)
377 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
378 "static inline %s __inline_%s_%s(%s __%s",
379 cfg
->includenameupper
,
380 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
382 for (arglistit
= funclistit
->arguments
, count
= 0;
383 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
384 arglistit
= arglistit
->next
387 char *type
= getargtype(arglistit
);
389 fprintf(out
, ", %s __arg%d", type
, ++count
);
391 fprintf(out
, ", ...)\n");
398 " va_start(__args, __arg%d);\n"
399 " retval = __inline_%s_%s(",
402 cfg
->basename
, funclistit
->name
404 for (arglistit
= funclistit
->arguments
, count
= 1;
405 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
406 arglistit
= arglistit
->next
, count
++
409 fprintf(out
, "__arg%d, ", count
);
421 for (arglistit
= funclistit
->arguments
, count
= 1;
422 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
423 arglistit
= arglistit
->next
, count
++
426 fprintf(out
, "arg%d, ", count
);
430 " __inline_%s_%s(%s, ",
431 cfg
->basename
, varargname
, cfg
->libbase
433 for (arglistit
= funclistit
->arguments
, count
= 1;
434 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
435 arglistit
= arglistit
->next
, count
++
438 fprintf(out
, "(arg%d), ", count
);
442 "#endif /* !NO_INLINE_STDARG */\n"
445 else if (isvararg
== 3)
450 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
451 "static inline %s __inline_%s_%s(%s __%s",
452 cfg
->includenameupper
,
453 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
455 for (arglistit
= funclistit
->arguments
, count
= 0;
456 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
457 arglistit
= arglistit
->next
460 char *type
= getargtype(arglistit
);
462 fprintf(out
, ", %s __arg%d", type
, ++count
);
464 fprintf(out
, ", ...)\n");
468 fprintf(out
, " %s retval;\n", funclistit
->type
);
472 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
473 " %s__inline_%s_%s(",
475 isvoid
? "" : "retval = ",
476 cfg
->basename
, funclistit
->name
478 for (arglistit
= funclistit
->arguments
, count
= 1;
479 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
480 arglistit
= arglistit
->next
, count
++
483 fprintf(out
, "__arg%d, ", count
);
487 "AROS_SLOWSTACKFORMAT_ARG(__arg%d), __%s);\n"
488 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
496 isvoid
? "" : " retval",
499 for (arglistit
= funclistit
->arguments
, count
= 1;
500 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
501 arglistit
= arglistit
->next
, count
++
504 fprintf(out
, "arg%d, ", count
);
508 " __inline_%s_%s((%s)(%s), ",
509 cfg
->basename
, varargname
,
510 cfg
->libbasetypeptrextern
,
513 for (arglistit
= funclistit
->arguments
, count
= 1;
514 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
515 arglistit
= arglistit
->next
, count
++
518 fprintf(out
, "(arg%d), ", count
);
522 "#endif /* !NO_INLINE_STDARG */\n"
528 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
530 struct stringlist
*aliasesit
;
532 for (aliasesit
= funclistit
->aliases
;
534 aliasesit
= aliasesit
->next
537 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);