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
->modulename
);
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
->modulenameupper
, cfg
->modulenameupper
, banner
, cfg
->modulename
48 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
50 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
54 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
61 if (funclistit
->libcall
!= STACK
)
63 writeinlineregister(out
, funclistit
, cfg
);
64 if (!funclistit
->novararg
)
65 writeinlinevararg(out
, funclistit
, cfg
);
67 else /* libcall == STACK */
69 /* This is the same as in defines */
70 writedefinestack(out
, funclistit
, cfg
);
73 writealiases(out
, funclistit
, cfg
);
77 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
88 "#endif /* INLINE_%s_H*/\n",
96 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
98 struct functionarg
*arglistit
;
103 isvoid
= strcmp(funclistit
->type
, "void") == 0
104 || strcmp(funclistit
->type
, "VOID") == 0;
108 "static inline %s __inline_%s_%s(",
109 funclistit
->type
, cfg
->basename
, funclistit
->name
111 for (arglistit
= funclistit
->arguments
, count
= 1;
113 arglistit
= arglistit
->next
, count
++
116 type
= getargtype(arglistit
);
117 fprintf(out
, "%s __arg%d, ", type
, count
);
118 if (strchr(arglistit
->reg
, '/') != NULL
) {
129 if (cfg
->options
& OPTION_AUTOINIT
) {
131 " AROS_LIBREQ(%s, %d)\n",
132 cfg
->libbase
, funclistit
->version
138 " %sAROS_LC%d%s(%s, %s,\n",
139 (isvoid
) ? "" : "return ",
140 funclistit
->argcount
, (isvoid
) ? "NR" : "",
141 funclistit
->type
, funclistit
->name
144 for (arglistit
= funclistit
->arguments
, count
= 1;
146 arglistit
= arglistit
->next
, count
++
149 type
= getargtype(arglistit
);
150 assert(type
!= NULL
);
152 " AROS_LCA(%s,(__arg%d),%s),\n",
153 type
, count
, arglistit
->reg
158 else /* nquad != 0 */
162 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
163 (isvoid
) ? "" : "return ", narg
,
164 nquad
, (isvoid
) ? "NR" : "",
165 funclistit
->type
, funclistit
->name
169 " %sAROS_LCQUAD%d%s(%s, %s,\n",
170 (isvoid
) ? "" : "return ",
171 nquad
, (isvoid
) ? "NR" : "",
172 funclistit
->type
, funclistit
->name
176 for (arglistit
= funclistit
->arguments
, count
= 1;
178 arglistit
= arglistit
->next
, count
++
181 char *quad2
= strchr(arglistit
->reg
, '/');
183 arglistit
->reg
[2] = 0;
184 type
= getargtype(arglistit
);
185 assert(type
!= NULL
);
190 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
191 type
, count
, arglistit
->reg
, quad2
+1
196 " AROS_LCA(%s, (__arg%d), %s), \\\n",
197 type
, count
, arglistit
->reg
204 " %s, (__%s), %u, %s"
207 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
210 fprintf(out
, "#define %s(", funclistit
->name
);
211 for (arglistit
= funclistit
->arguments
, count
= 1;
213 arglistit
= arglistit
->next
, count
++
216 if (arglistit
!= funclistit
->arguments
)
218 fprintf(out
, "arg%d", count
);
220 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
221 for (arglistit
= funclistit
->arguments
, count
= 1;
223 arglistit
= arglistit
->next
, count
++
225 fprintf(out
, "(arg%d), ", count
);
226 fprintf(out
, "(APTR)%s)\n", cfg
->libbase
);
230 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
232 struct functionarg
*arglistit
= funclistit
->arguments
;
233 char isvararg
= 0, *varargname
, *lastname
;
235 /* Go to last argument */
236 if (arglistit
== NULL
)
239 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
241 lastname
= getargname(arglistit
);
242 assert(lastname
!= NULL
);
244 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
247 varargname
= strdup(funclistit
->name
);
248 varargname
[strlen(funclistit
->name
)-1] = '\0';
250 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
253 /* TagList has to be changed in Tags at the end of the functionname */
254 varargname
= strdup(funclistit
->name
);
255 varargname
[strlen(funclistit
->name
)-4] = 's';
256 varargname
[strlen(funclistit
->name
)-3] = '\0';
258 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
259 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
263 varargname
= strdup(funclistit
->name
);
264 varargname
[strlen(funclistit
->name
)-4] = '\0';
266 else if ((funclistit
->name
[0] == 'V') && (strncmp(arglistit
->arg
, "va_list", 7) == 0))
269 varargname
= malloc(strlen(funclistit
->name
));
270 strcpy(varargname
, &funclistit
->name
[1]);
277 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
278 p
= arglistit
->arg
+ 5;
279 while (isspace(*p
)) p
++;
282 if (strncmp(p
, "struct", 6)==0)
285 while (isspace(*p
)) p
++;
286 if (strncmp(p
, "TagItem", 7) == 0)
289 while (isspace(*p
)) p
++;
294 varargname
= malloc(strlen(funclistit
->name
) + 5);
295 strcpy(varargname
, funclistit
->name
);
296 strcat(varargname
, "Tags");
307 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
309 cfg
->modulenameupper
, 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
);
324 for (arglistit
= funclistit
->arguments
, count
= 1;
326 arglistit
= arglistit
->next
, count
++
329 if (arglistit
!= funclistit
->arguments
)
332 if (arglistit
->next
== NULL
)
334 type
= getargtype(arglistit
);
335 assert(type
!= NULL
);
336 fprintf(out
, "(%s)(IPTR []){ AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }", type
);
340 fprintf(out
, "(arg%d)", count
);
345 "#endif /* !NO_INLINE_STDARG */\n"
350 else if (isvararg
== 2)
355 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
356 "static inline %s __inline_%s_%s(%s __%s",
357 cfg
->modulenameupper
,
358 funclistit
->type
, cfg
->basename
, varargname
, cfg
->libbasetypeptrextern
, cfg
->libbase
360 for (arglistit
= funclistit
->arguments
, count
= 0;
361 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
362 arglistit
= arglistit
->next
365 char *type
= getargtype(arglistit
);
367 fprintf(out
, ", %s __arg%d", type
, ++count
);
369 fprintf(out
, ", ...)\n");
376 " va_start(__args, __arg%d);\n"
377 " retval = __inline_%s_%s(",
380 cfg
->basename
, funclistit
->name
382 for (arglistit
= funclistit
->arguments
, count
= 1;
383 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
384 arglistit
= arglistit
->next
, count
++
387 fprintf(out
, "__arg%d, ", count
);
399 for (arglistit
= funclistit
->arguments
, count
= 1;
400 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
401 arglistit
= arglistit
->next
, count
++
404 fprintf(out
, "arg%d, ", count
);
408 " __inline_%s_%s(%s, ",
409 cfg
->basename
, varargname
, cfg
->libbase
411 for (arglistit
= funclistit
->arguments
, count
= 1;
412 arglistit
!= NULL
&& arglistit
->next
!= NULL
&& arglistit
->next
->next
!= NULL
;
413 arglistit
= arglistit
->next
, count
++
416 fprintf(out
, "(arg%d), ", count
);
420 "#endif /* !NO_INLINE_STDARG */\n"
428 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
430 struct stringlist
*aliasesit
;
432 for (aliasesit
= funclistit
->aliases
;
434 aliasesit
= aliasesit
->next
437 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);