2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 The code for storing information of functions present in the module
9 #include "functionhead.h"
12 struct functionhead
*newfunctionhead(const char *name
, enum libcall libcall
)
14 struct functionhead
*funchead
= malloc(sizeof(struct functionhead
));
18 funchead
->next
= NULL
;
19 funchead
->internalname
= funchead
->name
= strdup(name
);
20 funchead
->type
= NULL
;
21 funchead
->libcall
= libcall
;
23 funchead
->argcount
= 0;
24 funchead
->arguments
= NULL
;
25 funchead
->aliases
= NULL
;
26 funchead
->interface
= NULL
;
27 funchead
->method
= NULL
;
28 funchead
->novararg
= 0;
33 puts("Out of memory !");
40 struct functionarg
*funcaddarg
42 struct functionhead
*funchead
,
43 const char *arg
, const char *reg
46 struct functionarg
**argptr
= &funchead
->arguments
;
48 while ((*argptr
) != NULL
) argptr
= &(*argptr
)->next
;
50 *argptr
= malloc(sizeof(struct functionarg
));
53 (*argptr
)->next
= NULL
;
54 (*argptr
)->arg
= (arg
== NULL
) ? NULL
: strdup(arg
);
55 (*argptr
)->reg
= (reg
== NULL
) ? NULL
: strdup(reg
);
61 puts("Out of memory !");
68 struct stringlist
*funcaddalias(struct functionhead
*funchead
, const char *alias
)
70 return slist_append(&funchead
->aliases
, alias
);
73 void funcsetinternalname(struct functionhead
*funchead
, const char *internalname
)
75 if (funchead
->name
!= funchead
->internalname
)
76 free(funchead
->internalname
);
77 funchead
->internalname
= strdup(internalname
);
80 void writefuncdefs(FILE *out
, struct config
*cfg
, struct functionhead
*funclist
)
82 struct functionhead
*funclistit
;
83 struct functionarg
*arglistit
;
87 for(funclistit
= funclist
; funclistit
!= NULL
; funclistit
= funclistit
->next
)
89 switch (funclistit
->libcall
)
92 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->internalname
);
94 for(arglistit
= funclistit
->arguments
, first
= 1;
96 arglistit
= arglistit
->next
, first
= 0
102 fprintf(out
, "%s", arglistit
->arg
);
104 fprintf(out
, ");\n");
109 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->internalname
);
110 for (arglistit
= funclistit
->arguments
, first
= 1;
112 arglistit
= arglistit
->next
, first
= 0
117 fprintf(out
, "%s", arglistit
->arg
);
120 ");\nAROS_LH%d(%s, %s,\n",
121 funclistit
->argcount
, funclistit
->type
, funclistit
->internalname
123 for (arglistit
= funclistit
->arguments
;
125 arglistit
= arglistit
->next
128 type
= getargtype(arglistit
);
129 name
= getargname(arglistit
);
130 assert(name
!= NULL
&& type
!= NULL
);
133 " AROS_LHA(%s, %s, %s),\n",
134 type
, name
, arglistit
->reg
142 " AROS_LIBFUNC_INIT\n\n"
144 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
,
145 funclistit
->internalname
147 for (arglistit
= funclistit
->arguments
, first
= 1;
149 arglistit
= arglistit
->next
, first
= 0
152 name
= getargname(arglistit
);
153 assert(name
!= NULL
);
157 fprintf(out
, "%s", name
);
162 " AROS_LIBFUNC_EXIT\n"
168 if (funclistit
->arguments
== NULL
169 || strchr(funclistit
->arguments
->reg
, '/') == NULL
)
172 "AROS_LD%d(%s, %s,\n",
173 funclistit
->argcount
, funclistit
->type
, funclistit
->internalname
175 for (arglistit
= funclistit
->arguments
;
177 arglistit
= arglistit
->next
180 type
= getargtype(arglistit
);
181 name
= getargname(arglistit
);
182 assert(type
!= NULL
&& name
!= NULL
);
185 " AROS_LDA(%s, %s, %s),\n",
186 type
, name
, arglistit
->reg
192 " LIBBASETYPEPTR, %s, %u, %s\n"
194 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
200 "AROS_LDQUAD%d(%s, %s,\n",
201 funclistit
->argcount
, funclistit
->type
, funclistit
->internalname
203 for (arglistit
= funclistit
->arguments
;
205 arglistit
= arglistit
->next
208 if (strlen(arglistit
->reg
) != 5)
210 fprintf(stderr
, "Internal error: ../.. register format expected\n");
213 arglistit
->reg
[2] = 0;
215 type
= getargtype(arglistit
);
216 name
= getargname(arglistit
);
217 assert(type
!= NULL
&& name
!= NULL
);
220 " AROS_LDAQUAD(%s, %s, %s, %s),\n",
221 type
, name
, arglistit
->reg
, arglistit
->reg
+3
223 arglistit
->reg
[2] = '/';
228 " LIBBASETYPEPTR, %s, %u, %s\n"
230 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
236 fprintf(stderr
, "Internal error: unhandled libcall in writefuncdefs\n");
243 void writefuncprotos(FILE *out
, struct config
*cfg
, struct functionhead
*funclist
)
245 struct functionhead
*funclistit
;
246 struct functionarg
*arglistit
;
250 for(funclistit
= funclist
; funclistit
!= NULL
; funclistit
= funclistit
->next
)
254 "#if !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__)"
256 cfg
->modulenameupper
,
261 switch (funclistit
->libcall
)
264 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->name
);
266 for(arglistit
= funclistit
->arguments
, first
= 1;
268 arglistit
= arglistit
->next
, first
= 0
274 fprintf(out
, "%s", arglistit
->arg
);
276 fprintf(out
, ");\n");
282 if (funclistit
->priv
|| funclistit
->lvo
< cfg
->firstlvo
) {
283 fprintf(out
, "/* private */\n");
287 if (funclistit
->arguments
== NULL
288 || strchr(funclistit
->arguments
->reg
, '/') == NULL
292 "AROS_LP%d(%s, %s,\n",
293 funclistit
->argcount
, funclistit
->type
, funclistit
->name
295 for (arglistit
= funclistit
->arguments
;
297 arglistit
= arglistit
->next
300 type
= getargtype(arglistit
);
301 name
= getargname(arglistit
);
302 assert(type
!= NULL
&& name
!= NULL
);
305 " AROS_LPA(%s, %s, %s),\n",
306 type
, name
, arglistit
->reg
312 " LIBBASETYPEPTR, %s, %u, %s\n"
314 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
320 "AROS_LPQUAD%d(%s, %s,\n",
321 funclistit
->argcount
, funclistit
->type
, funclistit
->name
323 for (arglistit
= funclistit
->arguments
;
325 arglistit
= arglistit
->next
328 if (strlen(arglistit
->reg
) != 5)
330 fprintf(stderr
, "Internal error: ../.. register format expected\n");
333 arglistit
->reg
[2] = 0;
335 type
= getargtype(arglistit
);
336 name
= getargname(arglistit
);
337 assert(type
!= NULL
&& name
!= NULL
);
340 " AROS_LPAQUAD(%s, %s, %s, %s),\n",
341 type
, name
, arglistit
->reg
, arglistit
->reg
+3
343 arglistit
->reg
[2] = '/';
348 " LIBBASETYPEPTR, %s, %u, %s\n"
350 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
356 fprintf(stderr
, "Internal error: unhandled libcall in writefuncdefs\n");
363 "#endif /* !defined(__%s_LIBAPI__) || (%d <= __%s_LIBAPI__) */"
365 cfg
->modulenameupper
,
372 char *getargtype(const struct functionarg
*funcarg
)
374 char *s
, *begin
, *end
;
375 unsigned int brackets
= 0, i
;
377 begin
= s
= strdup(funcarg
->arg
);
379 /* Count the [] at the end of the argument */
380 end
= begin
+strlen(begin
);
381 while (isspace(*(end
-1))) end
--;
382 while (*(end
-1)==']')
386 while (isspace(*(end
-1)) || isdigit(*(end
-1))) end
--;
393 while (isspace(*(end
-1))) end
--;
396 /* Skip over the argument name */
397 while (!isspace(*(end
-1)) && *(end
-1)!='*')
402 fprintf(stderr
, "no argument type or name found for arg: %s\n", funcarg
->arg
);
408 /* Add * for the brackets */
409 while (isspace(*(end
-1))) end
--;
410 for (i
=0; i
<brackets
; i
++)
420 char *getargname(const struct functionarg
*funcarg
)
422 char *s
, *begin
, *end
;
425 /* Count the [] at the end of the argument */
426 end
= funcarg
->arg
+strlen(funcarg
->arg
);
427 while (isspace(*(end
-1))) end
--;
428 while (*(end
-1)==']')
431 while (isspace(*(end
-1))) end
--;
435 while (isspace(*(end
-1))) end
--;
438 /* Go to the beginning of the argument name */
440 while (!isspace(*(begin
-1)) && *(begin
-1)!='*') begin
--;
445 strncpy(s
, begin
, len
);