Import SB128-v5.24 to main branch
[AROS.git] / tools / genmodule / writestubs.c
blob623ca08ed12de00946b85af4f59ede1e71f847c5
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)
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_stubs.c", cfg->gendir, cfg->modulename);
18 out = fopen(line, "w");
20 if (out == NULL)
22 perror(line);
23 exit(20);
26 banner = getBanner(cfg);
27 fprintf
29 out,
30 "%s"
31 "#define NOLIBDEFINES\n"
32 "#define NOLIBINLINE\n"
33 "/* Be sure that the libbases are included in the stubs file */\n"
34 "#undef __NOLIBBASE__\n"
35 "#undef __%s_NOLIBBASE__\n",
36 banner, cfg->modulenameupper
38 freeBanner(banner);
40 if (cfg->modtype != MCC && cfg->modtype != MUI && cfg->modtype != MCP)
42 fprintf(out, "#include <proto/%s.h>\n", cfg->modulename);
45 fprintf
47 out,
48 "#include <exec/types.h>\n"
49 "#include <aros/cpu.h>\n"
50 "#include <aros/libcall.h>\n"
51 "\n"
54 for (funclistit = cfg->funclist;
55 funclistit!=NULL;
56 funclistit = funclistit->next
59 if (funclistit->lvo >= cfg->firstlvo)
61 if (funclistit->libcall != STACK)
63 int nargs = 0, nquad = 0;
64 int isvoid = strcmp(funclistit->type, "void") == 0
65 || strcmp(funclistit->type, "VOID") == 0;
67 fprintf(out,
68 "\n"
69 "%s %s(",
70 funclistit->type, funclistit->name
72 for (arglistit = funclistit->arguments;
73 arglistit!=NULL;
74 arglistit = arglistit->next
77 if (arglistit != funclistit->arguments)
78 fprintf(out, ", ");
79 fprintf(out, "%s", arglistit->arg);
80 if (strchr(arglistit->reg, '/')) {
81 nquad++;
82 } else {
83 nargs++;
87 if (nquad == 0)
89 fprintf(out,
90 ")\n"
91 "{\n"
92 " %sAROS_LC%d%s(%s, %s,\n",
93 (isvoid) ? "" : "return ",
94 funclistit->argcount, (isvoid) ? "NR" : "",
95 funclistit->type, funclistit->name
98 for (arglistit = funclistit->arguments;
99 arglistit!=NULL;
100 arglistit = arglistit->next
103 type = getargtype(arglistit);
104 name = getargname(arglistit);
105 assert(type != NULL && name != NULL);
107 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
108 type, name, arglistit->reg
110 free(type);
111 free(name);
114 else /* nquad != 0 */
116 if (nargs == 0) {
117 fprintf(out,
118 ") \\\n"
119 "{\n"
120 " %sAROS_LCQUAD%d%s(%s, %s, \\\n",
121 (isvoid) ? "" : "return ",
122 funclistit->argcount, (isvoid) ? "NR" : "",
123 funclistit->type, funclistit->name
126 else
128 fprintf(out,
129 ") \\\n"
130 "{\n"
131 " %sAROS_LC%dQUAD%d%s(%s, %s, \\\n",
132 (isvoid) ? "" : "return ",
133 nargs, nquad, (isvoid) ? "NR" : "",
134 funclistit->type, funclistit->name
138 for (arglistit = funclistit->arguments;
139 arglistit != NULL;
140 arglistit = arglistit->next
143 char *quad2 = strchr(arglistit->reg, '/');
145 type = getargtype(arglistit);
146 name = getargname(arglistit);
147 assert(type != NULL && name != NULL);
149 if (quad2) {
150 *quad2 = 0;
151 fprintf(out,
152 " AROS_LCAQUAD(%s, %s, %s, %s), \\\n",
153 type, name, arglistit->reg, quad2+1
155 *quad2 = '/';
157 else
159 fprintf(out,
160 " AROS_LCA(%s, %s, %s), \\\n",
161 type, name, arglistit->reg
164 free(type);
165 free(name);
169 fprintf(out, " %s, %s, %u, %s);\n}\n",
170 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
173 else /* libcall==STACK */
175 fprintf(out, "AROS_LIBFUNCSTUB(%s, %s, %d)\n",
176 funclistit->name, cfg->libbase, funclistit->lvo
180 for (aliasesit = funclistit->aliases;
181 aliasesit != NULL;
182 aliasesit = aliasesit->next
185 fprintf(out, "AROS_FUNCALIAS(%s, %s)\n",
186 funclistit->name, aliasesit->s
191 fclose(out);