2 Copyright © 1995-2008, 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
)
17 struct functionhead
*funclistit
;
19 snprintf(line
, 255, "%s/inline/%s.h", cfg
->gendir
, cfg
->modulename
);
20 out
= fopen(line
, "w");
29 "#ifndef INLINE_%s_H\n"
30 "#define INLINE_%s_H\n"
35 " Desc: Inline function for %s\n"
38 "#include <aros/libcall.h>\n"
39 "#include <exec/types.h>\n"
40 "#include <aros/preprocessor/variadic/cast2iptr.hpp>\n"
42 cfg
->modulenameupper
, cfg
->modulenameupper
, getBanner(cfg
), cfg
->modulename
44 if (cfg
->command
!=DUMMY
)
46 for (funclistit
= cfg
->funclist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
48 if (!funclistit
->priv
&& (funclistit
->lvo
>= cfg
->firstlvo
))
50 if (funclistit
->libcall
!= STACK
)
52 writeinlineregister(out
, funclistit
, cfg
);
53 if (!funclistit
->novararg
)
54 writeinlinevararg(out
, funclistit
, cfg
);
56 else /* libcall == STACK */
58 /* NOP: nothing to be written for stack argument passing.
59 The stubs in sthe link library will be used */
62 writealiases(out
, funclistit
, cfg
);
68 "#endif /* INLINE_%s_H*/\n",
76 writeinlineregister(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
78 struct functionarg
*arglistit
;
82 isvoid
= strcmp(funclistit
->type
, "void") == 0
83 || strcmp(funclistit
->type
, "VOID") == 0;
87 "static inline %s __%s_inline(",
88 funclistit
->type
, funclistit
->name
90 for (arglistit
= funclistit
->arguments
, count
= 1;
92 arglistit
= arglistit
->next
, count
++
95 type
= getargtype(arglistit
);
96 fprintf(out
, "%s __arg%d, ", type
, count
);
101 " %sAROS_LC%d%s(%s, %s,\n",
102 cfg
->libbasetypeptrextern
, cfg
->libbase
,
103 (isvoid
) ? "" : "return ",
104 funclistit
->argcount
, (isvoid
) ? "NR" : "",
105 funclistit
->type
, funclistit
->name
108 for (arglistit
= funclistit
->arguments
, count
= 1;
110 arglistit
= arglistit
->next
, count
++
113 type
= getargtype(arglistit
);
114 assert(type
!= NULL
);
116 " AROS_LCA(%s,(__arg%d),%s),\n",
117 type
, count
, arglistit
->reg
122 " %s, (__%s), %u, %s"
125 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
128 fprintf(out
, "#define %s(", funclistit
->name
);
129 for (arglistit
= funclistit
->arguments
, count
= 1;
131 arglistit
= arglistit
->next
, count
++
134 if (arglistit
!= funclistit
->arguments
)
136 fprintf(out
, "arg%d", count
);
138 fprintf(out
, ") \\\n __%s_inline(", funclistit
->name
);
139 for (arglistit
= funclistit
->arguments
, count
= 1;
141 arglistit
= arglistit
->next
, count
++
143 fprintf(out
, "(arg%d), ", count
);
144 fprintf(out
, "%s)\n", cfg
->libbase
);
148 writeinlinevararg(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
150 struct functionarg
*arglistit
= funclistit
->arguments
;
151 char isvararg
= 0, *varargname
, *lastname
;
153 /* Go to last argument */
154 if (arglistit
== NULL
)
157 while (arglistit
->next
!= NULL
) arglistit
= arglistit
->next
;
159 lastname
= getargname(arglistit
);
160 assert(lastname
!= NULL
);
162 if (*(funclistit
->name
+ strlen(funclistit
->name
) - 1) == 'A')
165 varargname
= strdup(funclistit
->name
);
166 varargname
[strlen(funclistit
->name
)-1] = '\0';
168 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 7, "TagList") == 0)
171 /* TagList has to be changed in Tags at the end of the functionname */
172 varargname
= strdup(funclistit
->name
);
173 varargname
[strlen(funclistit
->name
)-4] = 's';
174 varargname
[strlen(funclistit
->name
)-3] = '\0';
176 else if (strcmp(funclistit
->name
+ strlen(funclistit
->name
) - 4, "Args") == 0
177 && (strcasecmp(lastname
, "args") == 0 || strcasecmp(lastname
, "arglist") == 0)
181 varargname
= strdup(funclistit
->name
);
182 varargname
[strlen(funclistit
->name
)-4] = '\0';
189 if (strncmp(arglistit
->arg
, "const", 5) == 0) {
190 p
= arglistit
->arg
+ 5;
191 while (isspace(*p
)) p
++;
194 if (strncmp(p
, "struct", 6)==0)
197 while (isspace(*p
)) p
++;
198 if (strncmp(p
, "TagItem", 7) == 0)
201 while (isspace(*p
)) p
++;
206 varargname
= malloc(strlen(funclistit
->name
) + 5);
207 strcpy(varargname
, funclistit
->name
);
208 strcat(varargname
, "Tags");
219 "\n#if !defined(NO_INLINE_STDARG) && !defined(%s_NO_INLINE_STDARG)\n"
221 cfg
->modulenameupper
, varargname
223 for (arglistit
= funclistit
->arguments
, count
= 1;
224 arglistit
!= NULL
&& arglistit
->next
!= NULL
;
225 arglistit
= arglistit
->next
, count
++
228 fprintf(out
, "arg%d, ", count
);
233 " IPTR __args[] = { AROS_PP_VARIADIC_CAST2IPTR(__VA_ARGS__) }; \\\n"
237 for (arglistit
= funclistit
->arguments
, count
= 1;
239 arglistit
= arglistit
->next
, count
++
242 if (arglistit
!= funclistit
->arguments
)
245 if (arglistit
->next
== NULL
)
247 type
= getargtype(arglistit
);
248 assert(type
!= NULL
);
249 fprintf(out
, "(%s)__args", type
);
253 fprintf(out
, "(arg%d)", count
);
258 "#endif /* !NO_INLINE_STDARG */\n"
266 writealiases(FILE *out
, struct functionhead
*funclistit
, struct config
*cfg
)
268 struct stringlist
*aliasesit
;
270 for (aliasesit
= funclistit
->aliases
;
272 aliasesit
= aliasesit
->next
275 fprintf(out
, "#define %s %s\n", aliasesit
->s
, funclistit
->name
);