2 Copyright © 1995-2017, 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 "#if !defined(__%s_LIBBASE)\n"
45 "# if !defined(__NOLIBBASE__) && !defined(__%s_NOLIBBASE__)\n"
46 "# define __%s_LIBBASE __aros_getbase_%s()\n"
48 "# define __%s_LIBBASE %s\n"
52 cfg
->includenameupper
, cfg
->includenameupper
, banner
, cfg
->modulename
,
53 cfg
->includenameupper
, cfg
->includenameupper
,
54 cfg
->includenameupper
, cfg
->libbase
,
55 cfg
->includenameupper
, cfg
->libbase
59 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
61 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
63 char isvararg
= 0, *varargname
= NULL
, *lastname
;
67 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
69 cfg
->includenameupper
,
74 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
76 struct functionarg
*arglistit
= funclistit
->arguments
;
78 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
80 lastname
= getargname(arglistit
);
81 assert(lastname
!= NULL
);
83 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
86 varargname
= strdup(funclistit
->name
);
87 varargname
[strlen(funclistit
->name
)-1] = '\0';
88 if (arglistit
&& strncmp(arglistit
->arg
, "RAWARG", 6) == 0)
91 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
94 /* TagList has to be changed to Tags at the end of the functionname */
95 varargname
= strdup(funclistit
->name
);
96 varargname
[strlen(funclistit
->name
)-4] = 's';
97 varargname
[strlen(funclistit
->name
)-3] = '\0';
99 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
100 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
104 varargname
= strdup(funclistit
->name
);
105 varargname
[strlen(funclistit
->name
)-4] = '\0';
107 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
110 varargname
= malloc(strlen(funclistit
->name
));
111 strcpy(varargname
, &funclistit
->name
[1]);
113 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "RAWARG", 6) == 0))
116 varargname
= malloc(strlen(funclistit
->name
));
117 strcpy(varargname
, &funclistit
->name
[1]);
124 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
125 p
= arglistit
->arg
+ 5;
126 while (isspace(*p
)) p
++;
129 if (strncmp(p
, "struct", 6)==0)
132 while (isspace(*p
)) p
++;
133 if (strncmp(p
, "TagItem", 7) == 0)
136 while (isspace(*p
)) p
++;
141 varargname
= malloc(strlen(funclistit
->name
) + 5);
142 strcpy(varargname
, funclistit
->name
);
143 strcat(varargname
, "Tags");
150 writeinlineregister(out
, funclistit
, cfg
, isvararg
);
151 if (!funclistit
->novararg
&& isvararg
)
153 writeinlinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
157 writealiases(out
, funclistit
, cfg
);
161 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
163 cfg
->includenameupper
,
165 cfg
->includenameupper
172 "#endif /* INLINE_%s_H*/\n",
173 cfg
->includenameupper
179 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
181 struct functionarg
*arglistit
;
186 isvoid
= strcmp(funclistit
->type
, "void") == 0
187 || strcmp(funclistit
->type
, "VOID") == 0;
191 "static inline %s __inline_%s_%s(",
192 funclistit
->type
, cfg
->basename
, funclistit
->name
194 for (arglistit
= funclistit
->arguments
, count
= 1;
196 arglistit
= arglistit
->next
, count
++
199 type
= getargtype(arglistit
);
200 fprintf(out
, "%s __arg%d, ",
202 if (strchr(arglistit
->reg
, '/') != NULL
) {
214 " AROS_LIBREQ(%s, %d)\n",
215 cfg
->libbase
, funclistit
->version
220 " %sAROS_LC%d%s(%s, %s,\n",
221 (isvoid
) ? "" : "return ",
222 funclistit
->argcount
, (isvoid
) ? "NR" : "",
223 funclistit
->type
, funclistit
->name
226 for (arglistit
= funclistit
->arguments
, count
= 1;
228 arglistit
= arglistit
->next
, count
++
231 type
= getargtype(arglistit
);
232 assert(type
!= NULL
);
234 " AROS_LCA(%s,(__arg%d),%s),\n",
235 type
, count
, arglistit
->reg
240 else /* nquad != 0 */
244 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
245 (isvoid
) ? "" : "return ", narg
,
246 nquad
, (isvoid
) ? "NR" : "",
247 funclistit
->type
, funclistit
->name
251 " %sAROS_LCQUAD%d%s(%s, %s,\n",
252 (isvoid
) ? "" : "return ",
253 nquad
, (isvoid
) ? "NR" : "",
254 funclistit
->type
, funclistit
->name
258 for (arglistit
= funclistit
->arguments
, count
= 1;
260 arglistit
= arglistit
->next
, count
++
263 char *quad2
= strchr(arglistit
->reg
, '/');
265 arglistit
->reg
[2] = 0;
266 type
= getargtype(arglistit
);
267 assert(type
!= NULL
);
272 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
273 type
, count
, arglistit
->reg
, quad2
+1
278 " AROS_LCA(%s, (__arg%d), %s), \\\n",
279 type
, count
, arglistit
->reg
286 " %s, (__%s), %u, %s"
289 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
292 fprintf(out
, "#define %s(", funclistit
->name
);
293 for (arglistit
= funclistit
->arguments
, count
= 1;
295 arglistit
= arglistit
->next
, count
++
298 if (arglistit
!= funclistit
->arguments
)
300 fprintf(out
, "arg%d", count
);
302 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
303 for (arglistit
= funclistit
->arguments
, count
= 1;
305 arglistit
= arglistit
->next
, count
++
307 fprintf(out
, "(arg%d), ", count
);
308 fprintf(out
, "__%s_LIBBASE)\n", cfg
->includenameupper
);
312 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
314 struct functionarg
*arglistit
= funclistit
->arguments
;
317 isvoid
= strcmp(funclistit
->type
, "void") == 0
318 || strcmp(funclistit
->type
, "VOID") == 0;
326 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
328 cfg
->includenameupper
, varargname
330 for (arglistit
= funclistit
->arguments
, count
= 1;
331 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
332 arglistit
= arglistit
->next
, count
++
335 fprintf(out
, "arg%d, ", count
);
341 for (arglistit
= funclistit
->arguments
, count
= 1;
343 arglistit
= arglistit
->next
, count
++
346 if (arglistit
->next
== NULL
)
348 fprintf(out
, " const IPTR %s_args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) };\\\n", funclistit
->name
);
355 for (arglistit
= funclistit
->arguments
, count
= 1;
357 arglistit
= arglistit
->next
, count
++
360 if (arglistit
!= funclistit
->arguments
)
363 if (arglistit
->next
== NULL
)
365 type
= getargtype(arglistit
);
366 assert(type
!= NULL
);
367 fprintf(out
, "(%s)(%s_args)", type
, funclistit
->name
);
371 fprintf(out
, "(arg%d)", count
);
376 "#endif /* !NO_INLINE_STDARG */\n"
379 else if (isvararg
== 2)
384 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
385 "static inline %s __inline_%s_%s(%s __%s",
386 cfg
->includenameupper
,
387 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
389 for (arglistit
= funclistit
->arguments
, count
= 0;
390 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
391 arglistit
= arglistit
->next
394 char *type
= getargtype(arglistit
);
396 fprintf(out
, ", %s __arg%d", type
, ++count
);
398 fprintf(out
, ", ...)\n");
405 " va_start(__args, __arg%d);\n"
406 " retval = __inline_%s_%s(",
409 cfg
->basename
, funclistit
->name
411 for (arglistit
= funclistit
->arguments
, count
= 1;
412 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
413 arglistit
= arglistit
->next
, count
++
416 fprintf(out
, "__arg%d, ", count
);
428 for (arglistit
= funclistit
->arguments
, count
= 1;
429 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
430 arglistit
= arglistit
->next
, count
++
433 fprintf(out
, "arg%d, ", count
);
438 cfg
->basename
, varargname
440 fprintf(out
, "(%s)__%s_LIBBASE, ",
441 cfg
->libbasetypeptrextern
,
442 cfg
->includenameupper
);
443 for (arglistit
= funclistit
->arguments
, count
= 1;
444 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
445 arglistit
= arglistit
->next
, count
++
448 fprintf(out
, "(arg%d), ", count
);
452 "#endif /* !NO_INLINE_STDARG */\n"
455 else if (isvararg
== 3)
460 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
461 "static inline %s __inline_%s_%s(%s __%s",
462 cfg
->includenameupper
,
463 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
465 for (arglistit
= funclistit
->arguments
, count
= 0;
466 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
467 arglistit
= arglistit
->next
470 char *type
= getargtype(arglistit
);
472 fprintf(out
, ", %s __arg%d", type
, ++count
);
474 fprintf(out
, ", ...)\n");
478 fprintf(out
, " %s retval;\n", funclistit
->type
);
482 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
483 " %s__inline_%s_%s(",
485 isvoid
? "" : "retval = ",
486 cfg
->basename
, funclistit
->name
488 for (arglistit
= funclistit
->arguments
, count
= 1;
489 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
490 arglistit
= arglistit
->next
, count
++
493 fprintf(out
, "__arg%d, ", count
);
497 "AROS_SLOWSTACKFORMAT_ARG(__arg%d), __%s);\n"
498 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
506 isvoid
? "" : " retval",
509 for (arglistit
= funclistit
->arguments
, count
= 1;
510 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
511 arglistit
= arglistit
->next
, count
++
514 fprintf(out
, "arg%d, ", count
);
519 cfg
->basename
, varargname
521 fprintf(out
, "(%s)__%s_LIBBASE, ",
522 cfg
->libbasetypeptrextern
,
523 cfg
->includenameupper
);
524 for (arglistit
= funclistit
->arguments
, count
= 1;
525 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
526 arglistit
= arglistit
->next
, count
++
529 fprintf(out
, "(arg%d), ", count
);
533 "#endif /* !NO_INLINE_STDARG */\n"
539 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
541 struct stringlist
*aliasesit
;
543 for (aliasesit
= funclistit
->aliases
;
545 aliasesit
= aliasesit
->next
548 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);