added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / tools / genmodule / writestubs.c
blob5ae6c80913b3eaa476cf6cd58fc07ea6bb2c20b5
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Function to write module_stubs.c. Part of genmodule.
6 */
7 #include <aros/cpu.h>
9 #include "genmodule.h"
11 void writestubs(struct config *cfg)
13 FILE *out, *outasm;
14 char line[256], *type, *name;
15 struct functionhead *funclistit;
16 struct stringlist *aliasesit;
17 struct functionarg *arglistit;
19 snprintf(line, 255, "%s/%s_stubs.c", cfg->gendir, cfg->modulename);
20 out = fopen(line, "w");
22 if (out == NULL)
24 perror(line);
25 exit(20);
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 getBanner(cfg), 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", getBanner(cfg));
49 fprintf(outasm, STUBCODE_INIT);
52 if (cfg->modtype != MCC && cfg->modtype != MUI && cfg->modtype != MCP)
54 fprintf(out, "#include <proto/%s.h>\n", cfg->modulename);
57 fprintf
59 out,
60 "#include <exec/types.h>\n"
61 "#include <aros/libcall.h>\n"
62 "\n"
65 for (funclistit = cfg->funclist;
66 funclistit!=NULL;
67 funclistit = funclistit->next
70 if (funclistit->lvo >= cfg->firstlvo)
72 if (funclistit->libcall != STACK)
74 int isvoid = strcmp(funclistit->type, "void") == 0
75 || strcmp(funclistit->type, "VOID") == 0;
77 fprintf(out,
78 "\n"
79 "%s %s(",
80 funclistit->type, funclistit->name
82 for (arglistit = funclistit->arguments;
83 arglistit!=NULL;
84 arglistit = arglistit->next
87 if (arglistit != funclistit->arguments)
88 fprintf(out, ", ");
89 fprintf(out, "%s", arglistit->arg);
92 fprintf(out,
93 ")\n"
94 "{\n"
95 " return AROS_LC%d%s(%s, %s,\n",
96 funclistit->argcount, (isvoid) ? "NR" : "",
97 funclistit->type, funclistit->name
100 for (arglistit = funclistit->arguments;
101 arglistit!=NULL;
102 arglistit = arglistit->next
105 type = getargtype(arglistit);
106 name = getargname(arglistit);
107 assert(type != NULL && name != NULL);
109 fprintf(out, " AROS_LCA(%s,%s,%s),\n",
110 type, name, arglistit->reg
112 free(type);
113 free(name);
116 fprintf(out, " %s, %s, %u, %s);\n}\n",
117 cfg->libbasetypeptrextern, cfg->libbase, funclistit->lvo, cfg->basename
120 else /* libcall==STACK */
122 assert(cfg->intcfg & CFG_GENASTUBS);
124 fprintf(outasm,
125 STUBCODE,
126 funclistit->name,
127 cfg->libbase,
128 &(__AROS_GETJUMPVEC(NULL, funclistit->lvo)->vec)
132 for (aliasesit = funclistit->aliases;
133 aliasesit != NULL;
134 aliasesit = aliasesit->next
137 assert(cfg->intcfg & CFG_GENASTUBS);
139 fprintf(outasm, ALIASCODE, funclistit->name, aliasesit->s);
143 fclose(out);
144 if (cfg->intcfg & CFG_GENASTUBS)
145 fclose(outasm);