- Set a default PCM volume so that something can be heard when driver is
[AROS.git] / tools / genmodule / writestubs.c
blob2c2f56ce5a7af5ee99e226bb40883243452bc493
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 " return AROS_LC%d%s(%s, %s,\n",
93 funclistit->argcount, (isvoid) ? "NR" : "",
94 funclistit->type, funclistit->name
97 for (arglistit = funclistit->arguments;
98 arglistit!=NULL;
99 arglistit = arglistit->next
102 type = getargtype(arglistit);
103 name = getargname(arglistit);
104 assert(type != NULL && name != NULL);
106 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
107 type, name, arglistit->reg
109 free(type);
110 free(name);
113 } else { /* nquad != 0 */
114 if (nargs == 0) {
115 fprintf(out,
116 ") \\\n"
117 "{\n"
118 " return AROS_LCQUAD%d%s(%s, %s, \\\n",
119 funclistit->argcount, (isvoid) ? "NR" : "",
120 funclistit->type, funclistit->name
122 } else {
123 fprintf(out,
124 ") \\\n"
125 "{\n"
126 " return AROS_LC%dQUAD%d%s(%s, %s, \\\n",
127 nargs, nquad, (isvoid) ? "NR" : "",
128 funclistit->type, funclistit->name
132 for (arglistit = funclistit->arguments;
133 arglistit != NULL;
134 arglistit = arglistit->next
137 char *quad2 = strchr(arglistit->reg, '/');
139 type = getargtype(arglistit);
140 name = getargname(arglistit);
141 assert(type != NULL && name != NULL);
143 if (quad2) {
144 *quad2 = 0;
145 fprintf(out,
146 " AROS_LCAQUAD(%s, %s, %s, %s), \\\n",
147 type, name, arglistit->reg, quad2+1
149 *quad2 = '/';
150 } else {
151 fprintf(out,
152 " AROS_LCA(%s, %s, %s), \\\n",
153 type, name, arglistit->reg
156 arglistit->reg[2] = '/';
157 free(type);
158 free(name);
162 fprintf(out, " %s, %s, %u, %s);\n}\n",
163 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
166 else /* libcall==STACK */
168 fprintf(out, "AROS_LIBFUNCSTUB(%s, %s, %d)\n",
169 funclistit->name, cfg->libbase, funclistit->lvo
173 for (aliasesit = funclistit->aliases;
174 aliasesit != NULL;
175 aliasesit = aliasesit->next
178 fprintf(out, "AROS_FUNCALIAS(%s, %s)\n",
179 funclistit->name, aliasesit->s
184 fclose(out);