2 Copyright © 1995-2005, 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
->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 writefuncdefs(FILE *out
, struct config
*cfg
, struct functionhead
*funclist
)
75 struct functionhead
*funclistit
;
76 struct functionarg
*arglistit
;
80 for(funclistit
= funclist
; funclistit
!= NULL
; funclistit
= funclistit
->next
)
82 switch (funclistit
->libcall
)
85 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->name
);
87 for(arglistit
= funclistit
->arguments
, first
= 1;
89 arglistit
= arglistit
->next
, first
= 0
95 fprintf(out
, "%s", arglistit
->arg
);
102 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->name
);
103 for (arglistit
= funclistit
->arguments
, first
= 1;
105 arglistit
= arglistit
->next
, first
= 0
110 fprintf(out
, "%s", arglistit
->arg
);
113 ");\nAROS_LH%d(%s, %s,\n",
114 funclistit
->argcount
, funclistit
->type
, funclistit
->name
116 for (arglistit
= funclistit
->arguments
;
118 arglistit
= arglistit
->next
121 type
= getargtype(arglistit
);
122 name
= getargname(arglistit
);
123 assert(name
!= NULL
&& type
!= NULL
);
126 " AROS_LHA(%s, %s, %s),\n",
127 type
, name
, arglistit
->reg
135 " AROS_LIBFUNC_INIT\n\n"
137 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclistit
->lvo
, cfg
->basename
,
140 for (arglistit
= funclistit
->arguments
, first
= 1;
142 arglistit
= arglistit
->next
, first
= 0
145 name
= getargname(arglistit
);
146 assert(name
!= NULL
);
150 fprintf(out
, "%s", name
);
155 " AROS_LIBFUNC_EXIT\n"
161 if (funclistit
->arguments
== NULL
162 || strchr(funclistit
->arguments
->reg
, '/') == NULL
)
165 "AROS_LD%d(%s, %s,\n",
166 funclistit
->argcount
, funclistit
->type
, funclistit
->name
168 for (arglistit
= funclistit
->arguments
;
170 arglistit
= arglistit
->next
173 type
= getargtype(arglistit
);
174 name
= getargname(arglistit
);
175 assert(type
!= NULL
&& name
!= NULL
);
178 " AROS_LDA(%s, %s, %s),\n",
179 type
, name
, arglistit
->reg
185 " LIBBASETYPEPTR, %s, %u, %s\n"
187 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
193 "AROS_LDQUAD%d(%s, %s,\n",
194 funclistit
->argcount
, funclistit
->type
, funclistit
->name
196 for (arglistit
= funclistit
->arguments
;
198 arglistit
= arglistit
->next
201 if (strlen(arglistit
->reg
) != 5)
203 fprintf(stderr
, "Internal error: ../.. register format expected\n");
206 arglistit
->reg
[2] = 0;
208 type
= getargtype(arglistit
);
209 name
= getargname(arglistit
);
210 assert(type
!= NULL
&& name
!= NULL
);
213 " AROS_LDAQUAD(%s, %s, %s, %s),\n",
214 type
, name
, arglistit
->reg
, arglistit
->reg
+3
216 arglistit
->reg
[2] = '/';
221 " LIBBASETYPEPTR, %s, %u, %s\n"
223 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
229 fprintf(stderr
, "Internal error: unhandled libcall in writefuncdefs\n");
236 void writefuncprotos(FILE *out
, struct config
*cfg
, struct functionhead
*funclist
)
238 struct functionhead
*funclistit
;
239 struct functionarg
*arglistit
;
243 for(funclistit
= funclist
; funclistit
!= NULL
; funclistit
= funclistit
->next
)
245 switch (funclistit
->libcall
)
248 fprintf(out
, "%s %s(", funclistit
->type
, funclistit
->name
);
250 for(arglistit
= funclistit
->arguments
, first
= 1;
252 arglistit
= arglistit
->next
, first
= 0
258 fprintf(out
, "%s", arglistit
->arg
);
260 fprintf(out
, ");\n");
266 if (funclistit
->priv
|| funclistit
->lvo
< cfg
->firstlvo
)
269 if (funclistit
->arguments
== NULL
270 || strchr(funclistit
->arguments
->reg
, '/') == NULL
274 "AROS_LP%d(%s, %s,\n",
275 funclistit
->argcount
, funclistit
->type
, funclistit
->name
277 for (arglistit
= funclistit
->arguments
;
279 arglistit
= arglistit
->next
282 type
= getargtype(arglistit
);
283 name
= getargname(arglistit
);
284 assert(type
!= NULL
&& name
!= NULL
);
287 " AROS_LPA(%s, %s, %s),\n",
288 type
, name
, arglistit
->reg
294 " LIBBASETYPEPTR, %s, %u, %s\n"
296 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
302 "AROS_LPQUAD%d(%s, %s,\n",
303 funclistit
->argcount
, funclistit
->type
, funclistit
->name
305 for (arglistit
= funclistit
->arguments
;
307 arglistit
= arglistit
->next
310 if (strlen(arglistit
->reg
) != 5)
312 fprintf(stderr
, "Internal error: ../.. register format expected\n");
315 arglistit
->reg
[2] = 0;
317 type
= getargtype(arglistit
);
318 name
= getargname(arglistit
);
319 assert(type
!= NULL
&& name
!= NULL
);
322 " AROS_LPAQUAD(%s, %s, %s, %s),\n",
323 type
, name
, arglistit
->reg
, arglistit
->reg
+3
325 arglistit
->reg
[2] = '/';
330 " LIBBASETYPEPTR, %s, %u, %s\n"
332 cfg
->libbase
, funclistit
->lvo
, cfg
->basename
338 fprintf(stderr
, "Internal error: unhandled libcall in writefuncdefs\n");
345 char *getargtype(const struct functionarg
*funcarg
)
347 char *s
, *begin
, *end
;
348 unsigned int brackets
= 0, i
;
350 begin
= s
= strdup(funcarg
->arg
);
352 /* Count the [] at the end of the argument */
353 end
= begin
+strlen(begin
);
354 while (isspace(*(end
-1))) end
--;
355 while (*(end
-1)==']')
359 while (isspace(*(end
-1))) end
--;
366 while (isspace(*(end
-1))) end
--;
369 /* Skip over the argument name */
370 while (!isspace(*(end
-1)) && *(end
-1)!='*') end
--;
372 /* Add * for the brackets */
373 while (isspace(*(end
-1))) end
--;
374 for (i
=0; i
<brackets
; i
++)
384 char *getargname(const struct functionarg
*funcarg
)
386 char *s
, *begin
, *end
;
389 /* Count the [] at the end of the argument */
390 end
= funcarg
->arg
+strlen(funcarg
->arg
);
391 while (isspace(*(end
-1))) end
--;
392 while (*(end
-1)==']')
395 while (isspace(*(end
-1))) end
--;
399 while (isspace(*(end
-1))) end
--;
402 /* Go to the beginning of the argument name */
404 while (!isspace(*(begin
-1)) && *(begin
-1)!='*') begin
--;
409 strncpy(s
, begin
, len
);