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 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 __arg%d, ",
191 if (strchr(arglistit
->reg
, '/') != NULL
) {
203 " AROS_LIBREQ(%s, %d)\n",
204 cfg
->libbase
, funclistit
->version
209 " %sAROS_LC%d%s(%s, %s,\n",
210 (isvoid
) ? "" : "return ",
211 funclistit
->argcount
, (isvoid
) ? "NR" : "",
212 funclistit
->type
, funclistit
->name
215 for (arglistit
= funclistit
->arguments
, count
= 1;
217 arglistit
= arglistit
->next
, count
++
220 type
= getargtype(arglistit
);
221 assert(type
!= NULL
);
223 " AROS_LCA(%s,(__arg%d),%s),\n",
224 type
, count
, arglistit
->reg
229 else /* nquad != 0 */
233 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
234 (isvoid
) ? "" : "return ", narg
,
235 nquad
, (isvoid
) ? "NR" : "",
236 funclistit
->type
, funclistit
->name
240 " %sAROS_LCQUAD%d%s(%s, %s,\n",
241 (isvoid
) ? "" : "return ",
242 nquad
, (isvoid
) ? "NR" : "",
243 funclistit
->type
, funclistit
->name
247 for (arglistit
= funclistit
->arguments
, count
= 1;
249 arglistit
= arglistit
->next
, count
++
252 char *quad2
= strchr(arglistit
->reg
, '/');
254 arglistit
->reg
[2] = 0;
255 type
= getargtype(arglistit
);
256 assert(type
!= NULL
);
261 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
262 type
, count
, arglistit
->reg
, quad2
+1
267 " AROS_LCA(%s, (__arg%d), %s), \\\n",
268 type
, count
, arglistit
->reg
275 " %s, (__%s), %u, %s"
278 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
281 fprintf(out
, "#define %s(", funclistit
->name
);
282 for (arglistit
= funclistit
->arguments
, count
= 1;
284 arglistit
= arglistit
->next
, count
++
287 if (arglistit
!= funclistit
->arguments
)
289 fprintf(out
, "arg%d", count
);
291 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
292 for (arglistit
= funclistit
->arguments
, count
= 1;
294 arglistit
= arglistit
->next
, count
++
296 fprintf(out
, "(arg%d), ", count
);
297 fprintf(out
, "__aros_getbase_%s())\n", cfg
->libbase
);
301 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
303 struct functionarg
*arglistit
= funclistit
->arguments
;
306 isvoid
= strcmp(funclistit
->type
, "void") == 0
307 || strcmp(funclistit
->type
, "VOID") == 0;
315 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
317 cfg
->includenameupper
, varargname
319 for (arglistit
= funclistit
->arguments
, count
= 1;
320 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
321 arglistit
= arglistit
->next
, count
++
324 fprintf(out
, "arg%d, ", count
);
330 for (arglistit
= funclistit
->arguments
, count
= 1;
332 arglistit
= arglistit
->next
, count
++
335 if (arglistit
->next
== NULL
)
337 fprintf(out
, " const IPTR %s_args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) };\\\n", funclistit
->name
);
344 for (arglistit
= funclistit
->arguments
, count
= 1;
346 arglistit
= arglistit
->next
, count
++
349 if (arglistit
!= funclistit
->arguments
)
352 if (arglistit
->next
== NULL
)
354 type
= getargtype(arglistit
);
355 assert(type
!= NULL
);
356 fprintf(out
, "(%s)(%s_args)", type
, funclistit
->name
);
360 fprintf(out
, "(arg%d)", count
);
365 "#endif /* !NO_INLINE_STDARG */\n"
368 else if (isvararg
== 2)
373 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
374 "static inline %s __inline_%s_%s(%s __%s",
375 cfg
->includenameupper
,
376 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
378 for (arglistit
= funclistit
->arguments
, count
= 0;
379 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
380 arglistit
= arglistit
->next
383 char *type
= getargtype(arglistit
);
385 fprintf(out
, ", %s __arg%d", type
, ++count
);
387 fprintf(out
, ", ...)\n");
394 " va_start(__args, __arg%d);\n"
395 " retval = __inline_%s_%s(",
398 cfg
->basename
, funclistit
->name
400 for (arglistit
= funclistit
->arguments
, count
= 1;
401 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
402 arglistit
= arglistit
->next
, count
++
405 fprintf(out
, "__arg%d, ", count
);
417 for (arglistit
= funclistit
->arguments
, count
= 1;
418 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
419 arglistit
= arglistit
->next
, count
++
422 fprintf(out
, "arg%d, ", count
);
427 cfg
->basename
, varargname
429 fprintf(out
, "(%s)__aros_getbase_%s(), ",
430 cfg
->libbasetypeptrextern
,
432 for (arglistit
= funclistit
->arguments
, count
= 1;
433 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
434 arglistit
= arglistit
->next
, count
++
437 fprintf(out
, "(arg%d), ", count
);
441 "#endif /* !NO_INLINE_STDARG */\n"
444 else if (isvararg
== 3)
449 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
450 "static inline %s __inline_%s_%s(%s __%s",
451 cfg
->includenameupper
,
452 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
454 for (arglistit
= funclistit
->arguments
, count
= 0;
455 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
456 arglistit
= arglistit
->next
459 char *type
= getargtype(arglistit
);
461 fprintf(out
, ", %s __arg%d", type
, ++count
);
463 fprintf(out
, ", ...)\n");
467 fprintf(out
, " %s retval;\n", funclistit
->type
);
471 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
472 " %s__inline_%s_%s(",
474 isvoid
? "" : "retval = ",
475 cfg
->basename
, funclistit
->name
477 for (arglistit
= funclistit
->arguments
, count
= 1;
478 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
479 arglistit
= arglistit
->next
, count
++
482 fprintf(out
, "__arg%d, ", count
);
486 "AROS_SLOWSTACKFORMAT_ARG(__arg%d), __%s);\n"
487 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
495 isvoid
? "" : " retval",
498 for (arglistit
= funclistit
->arguments
, count
= 1;
499 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
500 arglistit
= arglistit
->next
, count
++
503 fprintf(out
, "arg%d, ", count
);
508 cfg
->basename
, varargname
510 fprintf(out
, "(%s)__aros_getbase_%s(), ",
511 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
);