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
*, 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';
78 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
81 /* TagList has to be changed in Tags at the end of the functionname */
82 varargname
= strdup(funclistit
->name
);
83 varargname
[strlen(funclistit
->name
)-4] = 's';
84 varargname
[strlen(funclistit
->name
)-3] = '\0';
86 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
87 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
91 varargname
= strdup(funclistit
->name
);
92 varargname
[strlen(funclistit
->name
)-4] = '\0';
94 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
97 varargname
= malloc(strlen(funclistit
->name
));
98 strcpy(varargname
, &funclistit
->name
[1]);
105 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
106 p
= arglistit
->arg
+ 5;
107 while (isspace(*p
)) p
++;
110 if (strncmp(p
, "struct", 6)==0)
113 while (isspace(*p
)) p
++;
114 if (strncmp(p
, "TagItem", 7) == 0)
117 while (isspace(*p
)) p
++;
122 varargname
= malloc(strlen(funclistit
->name
) + 5);
123 strcpy(varargname
, funclistit
->name
);
124 strcat(varargname
, "Tags");
131 writeinlineregister(out
, funclistit
, cfg
, isvararg
);
132 if (!funclistit
->novararg
&& isvararg
)
134 writeinlinevararg(out
, funclistit
, cfg
, isvararg
, varargname
);
138 writealiases(out
, funclistit
, cfg
);
142 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
144 cfg
->includenameupper
,
146 cfg
->includenameupper
153 "#endif /* INLINE_%s_H*/\n",
154 cfg
->includenameupper
160 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
)
162 struct functionarg
*arglistit
;
167 isvoid
= strcmp(funclistit
->type
, "void") == 0
168 || strcmp(funclistit
->type
, "VOID") == 0;
172 "static inline %s __inline_%s_%s(",
173 funclistit
->type
, cfg
->basename
, funclistit
->name
175 for (arglistit
= funclistit
->arguments
, count
= 1;
177 arglistit
= arglistit
->next
, count
++
180 type
= getargtype(arglistit
);
181 fprintf(out
, "%s%s __arg%d, ",
182 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
184 if (strchr(arglistit
->reg
, '/') != NULL
) {
196 " AROS_LIBREQ(%s, %d)\n",
197 cfg
->libbase
, funclistit
->version
202 " %sAROS_LC%d%s(%s, %s,\n",
203 (isvoid
) ? "" : "return ",
204 funclistit
->argcount
, (isvoid
) ? "NR" : "",
205 funclistit
->type
, funclistit
->name
208 for (arglistit
= funclistit
->arguments
, count
= 1;
210 arglistit
= arglistit
->next
, count
++
213 type
= getargtype(arglistit
);
214 assert(type
!= NULL
);
216 " AROS_LCA(%s%s,(__arg%d),%s),\n",
217 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
218 type
, count
, arglistit
->reg
223 else /* nquad != 0 */
227 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
228 (isvoid
) ? "" : "return ", narg
,
229 nquad
, (isvoid
) ? "NR" : "",
230 funclistit
->type
, funclistit
->name
234 " %sAROS_LCQUAD%d%s(%s, %s,\n",
235 (isvoid
) ? "" : "return ",
236 nquad
, (isvoid
) ? "NR" : "",
237 funclistit
->type
, funclistit
->name
241 for (arglistit
= funclistit
->arguments
, count
= 1;
243 arglistit
= arglistit
->next
, count
++
246 char *quad2
= strchr(arglistit
->reg
, '/');
248 arglistit
->reg
[2] = 0;
249 type
= getargtype(arglistit
);
250 assert(type
!= NULL
);
255 " AROS_LCAQUAD(%s%s, (__arg%d), %s, %s), \\\n",
256 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
257 type
, count
, arglistit
->reg
, quad2
+1
262 " AROS_LCA(%s%s, (__arg%d), %s), \\\n",
263 ((isvararg
) && (!arglistit
->next
)) ? "const " : "",
264 type
, count
, arglistit
->reg
271 " %s, (__%s), %u, %s"
274 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
277 fprintf(out
, "#define %s(", funclistit
->name
);
278 for (arglistit
= funclistit
->arguments
, count
= 1;
280 arglistit
= arglistit
->next
, count
++
283 if (arglistit
!= funclistit
->arguments
)
285 fprintf(out
, "arg%d", count
);
287 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
288 for (arglistit
= funclistit
->arguments
, count
= 1;
290 arglistit
= arglistit
->next
, count
++
292 fprintf(out
, "(arg%d), ", count
);
293 fprintf(out
, "__aros_getbase_%s())\n", cfg
->libbase
);
297 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
, char isvararg
, char *varargname
)
299 struct functionarg
*arglistit
= funclistit
->arguments
;
307 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
309 cfg
->includenameupper
, varargname
311 for (arglistit
= funclistit
->arguments
, count
= 1;
312 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
313 arglistit
= arglistit
->next
, count
++
316 fprintf(out
, "arg%d, ", count
);
322 for (arglistit
= funclistit
->arguments
, count
= 1;
324 arglistit
= arglistit
->next
, count
++
327 if (arglistit
->next
== NULL
)
329 fprintf(out
, " const IPTR %s_args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) };\\\n", funclistit
->name
);
336 for (arglistit
= funclistit
->arguments
, count
= 1;
338 arglistit
= arglistit
->next
, count
++
341 if (arglistit
!= funclistit
->arguments
)
344 if (arglistit
->next
== NULL
)
346 type
= getargtype(arglistit
);
347 assert(type
!= NULL
);
348 fprintf(out
, "(const %s)(%s_args)", type
, funclistit
->name
);
352 fprintf(out
, "(arg%d)", count
);
357 "#endif /* !NO_INLINE_STDARG */\n"
360 else if (isvararg
== 2)
365 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
366 "static inline %s __inline_%s_%s(%s __%s",
367 cfg
->includenameupper
,
368 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
370 for (arglistit
= funclistit
->arguments
, count
= 0;
371 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
372 arglistit
= arglistit
->next
375 char *type
= getargtype(arglistit
);
377 fprintf(out
, ", %s __arg%d", type
, ++count
);
379 fprintf(out
, ", ...)\n");
386 " va_start(__args, __arg%d);\n"
387 " retval = __inline_%s_%s(",
390 cfg
->basename
, funclistit
->name
392 for (arglistit
= funclistit
->arguments
, count
= 1;
393 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
394 arglistit
= arglistit
->next
, count
++
397 fprintf(out
, "__arg%d, ", count
);
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 " __inline_%s_%s(%s, ",
419 cfg
->basename
, varargname
, cfg
->libbase
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 "#endif /* !NO_INLINE_STDARG */\n"
436 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
438 struct stringlist
*aliasesit
;
440 for (aliasesit
= funclistit
->aliases
;
442 aliasesit
= aliasesit
->next
445 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);