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/preprocessor/variadic/cast2iptr.hpp>\n"
43 cfg
->modulenameupper
, cfg
->modulenameupper
, banner
, cfg
->modulename
47 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
49 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
51 if (funclistit
->libcall
!= STACK
)
53 writeinlineregister(out
, funclistit
, cfg
);
54 if (!funclistit
->novararg
)
55 writeinlinevararg(out
, funclistit
, cfg
);
57 else /* libcall == STACK */
59 /* NOP: nothing to be written for stack argument passing.
60 The stubs in sthe link library will be used */
63 writealiases(out
, funclistit
, cfg
);
69 "#endif /* INLINE_%s_H*/\n",
77 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
79 struct functionarg
*arglistit
;
84 isvoid
= strcmp(funclistit
->type
, "void") == 0
85 || strcmp(funclistit
->type
, "VOID") == 0;
89 "static inline %s __inline_%s_%s(",
90 funclistit
->type
, cfg
->basename
, funclistit
->name
92 for (arglistit
= funclistit
->arguments
, count
= 1;
94 arglistit
= arglistit
->next
, count
++
97 type
= getargtype(arglistit
);
98 fprintf(out
, "%s __arg%d, ", type
, count
);
99 if (strchr(arglistit
->reg
, '/') != NULL
) {
110 " %sAROS_LC%d%s(%s, %s,\n",
112 (isvoid
) ? "" : "return ",
113 funclistit
->argcount
, (isvoid
) ? "NR" : "",
114 funclistit
->type
, funclistit
->name
117 for (arglistit
= funclistit
->arguments
, count
= 1;
119 arglistit
= arglistit
->next
, count
++
122 type
= getargtype(arglistit
);
123 assert(type
!= NULL
);
125 " AROS_LCA(%s,(__arg%d),%s),\n",
126 type
, count
, arglistit
->reg
131 else /* nquad != 0 */
137 " %sAROS_LC%dQUAD%d%s(%s, %s,\n",
139 (isvoid
) ? "" : "return ", narg
,
140 nquad
, (isvoid
) ? "NR" : "",
141 funclistit
->type
, funclistit
->name
147 " %sAROS_LCQUAD%d%s(%s, %s,\n",
149 (isvoid
) ? "" : "return ",
150 nquad
, (isvoid
) ? "NR" : "",
151 funclistit
->type
, funclistit
->name
155 for (arglistit
= funclistit
->arguments
, count
= 1;
157 arglistit
= arglistit
->next
, count
++
160 char *quad2
= strchr(arglistit
->reg
, '/');
162 arglistit
->reg
[2] = 0;
163 type
= getargtype(arglistit
);
164 assert(type
!= NULL
);
169 " AROS_LCAQUAD(%s, (__arg%d), %s, %s), \\\n",
170 type
, count
, arglistit
->reg
, quad2
+1
175 " AROS_LCA(%s, (__arg%d), %s), \\\n",
176 type
, count
, arglistit
->reg
183 " %s, (__%s), %u, %s"
186 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
189 fprintf(out
, "#define %s(", funclistit
->name
);
190 for (arglistit
= funclistit
->arguments
, count
= 1;
192 arglistit
= arglistit
->next
, count
++
195 if (arglistit
!= funclistit
->arguments
)
197 fprintf(out
, "arg%d", count
);
199 fprintf(out
, ") \\\n __inline_%s_%s(", cfg
->basename
, funclistit
->name
);
200 for (arglistit
= funclistit
->arguments
, count
= 1;
202 arglistit
= arglistit
->next
, count
++
204 fprintf(out
, "(arg%d), ", count
);
205 fprintf(out
, "(APTR)%s)\n", cfg
->libbase
);
209 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
211 struct functionarg
*arglistit
= funclistit
->arguments
;
212 char isvararg
= 0, *varargname
, *lastname
;
214 /* Go to last argument */
215 if (arglistit
== NULL
)
218 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
220 lastname
= getargname(arglistit
);
221 assert(lastname
!= NULL
);
223 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
226 varargname
= strdup(funclistit
->name
);
227 varargname
[strlen(funclistit
->name
)-1] = '\0';
229 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
232 /* TagList has to be changed in Tags at the end of the functionname */
233 varargname
= strdup(funclistit
->name
);
234 varargname
[strlen(funclistit
->name
)-4] = 's';
235 varargname
[strlen(funclistit
->name
)-3] = '\0';
237 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
238 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
242 varargname
= strdup(funclistit
->name
);
243 varargname
[strlen(funclistit
->name
)-4] = '\0';
250 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
251 p
= arglistit
->arg
+ 5;
252 while (isspace(*p
)) p
++;
255 if (strncmp(p
, "struct", 6)==0)
258 while (isspace(*p
)) p
++;
259 if (strncmp(p
, "TagItem", 7) == 0)
262 while (isspace(*p
)) p
++;
267 varargname
= malloc(strlen(funclistit
->name
) + 5);
268 strcpy(varargname
, funclistit
->name
);
269 strcat(varargname
, "Tags");
280 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
282 cfg
->modulenameupper
, varargname
284 for (arglistit
= funclistit
->arguments
, count
= 1;
285 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
286 arglistit
= arglistit
->next
, count
++
289 fprintf(out
, "arg%d, ", count
);
294 " IPTR __args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }; \\\n"
298 for (arglistit
= funclistit
->arguments
, count
= 1;
300 arglistit
= arglistit
->next
, count
++
303 if (arglistit
!= funclistit
->arguments
)
306 if (arglistit
->next
== NULL
)
308 type
= getargtype(arglistit
);
309 assert(type
!= NULL
);
310 fprintf(out
, "(%s)__args", type
);
314 fprintf(out
, "(arg%d)", count
);
319 "#endif /* !NO_INLINE_STDARG */\n"
327 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
329 struct stringlist
*aliasesit
;
331 for (aliasesit
= funclistit
->aliases
;
333 aliasesit
= aliasesit
->next
336 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);