replace value with speed definition
[AROS.git] / tools / genmodule / writestubs.c
blobdcb88d071ffdbceac477b786fc5dd6488358a91e
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 fprintf(out,
94 ")\n"
95 "{\n"
96 " return AROS_LC%d%s(%s, %s,\n",
97 funclistit->argcount, (isvoid) ? "NR" : "",
98 funclistit->type, funclistit->name
101 for (arglistit = funclistit->arguments;
102 arglistit!=NULL;
103 arglistit = arglistit->next
106 type = getargtype(arglistit);
107 name = getargname(arglistit);
108 assert(type != NULL && name != NULL);
110 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
111 type, name, arglistit->reg
113 free(type);
114 free(name);
117 fprintf(out, " %s, %s, %u, %s);\n}\n",
118 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
121 else /* libcall==STACK */
123 assert(cfg->intcfg & CFG_GENASTUBS);
125 fprintf(outasm,
126 STUBCODE,
127 funclistit->name,
128 cfg->libbase,
129 -funclistit->lvo*LIB_VECTSIZE
133 for (aliasesit = funclistit->aliases;
134 aliasesit != NULL;
135 aliasesit = aliasesit->next
138 assert(cfg->intcfg & CFG_GENASTUBS);
140 fprintf(outasm, ALIASCODE, funclistit->name, aliasesit->s);
144 fclose(out);
145 if (cfg->intcfg & CFG_GENASTUBS)
146 fclose(outasm);