Added support for library libbases to be stored as an offset in the
[AROS.git] / tools / genmodule / writestubs.c
blob443e29359aeeaa4a112fdd6645a0f2703e2884f8
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 Function to write module_stubs.c. Part of genmodule.
6 */
7 #include "genmodule.h"
9 void writestubs(struct config *cfg, int is_rel)
11 FILE *out;
12 char line[256], *type, *name, *banner;
13 struct functionhead *funclistit;
14 struct stringlist *aliasesit;
15 struct functionarg *arglistit;
17 snprintf(line, 255, "%s/%s_%sstubs.c", cfg->gendir, cfg->modulename, is_rel ? "rel" : "");
18 out = fopen(line, "w");
20 if (out == NULL)
22 perror(line);
23 exit(20);
26 banner = getBanner(cfg);
27 if (is_rel) {
28 fprintf
30 out,
31 "%s"
32 "#define NOLIBINLINE\n"
33 "#define NOLIBDEFINES\n"
34 "#ifndef __%s_NOLIBBASE__\n"
35 "/* Do not include the libbase */\n"
36 "#define __%s_NOLIBBASE__\n"
37 "#endif\n",
38 banner, cfg->modulenameupper, cfg->modulenameupper
40 } else {
41 fprintf
43 out,
44 "%s"
45 "#define NOLIBINLINE\n"
46 "#define NOLIBDEFINES\n"
47 "/* Be sure that the libbases are included in the stubs file */\n"
48 "#undef __NOLIBBASE__\n"
49 "#undef __%s_NOLIBBASE__\n",
50 banner, cfg->modulenameupper
53 freeBanner(banner);
55 if (cfg->modtype != MCC && cfg->modtype != MUI && cfg->modtype != MCP)
57 fprintf(out, "#include <proto/%s.h>\n", cfg->modulename);
58 if (is_rel)
59 fprintf(out, "extern IPTR %s_offset;\n", cfg->libbase);
62 fprintf
64 out,
65 "#include <exec/types.h>\n"
66 "#include <aros/cpu.h>\n"
67 "#include <aros/libcall.h>\n"
68 "\n"
71 for (funclistit = cfg->funclist;
72 funclistit!=NULL;
73 funclistit = funclistit->next
76 if (funclistit->lvo >= cfg->firstlvo)
78 if (funclistit->libcall != STACK)
80 int nargs = 0, nquad = 0;
81 int isvoid = strcmp(funclistit->type, "void") == 0
82 || strcmp(funclistit->type, "VOID") == 0;
84 fprintf(out,
85 "\n"
86 "%s %s(",
87 funclistit->type, funclistit->name
89 for (arglistit = funclistit->arguments;
90 arglistit!=NULL;
91 arglistit = arglistit->next
94 if (arglistit != funclistit->arguments)
95 fprintf(out, ", ");
96 fprintf(out, "%s", arglistit->arg);
97 if (strchr(arglistit->reg, '/')) {
98 nquad++;
99 } else {
100 nargs++;
104 fprintf(out,
105 ")\n"
106 "{\n"
108 if (is_rel) {
109 fprintf(out,
110 " %s %s = AROS_GET_RELBASE + %s_offset;\n",
111 cfg->libbasetypeptrextern, cfg->libbase,
112 cfg->libbase
115 if (nquad == 0) {
116 fprintf(out,
117 " %sAROS_LC%d%s(%s, %s,\n",
118 (isvoid) ? "" : "return ",
119 funclistit->argcount, (isvoid) ? "NR" : "",
120 funclistit->type, funclistit->name
123 for (arglistit = funclistit->arguments;
124 arglistit!=NULL;
125 arglistit = arglistit->next
128 type = getargtype(arglistit);
129 name = getargname(arglistit);
130 assert(type != NULL && name != NULL);
132 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
133 type, name, arglistit->reg
135 free(type);
136 free(name);
139 else /* nquad != 0 */
141 if (nargs == 0) {
142 fprintf(out,
143 " %sAROS_LCQUAD%d%s(%s, %s, \\\n",
144 (isvoid) ? "" : "return ",
145 funclistit->argcount, (isvoid) ? "NR" : "",
146 funclistit->type, funclistit->name
149 else
151 fprintf(out,
152 " %sAROS_LC%dQUAD%d%s(%s, %s, \\\n",
153 (isvoid) ? "" : "return ",
154 nargs, nquad, (isvoid) ? "NR" : "",
155 funclistit->type, funclistit->name
159 for (arglistit = funclistit->arguments;
160 arglistit != NULL;
161 arglistit = arglistit->next
164 char *quad2 = strchr(arglistit->reg, '/');
166 type = getargtype(arglistit);
167 name = getargname(arglistit);
168 assert(type != NULL && name != NULL);
170 if (quad2) {
171 *quad2 = 0;
172 fprintf(out,
173 " AROS_LCAQUAD(%s, %s, %s, %s), \\\n",
174 type, name, arglistit->reg, quad2+1
176 *quad2 = '/';
178 else
180 fprintf(out,
181 " AROS_LCA(%s, %s, %s), \\\n",
182 type, name, arglistit->reg
185 free(type);
186 free(name);
190 fprintf(out, " %s, %s, %u, %s);\n}\n",
191 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
194 else /* libcall==STACK */
196 fprintf(out, "AROS_%sLIBFUNCSTUB(%s, %s, %d)\n",
197 is_rel ? "REL" : "",
198 funclistit->name, cfg->libbase, funclistit->lvo
202 for (aliasesit = funclistit->aliases;
203 aliasesit != NULL;
204 aliasesit = aliasesit->next
207 fprintf(out, "AROS_FUNCALIAS(%s, %s)\n",
208 funclistit->name, aliasesit->s
213 fclose(out);