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
46 if ((cfg
->options
& OPTION_RELLINKLIB
) || (cfg
->options
& OPTION_DUPBASE
))
49 "#if !defined(__%s_LIBBASE)\n"
50 "# if !defined(__NOLIBBASE__) && !defined(__%s_NOLIBBASE__)\n"
51 "# define __%s_LIBBASE __aros_getbase_%s()\n"
53 "# define __%s_LIBBASE %s\n"
57 cfg
->includenameupper
, cfg
->includenameupper
,
58 cfg
->includenameupper
, cfg
->libbase
,
59 cfg
->includenameupper
, cfg
->libbase
64 "#if !defined(__%s_LIBBASE)\n"
65 "# define __%s_LIBBASE %s\n"
68 cfg
->includenameupper
,
69 cfg
->includenameupper
, cfg
->libbase
73 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
75 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
) && funclistit
->libcall
!= STACK
)
77 char isvararg
= 0, *varargname
= NULL
, *lastname
;
81 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
83 cfg
->includenameupper
,
88 if ((!funclistit
->novararg
) && (funclistit
->arguments
))
90 struct functionarg
*arglistit
= funclistit
->arguments
;
92 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
94 lastname
= getargname(arglistit
);
95 assert(lastname
!= NULL
);
97 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
100 varargname
= strdup(funclistit
->name
);
101 varargname
[strlen(funclistit
->name
)-1] = '\0';
102 if (arglistit
&& strncmp(arglistit
->arg
, "RAWARG", 6) == 0)
105 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
108 /* TagList has to be changed to Tags at the end of the functionname */
109 varargname
= strdup(funclistit
->name
);
110 varargname
[strlen(funclistit
->name
)-4] = 's';
111 varargname
[strlen(funclistit
->name
)-3] = '\0';
113 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
114 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
118 varargname
= strdup(funclistit
->name
);
119 varargname
[strlen(funclistit
->name
)-4] = '\0';
121 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
124 varargname
= malloc(strlen(funclistit
->name
));
125 strcpy(varargname
, &funclistit
->name
[1]);
127 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "RAWARG", 6) == 0))
130 varargname
= malloc(strlen(funclistit
->name
));
131 strcpy(varargname
, &funclistit
->name
[1]);
138 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
139 p
= arglistit
->arg
+ 5;
140 while (isspace(*p
)) p
++;
143 if (strncmp(p
, "struct", 6)==0)
146 while (isspace(*p
)) p
++;
147 if (strncmp(p
, "TagItem", 7) == 0)
150 while (isspace(*p
)) p
++;
155 varargname
= malloc(strlen(funclistit
->name
) + 5);
156 strcpy(varargname
, funclistit
->name
);
157 strcat(varargname
, "Tags");
164 writeinlineregister(out
, funclistit
, cfg
, isvararg
);
165 if (!funclistit
->novararg
&& isvararg
)
167 writeinlinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
171 writealiases(out
, funclistit
, cfg
);
175 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
177 cfg
->includenameupper
,
179 cfg
->includenameupper
186 "#endif /* INLINE_%s_H*/\n",
187 cfg
->includenameupper
193 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
195 struct functionarg
*arglistit
;
200 isvoid
= strcmp(funclistit
->type
, "void") == 0
201 || strcmp(funclistit
->type
, "VOID") == 0;
205 "static inline %s __inline_%s_%s(",
206 funclistit
->type
, cfg
->basename
, funclistit
->name
208 for (arglistit
= funclistit
->arguments
, count
= 1;
210 arglistit
= arglistit
->next
, count
++
213 type
= getargtype(arglistit
);
214 fprintf(out
, "%s __arg%d, ",
216 if (strchr(arglistit
->reg
, '/') != NULL
) {
228 " AROS_LIBREQ(%s, %d)\n",
229 cfg
->libbase
, funclistit
->version
234 " %sAROS_LC%d%s(%s, %s,\n",
235 (isvoid
) ? "" : "return ",
236 funclistit
->argcount
, (isvoid
) ? "NR" : "",
237 funclistit
->type
, funclistit
->name
240 for (arglistit
= funclistit
->arguments
, count
= 1;
242 arglistit
= arglistit
->next
, count
++
245 type
= getargtype(arglistit
);
246 assert(type
!= NULL
);
248 " AROS_LCA(%s,(__arg%d),%s),\n",
249 type
, count
, arglistit
->reg
254 else /* nquad != 0 */
258 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
259 (isvoid
) ? "" : "return ", narg
,
260 nquad
, (isvoid
) ? "NR" : "",
261 funclistit
->type
, funclistit
->name
265 " %sAROS_LCQUAD%d%s(%s, %s,\n",
266 (isvoid
) ? "" : "return ",
267 nquad
, (isvoid
) ? "NR" : "",
268 funclistit
->type
, funclistit
->name
272 for (arglistit
= funclistit
->arguments
, count
= 1;
274 arglistit
= arglistit
->next
, count
++
277 char *quad2
= strchr(arglistit
->reg
, '/');
279 arglistit
->reg
[2] = 0;
280 type
= getargtype(arglistit
);
281 assert(type
!= NULL
);
286 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \n",
287 type
, count
, arglistit
->reg
, quad2
+1
292 " AROS_LCA(%s, (__arg%d), %s), \n",
293 type
, count
, arglistit
->reg
300 " %s, (__%s), %u, %s"
303 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
306 fprintf(out
, "#define %s(", funclistit
->name
);
307 for (arglistit
= funclistit
->arguments
, count
= 1;
309 arglistit
= arglistit
->next
, count
++
312 if (arglistit
!= funclistit
->arguments
)
314 fprintf(out
, "arg%d", count
);
316 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
317 for (arglistit
= funclistit
->arguments
, count
= 1;
319 arglistit
= arglistit
->next
, count
++
321 fprintf(out
, "(arg%d), ", count
);
322 fprintf(out
, "__%s_LIBBASE)\n", cfg
->includenameupper
);
326 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
328 struct functionarg
*arglistit
= funclistit
->arguments
;
331 isvoid
= strcmp(funclistit
->type
, "void") == 0
332 || strcmp(funclistit
->type
, "VOID") == 0;
340 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
342 cfg
->includenameupper
, varargname
344 for (arglistit
= funclistit
->arguments
, count
= 1;
345 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
346 arglistit
= arglistit
->next
, count
++
349 fprintf(out
, "arg%d, ", count
);
355 for (arglistit
= funclistit
->arguments
, count
= 1;
357 arglistit
= arglistit
->next
, count
++
360 if (arglistit
->next
== NULL
)
362 fprintf(out
, " const IPTR %s_args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) };\\\n", funclistit
->name
);
369 for (arglistit
= funclistit
->arguments
, count
= 1;
371 arglistit
= arglistit
->next
, count
++
374 if (arglistit
!= funclistit
->arguments
)
377 if (arglistit
->next
== NULL
)
379 type
= getargtype(arglistit
);
380 assert(type
!= NULL
);
381 fprintf(out
, "(%s)(%s_args)", type
, funclistit
->name
);
385 fprintf(out
, "(arg%d)", count
);
390 "#endif /* !NO_INLINE_STDARG */\n"
393 else if (isvararg
== 2)
398 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
399 "static inline %s __inline_%s_%s(%s __%s",
400 cfg
->includenameupper
,
401 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
403 for (arglistit
= funclistit
->arguments
, count
= 0;
404 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
405 arglistit
= arglistit
->next
408 char *type
= getargtype(arglistit
);
410 fprintf(out
, ", %s __arg%d", type
, ++count
);
412 fprintf(out
, ", ...)\n");
419 " va_start(__args, __arg%d);\n"
420 " retval = __inline_%s_%s(",
423 cfg
->basename
, funclistit
->name
425 for (arglistit
= funclistit
->arguments
, count
= 1;
426 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
427 arglistit
= arglistit
->next
, count
++
430 fprintf(out
, "__arg%d, ", count
);
442 for (arglistit
= funclistit
->arguments
, count
= 1;
443 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
444 arglistit
= arglistit
->next
, count
++
447 fprintf(out
, "arg%d, ", count
);
452 cfg
->basename
, varargname
454 fprintf(out
, "(%s)__%s_LIBBASE, ",
455 cfg
->libbasetypeptrextern
,
456 cfg
->includenameupper
);
457 for (arglistit
= funclistit
->arguments
, count
= 1;
458 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
459 arglistit
= arglistit
->next
, count
++
462 fprintf(out
, "(arg%d), ", count
);
466 "#endif /* !NO_INLINE_STDARG */\n"
469 else if (isvararg
== 3)
474 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
475 "static inline %s __inline_%s_%s(%s __%s",
476 cfg
->includenameupper
,
477 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
479 for (arglistit
= funclistit
->arguments
, count
= 0;
480 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
481 arglistit
= arglistit
->next
484 char *type
= getargtype(arglistit
);
486 fprintf(out
, ", %s __arg%d", type
, ++count
);
488 fprintf(out
, ", ...)\n");
492 fprintf(out
, " %s retval;\n", funclistit
->type
);
496 " AROS_SLOWSTACKFORMAT_PRE(__arg%d);\n"
497 " %s__inline_%s_%s(",
499 isvoid
? "" : "retval = ",
500 cfg
->basename
, funclistit
->name
502 for (arglistit
= funclistit
->arguments
, count
= 1;
503 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
504 arglistit
= arglistit
->next
, count
++
507 fprintf(out
, "__arg%d, ", count
);
511 "AROS_SLOWSTACKFORMAT_ARG(__arg%d), __%s);\n"
512 " AROS_SLOWSTACKFORMAT_POST(__arg%d);\n"
520 isvoid
? "" : " retval",
523 for (arglistit
= funclistit
->arguments
, count
= 1;
524 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
525 arglistit
= arglistit
->next
, count
++
528 fprintf(out
, "arg%d, ", count
);
533 cfg
->basename
, varargname
535 fprintf(out
, "(%s)__%s_LIBBASE, ",
536 cfg
->libbasetypeptrextern
,
537 cfg
->includenameupper
);
538 for (arglistit
= funclistit
->arguments
, count
= 1;
539 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
540 arglistit
= arglistit
->next
, count
++
543 fprintf(out
, "(arg%d), ", count
);
547 "#endif /* !NO_INLINE_STDARG */\n"
553 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
555 struct stringlist
*aliasesit
;
557 for (aliasesit
= funclistit
->aliases
;
559 aliasesit
= aliasesit
->next
562 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);