TaggedOpenLibrary constants off by one fix.
[AROS.git] / tools / genmodule / writestubs.c
blobf212e289bed4966c27eb7f59b0cbe8aa8fb50a12
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 "archspecific.h"
8 #include "genmodule.h"
10 void writestubs(struct config *cfg)
12 FILE *out, *outasm;
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_stubs.c", cfg->gendir, cfg->modulename);
19 out = fopen(line, "w");
21 if (out == NULL)
23 perror(line);
24 exit(20);
27 banner = getBanner(cfg);
28 fprintf
30 out,
31 "%s"
32 "#define NOLIBDEFINES\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
39 if (cfg->intcfg & CFG_GENASTUBS)
41 snprintf(line, 255, "%s/%s_astubs.S", cfg->gendir, cfg->modulename);
42 outasm = fopen(line, "w");
43 if (outasm==NULL)
45 fprintf(stderr, "Could not write %s\n", line);
46 exit(20);
48 fprintf(outasm, "%s", banner);
49 fprintf(outasm, STUBCODE_INIT);
51 freeBanner(banner);
53 if (cfg->modtype != MCC && cfg->modtype != MUI && cfg->modtype != MCP)
55 fprintf(out, "#include <proto/%s.h>\n", cfg->modulename);
58 fprintf
60 out,
61 "#include <exec/types.h>\n"
62 "#include <aros/libcall.h>\n"
63 "\n"
66 for (funclistit = cfg->funclist;
67 funclistit!=NULL;
68 funclistit = funclistit->next
71 if (funclistit->lvo >= cfg->firstlvo)
73 if (funclistit->libcall != STACK)
75 int isvoid = strcmp(funclistit->type, "void") == 0
76 || strcmp(funclistit->type, "VOID") == 0;
78 fprintf(out,
79 "\n"
80 "%s %s(",
81 funclistit->type, funclistit->name
83 for (arglistit = funclistit->arguments;
84 arglistit!=NULL;
85 arglistit = arglistit->next
88 if (arglistit != funclistit->arguments)
89 fprintf(out, ", ");
90 fprintf(out, "%s", arglistit->arg);
93 if (funclistit->arguments == NULL
94 || strchr(funclistit->arguments->reg, '/') == NULL)
96 fprintf(out,
97 ")\n"
98 "{\n"
99 " return AROS_LC%d%s(%s, %s,\n",
100 funclistit->argcount, (isvoid) ? "NR" : "",
101 funclistit->type, funclistit->name
104 for (arglistit = funclistit->arguments;
105 arglistit!=NULL;
106 arglistit = arglistit->next
109 type = getargtype(arglistit);
110 name = getargname(arglistit);
111 assert(type != NULL && name != NULL);
113 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
114 type, name, arglistit->reg
116 free(type);
117 free(name);
120 } else {
121 fprintf(out,
122 ") \\\n"
123 "{\n"
124 " return AROS_LCQUAD%d%s(%s, %s, \\\n",
125 funclistit->argcount, (isvoid) ? "NR" : "",
126 funclistit->type, funclistit->name
129 for (arglistit = funclistit->arguments;
130 arglistit != NULL;
131 arglistit = arglistit->next
134 if (strlen(arglistit->reg) != 5)
136 fprintf(stderr, "Internal error: ../.. register format expected\n");
137 exit(20);
139 arglistit->reg[2] = 0;
141 type = getargtype(arglistit);
142 name = getargname(arglistit);
143 assert(type != NULL && name != NULL);
145 fprintf(out,
146 " AROS_LCAQUAD(%s, %s, %s, %s), \\\n",
147 type, name, arglistit->reg, arglistit->reg+3
149 arglistit->reg[2] = '/';
150 free(type);
151 free(name);
155 fprintf(out, " %s, %s, %u, %s);\n}\n",
156 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
159 else /* libcall==STACK */
161 assert(cfg->intcfg & CFG_GENASTUBS);
163 fprintf(outasm,
164 STUBCODE,
165 funclistit->name,
166 cfg->libbase,
167 -funclistit->lvo*LIB_VECTSIZE
171 for (aliasesit = funclistit->aliases;
172 aliasesit != NULL;
173 aliasesit = aliasesit->next
176 assert(cfg->intcfg & CFG_GENASTUBS);
178 fprintf(outasm, ALIASCODE, funclistit->name, aliasesit->s);
182 fclose(out);
183 if (cfg->intcfg & CFG_GENASTUBS)
184 fclose(outasm);