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
*);
10 static void writeinlinevararg(FILE *, struct functionhead
*, struct config
*);
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 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
)
54 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
56 cfg
->includenameupper
,
61 writeinlineregister(out
, funclistit
, cfg
);
62 if (!funclistit
->novararg
)
63 writeinlinevararg(out
, funclistit
, cfg
);
65 writealiases(out
, funclistit
, cfg
);
69 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
71 cfg
->includenameupper
,
80 "#endif /* INLINE_%s_H*/\n",
88 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
90 struct functionarg
*arglistit
;
95 isvoid
= strcmp(funclistit
->type
, "void") == 0
96 || strcmp(funclistit
->type
, "VOID") == 0;
100 "static inline %s __inline_%s_%s(",
101 funclistit
->type
, cfg
->basename
, funclistit
->name
103 for (arglistit
= funclistit
->arguments
, count
= 1;
105 arglistit
= arglistit
->next
, count
++
108 type
= getargtype(arglistit
);
109 fprintf(out
, "%s __arg%d, ", type
, count
);
110 if (strchr(arglistit
->reg
, '/') != NULL
) {
122 " AROS_LIBREQ(%s, %d)\n",
123 cfg
->libbase
, funclistit
->version
128 " %sAROS_LC%d%s(%s, %s,\n",
129 (isvoid
) ? "" : "return ",
130 funclistit
->argcount
, (isvoid
) ? "NR" : "",
131 funclistit
->type
, funclistit
->name
134 for (arglistit
= funclistit
->arguments
, count
= 1;
136 arglistit
= arglistit
->next
, count
++
139 type
= getargtype(arglistit
);
140 assert(type
!= NULL
);
142 " AROS_LCA(%s,(__arg%d),%s),\n",
143 type
, count
, arglistit
->reg
148 else /* nquad != 0 */
152 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
153 (isvoid
) ? "" : "return ", narg
,
154 nquad
, (isvoid
) ? "NR" : "",
155 funclistit
->type
, funclistit
->name
159 " %sAROS_LCQUAD%d%s(%s, %s,\n",
160 (isvoid
) ? "" : "return ",
161 nquad
, (isvoid
) ? "NR" : "",
162 funclistit
->type
, funclistit
->name
166 for (arglistit
= funclistit
->arguments
, count
= 1;
168 arglistit
= arglistit
->next
, count
++
171 char *quad2
= strchr(arglistit
->reg
, '/');
173 arglistit
->reg
[2] = 0;
174 type
= getargtype(arglistit
);
175 assert(type
!= NULL
);
180 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
181 type
, count
, arglistit
->reg
, quad2
+1
186 " AROS_LCA(%s, (__arg%d), %s), \\\n",
187 type
, count
, arglistit
->reg
194 " %s, (__%s), %u, %s"
197 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
200 fprintf(out
, "#define %s(", funclistit
->name
);
201 for (arglistit
= funclistit
->arguments
, count
= 1;
203 arglistit
= arglistit
->next
, count
++
206 if (arglistit
!= funclistit
->arguments
)
208 fprintf(out
, "arg%d", count
);
210 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
211 for (arglistit
= funclistit
->arguments
, count
= 1;
213 arglistit
= arglistit
->next
, count
++
215 fprintf(out
, "(arg%d), ", count
);
216 fprintf(out
, "__aros_getbase_%s())\n", cfg
->libbase
);
220 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
222 struct functionarg
*arglistit
= funclistit
->arguments
;
223 char isvararg
= 0, *varargname
, *lastname
;
225 /* Go to last argument */
226 if (arglistit
== NULL
)
229 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
231 lastname
= getargname(arglistit
);
232 assert(lastname
!= NULL
);
234 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
237 varargname
= strdup(funclistit
->name
);
238 varargname
[strlen(funclistit
->name
)-1] = '\0';
240 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
243 /* TagList has to be changed in Tags at the end of the functionname */
244 varargname
= strdup(funclistit
->name
);
245 varargname
[strlen(funclistit
->name
)-4] = 's';
246 varargname
[strlen(funclistit
->name
)-3] = '\0';
248 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
249 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
253 varargname
= strdup(funclistit
->name
);
254 varargname
[strlen(funclistit
->name
)-4] = '\0';
256 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
259 varargname
= malloc(strlen(funclistit
->name
));
260 strcpy(varargname
, &funclistit
->name
[1]);
267 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
268 p
= arglistit
->arg
+ 5;
269 while (isspace(*p
)) p
++;
272 if (strncmp(p
, "struct", 6)==0)
275 while (isspace(*p
)) p
++;
276 if (strncmp(p
, "TagItem", 7) == 0)
279 while (isspace(*p
)) p
++;
284 varargname
= malloc(strlen(funclistit
->name
) + 5);
285 strcpy(varargname
, funclistit
->name
);
286 strcat(varargname
, "Tags");
297 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
299 cfg
->includenameupper
, varargname
301 for (arglistit
= funclistit
->arguments
, count
= 1;
302 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
303 arglistit
= arglistit
->next
, count
++
306 fprintf(out
, "arg%d, ", count
);
314 for (arglistit
= funclistit
->arguments
, count
= 1;
316 arglistit
= arglistit
->next
, count
++
319 if (arglistit
!= funclistit
->arguments
)
322 if (arglistit
->next
== NULL
)
324 type
= getargtype(arglistit
);
325 assert(type
!= NULL
);
326 fprintf(out
, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
330 fprintf(out
, "(arg%d)", count
);
335 "#endif /* !NO_INLINE_STDARG */\n"
340 else if (isvararg
== 2)
345 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
346 "static inline %s __inline_%s_%s(%s __%s",
347 cfg
->includenameupper
,
348 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
350 for (arglistit
= funclistit
->arguments
, count
= 0;
351 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
352 arglistit
= arglistit
->next
355 char *type
= getargtype(arglistit
);
357 fprintf(out
, ", %s __arg%d", type
, ++count
);
359 fprintf(out
, ", ...)\n");
366 " va_start(__args, __arg%d);\n"
367 " retval = __inline_%s_%s(",
370 cfg
->basename
, funclistit
->name
372 for (arglistit
= funclistit
->arguments
, count
= 1;
373 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
374 arglistit
= arglistit
->next
, count
++
377 fprintf(out
, "__arg%d, ", count
);
389 for (arglistit
= funclistit
->arguments
, count
= 1;
390 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
391 arglistit
= arglistit
->next
, count
++
394 fprintf(out
, "arg%d, ", count
);
398 " __inline_%s_%s(%s, ",
399 cfg
->basename
, varargname
, cfg
->libbase
401 for (arglistit
= funclistit
->arguments
, count
= 1;
402 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
403 arglistit
= arglistit
->next
, count
++
406 fprintf(out
, "(arg%d), ", count
);
410 "#endif /* !NO_INLINE_STDARG */\n"
418 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
420 struct stringlist
*aliasesit
;
422 for (aliasesit
= funclistit
->aliases
;
424 aliasesit
= aliasesit
->next
427 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);