Detabbed
[AROS.git] / tools / genmodule / writestubs.c
blobff47125613609d4f88e68be910672785fb9c2970
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Function to write module_stubs.c. Part of genmodule.
6 */
8 #include "genmodule.h"
10 void writestubs(struct config *cfg, int is_rel)
12 FILE *out;
13 char line[256], *type, *name, *banner;
14 struct functionhead *funclistit;
15 struct stringlist *aliasesit;
16 struct functionarg *arglistit;
18 snprintf(line, 255, "%s/%s_%sstubs.c", cfg->gendir, cfg->modulename, is_rel ? "rel" : "");
19 out = fopen(line, "w");
21 if (out == NULL)
23 perror(line);
24 exit(20);
27 banner = getBanner(cfg);
28 if (is_rel) {
29 fprintf
31 out,
32 "%s"
33 "#undef NOLIBINLINE\n"
34 "#undef NOLIBDEFINES\n"
35 "#define NOLIBINLINE\n"
36 "#define NOLIBDEFINES\n"
37 "char *__aros_getoffsettable(void);\n"
38 "#ifndef __%s_NOLIBBASE__\n"
39 "/* Do not include the libbase */\n"
40 "#define __%s_NOLIBBASE__\n"
41 "#endif\n",
42 banner, cfg->modulenameupper, cfg->modulenameupper
44 } else {
45 fprintf
47 out,
48 "%s"
49 "#undef NOLIBINLINE\n"
50 "#undef NOLIBDEFINES\n"
51 "#define NOLIBINLINE\n"
52 "#define NOLIBDEFINES\n"
53 "/* Be sure that the libbases are included in the stubs file */\n"
54 "#undef __NOLIBBASE__\n"
55 "#undef __%s_NOLIBBASE__\n",
56 banner, cfg->modulenameupper
59 freeBanner(banner);
61 if (!(cfg->options & OPTION_NOINCLUDES))
63 if (is_rel)
64 fprintf(out, "#define __%s_RELLIBBASE__\n", cfg->modulenameupper);
65 fprintf(out, "#include <proto/%s.h>\n", cfg->modulename);
68 fprintf
70 out,
71 "#include <stddef.h>\n"
72 "\n"
73 "#include <aros/cpu.h>\n"
74 "#include <aros/genmodule.h>\n"
75 "#include <aros/libcall.h>\n"
76 "\n"
79 for (funclistit = cfg->funclist;
80 funclistit!=NULL;
81 funclistit = funclistit->next
84 if (funclistit->lvo >= cfg->firstlvo)
86 if (funclistit->libcall != STACK)
88 int nargs = 0, nquad = 0;
89 int isvoid = strcmp(funclistit->type, "void") == 0
90 || strcmp(funclistit->type, "VOID") == 0;
92 fprintf(out,
93 "\n"
94 "%s %s(",
95 funclistit->type, funclistit->name
97 for (arglistit = funclistit->arguments;
98 arglistit!=NULL;
99 arglistit = arglistit->next
102 if (arglistit != funclistit->arguments)
103 fprintf(out, ", ");
104 fprintf(out, "%s", arglistit->arg);
105 if (strchr(arglistit->reg, '/')) {
106 nquad++;
107 } else {
108 nargs++;
112 fprintf(out,
113 ")\n"
114 "{\n"
116 if (nquad == 0) {
117 fprintf(out,
118 " %sAROS_LC%d%s(%s, %s,\n",
119 (isvoid) ? "" : "return ",
120 funclistit->argcount, (isvoid) ? "NR" : "",
121 funclistit->type, funclistit->name
124 for (arglistit = funclistit->arguments;
125 arglistit!=NULL;
126 arglistit = arglistit->next
129 type = getargtype(arglistit);
130 name = getargname(arglistit);
131 assert(type != NULL && name != NULL);
133 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
134 type, name, arglistit->reg
136 free(type);
137 free(name);
140 else /* nquad != 0 */
142 if (nargs == 0) {
143 fprintf(out,
144 " %sAROS_LCQUAD%d%s(%s, %s, \\\n",
145 (isvoid) ? "" : "return ",
146 funclistit->argcount, (isvoid) ? "NR" : "",
147 funclistit->type, funclistit->name
150 else
152 fprintf(out,
153 " %sAROS_LC%dQUAD%d%s(%s, %s, \\\n",
154 (isvoid) ? "" : "return ",
155 nargs, nquad, (isvoid) ? "NR" : "",
156 funclistit->type, funclistit->name
160 for (arglistit = funclistit->arguments;
161 arglistit != NULL;
162 arglistit = arglistit->next
165 char *quad2 = strchr(arglistit->reg, '/');
167 type = getargtype(arglistit);
168 name = getargname(arglistit);
169 assert(type != NULL && name != NULL);
171 if (quad2) {
172 *quad2 = 0;
173 fprintf(out,
174 " AROS_LCAQUAD(%s, %s, %s, %s), \\\n",
175 type, name, arglistit->reg, quad2+1
177 *quad2 = '/';
179 else
181 fprintf(out,
182 " AROS_LCA(%s, %s, %s), \\\n",
183 type, name, arglistit->reg
186 free(type);
187 free(name);
191 fprintf(out, " %s, __aros_getbase_%s(), %u, %s);\n}\n",
192 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
195 else /* libcall==STACK */
197 fprintf(out, "AROS_GM_%sLIBFUNCSTUB(%s, %s, %d)\n",
198 is_rel ? "REL" : "",
199 funclistit->name, cfg->libbase, funclistit->lvo
203 for (aliasesit = funclistit->aliases;
204 aliasesit != NULL;
205 aliasesit = aliasesit->next
208 fprintf(out, "AROS_GM_LIBFUNCALIAS(%s, %s)\n",
209 funclistit->name, aliasesit->s
214 fclose(out);