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
)
252 switch (funclistit
->libcall
)
255 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->name
);
257 for(arglistit
= funclistit
->arguments
, first
= 1;
259 arglistit
= arglistit
->next
, first
= 0
265 fprintf(out
, "%s", arglistit
->arg
);
267 fprintf(out
, ");\n");
273 if (funclistit
->priv
|| funclistit
->lvo
< cfg
->firstlvo
)
276 if (funclistit
->arguments
== NULL
277 || strchr(funclistit
->arguments
->reg
, '/') == NULL
281 "AROS_LP%d(%s, %s,\n",
282 funclistit
->argcount
, funclistit
->type
, funclistit
->name
284 for (arglistit
= funclistit
->arguments
;
286 arglistit
= arglistit
->next
289 type
= getargtype(arglistit
);
290 name
= getargname(arglistit
);
291 assert(type
!= NULL
&& name
!= NULL
);
294 " AROS_LPA(%s, %s, %s),\n",
295 type
, name
, arglistit
->reg
301 " LIBBASETYPEPTR, %s, %u, %s\n"
303 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
309 "AROS_LPQUAD%d(%s, %s,\n",
310 funclistit
->argcount
, funclistit
->type
, funclistit
->name
312 for (arglistit
= funclistit
->arguments
;
314 arglistit
= arglistit
->next
317 if (strlen(arglistit
->reg
) != 5)
319 fprintf(stderr
, "Internal error: ../.. register format expected\n");
322 arglistit
->reg
[2] = 0;
324 type
= getargtype(arglistit
);
325 name
= getargname(arglistit
);
326 assert(type
!= NULL
&& name
!= NULL
);
329 " AROS_LPAQUAD(%s, %s, %s, %s),\n",
330 type
, name
, arglistit
->reg
, arglistit
->reg
+3
332 arglistit
->reg
[2] = '/';
337 " LIBBASETYPEPTR, %s, %u, %s\n"
339 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
345 fprintf(stderr
, "Internal error: unhandled libcall in writefuncdefs\n");
352 char *getargtype(const struct functionarg
*funcarg
)
354 char *s
, *begin
, *end
;
355 unsigned int brackets
= 0, i
;
357 begin
= s
= strdup(funcarg
->arg
);
359 /* Count the [] at the end of the argument */
360 end
= begin
+strlen(begin
);
361 while (isspace(*(end
-1))) end
--;
362 while (*(end
-1)==']')
366 while (isspace(*(end
-1))) end
--;
373 while (isspace(*(end
-1))) end
--;
376 /* Skip over the argument name */
377 while (!isspace(*(end
-1)) && *(end
-1)!='*')
382 fprintf(stderr
, "no argument type or name found for arg: %s\n", funcarg
->arg
);
388 /* Add * for the brackets */
389 while (isspace(*(end
-1))) end
--;
390 for (i
=0; i
<brackets
; i
++)
400 char *getargname(const struct functionarg
*funcarg
)
402 char *s
, *begin
, *end
;
405 /* Count the [] at the end of the argument */
406 end
= funcarg
->arg
+strlen(funcarg
->arg
);
407 while (isspace(*(end
-1))) end
--;
408 while (*(end
-1)==']')
411 while (isspace(*(end
-1))) end
--;
415 while (isspace(*(end
-1))) end
--;
418 /* Go to the beginning of the argument name */
420 while (!isspace(*(begin
-1)) && *(begin
-1)!='*') begin
--;
425 strncpy(s
, begin
, len
);