attempt to register additional cores
[AROS.git] / tools / genmodule / writeincinterfaces.c
blobb6f3c6fec8c65d120e4864a8e174bb0953ccc088
1 /*
2 * Copyright (C) 2012, The AROS Development Team
3 * All right reserved.
4 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
6 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
8 * Generate include/interface/XXXX.h files
9 */
10 #include "genmodule.h"
12 static void writeincinterface(struct config *cfg, struct interfaceinfo *in)
14 FILE *out;
15 char line[256], *banner;
16 struct functionhead *funclistit;
17 int maxlvo = -1;
19 snprintf(line, 255, "%s/interface/%s.h", cfg->gendir, in->interfacename);
20 out = fopen(line, "w");
22 if (out == NULL)
24 perror(line);
25 exit(20);
28 banner = getBanner(cfg);
29 fprintf(out,
30 "#ifndef INTERFACE_%s_H\n"
31 "#define INTERFACE_%s_H\n"
32 "\n"
33 "%s"
34 "\n"
35 "/*\n"
36 " Desc: interface inlines for %s\n"
37 "*/\n"
38 "\n"
39 "#include <exec/types.h>\n"
40 "#include <proto/oop.h>\n"
41 "\n"
42 "#define IID_%-32s \"%s\"\n"
43 "\n"
44 , in->interfacename
45 , in->interfacename
46 , banner
47 , in->interfacename
48 , in->interfacename
49 , in->interfaceid
51 freeBanner(banner);
53 /* Emit the get-the-methodbase stub */
54 fprintf(out,
55 "#if !defined(%s) && !defined(__OOP_NOMETHODBASES__) && !defined(__%s_NOMETHODBASE__)\n"
56 "#define %s %s_GetMethodBase(__obj)\n"
57 "\n"
58 "static inline OOP_MethodID %s_GetMethodBase(OOP_Object *obj)\n"
59 "{\n"
60 " static OOP_MethodID %s_mid;\n"
61 " if (!%s_mid) {\n"
62 " struct Library *OOPBase = (struct Library *)OOP_OCLASS(obj)->OOPBasePtr;\n"
63 " %s_mid = OOP_GetMethodID(IID_%s, 0);\n"
64 " }\n"
65 " return %s_mid;\n"
66 "}\n"
67 "#endif\n"
68 "\n"
69 ,in->methodbase
70 ,in->interfacename
71 ,in->methodbase
72 ,in->interfacename
73 ,in->interfacename
74 ,in->interfacename
75 ,in->interfacename
76 ,in->interfacename
77 ,in->interfacename
78 ,in->interfacename
81 if (in->attributelist) {
82 fprintf(out,
83 "#define %-32s __I%s\n"
84 "\n"
85 "#if !defined(__OOP_NOATTRBASES__) && !defined(__%s_NOATTRBASE__)\n"
86 "extern OOP_AttrBase %s;\n"
87 "#endif\n"
88 "\n"
89 "enum\n"
90 "{\n"
91 , in->attributebase
92 , in->interfacename
93 , in->interfacename
94 , in->attributebase
98 /* Define all the attribute ids */
99 for (funclistit = in->attributelist; funclistit!=NULL; funclistit = funclistit->next)
101 fprintf(out,
102 " ao%s_%s = %d,"
103 , in->interfacename
104 , funclistit->name
105 , funclistit->lvo
107 if (funclistit->comment)
109 fprintf(out,
110 " /* %s */"
111 , funclistit->comment
114 fprintf(out, "\n");
115 if ((int)funclistit->lvo > maxlvo)
116 maxlvo = funclistit->lvo;
119 if (maxlvo >= 0) {
120 fprintf(out,
121 " num_%s_Attrs = %d,\n"
122 "};\n"
123 "\n"
124 , in->interfacename
125 , maxlvo+1
129 for (funclistit = in->attributelist; funclistit!=NULL; funclistit = funclistit->next)
131 fprintf(out,
132 "#define a%s_%-32s (%s + ao%s_%s)\n"
133 , in->interfacename
134 , funclistit->name
135 , in->attributebase
136 , in->interfacename
137 , funclistit->name
141 fprintf(out,
142 "\n"
143 "#define %s_Switch(attr, idx) \\\n"
144 "if (((idx) = (attr) - %s) < num_%s_Attrs) \\\n"
145 "switch (idx)\n"
146 "\n"
147 , in->interfacename
148 , in->attributebase
149 , in->interfacename
152 if (!in->methodlist)
153 goto done;
155 /* Define method ids */
156 fprintf(out,
157 "\n"
158 "enum {\n"
160 maxlvo = -1;
161 for (funclistit = in->methodlist; funclistit!=NULL; funclistit = funclistit->next)
163 fprintf(out,
164 " mo%s_%s = %d,\n"
165 , in->interfacename
166 , funclistit->name
167 , funclistit->lvo
169 if ((int)funclistit->lvo > maxlvo)
170 maxlvo = funclistit->lvo;
173 fprintf(out,
174 " num_%s_Methods = %d\n"
175 "};\n"
176 "\n"
177 , in->interfacename
178 , maxlvo+1
181 /* Define method stubs */
182 for (funclistit = in->methodlist; funclistit!=NULL; funclistit = funclistit->next)
184 struct functionarg *arg;
186 /* Define message types */
187 fprintf(out,
188 "struct p%s_%s\n"
189 "{\n"
190 " OOP_MethodID mID;\n"
191 , in->interfacename
192 , funclistit->name
195 for (arg = funclistit->arguments; arg; arg = arg->next)
197 fprintf(out,
198 " %s;\n"
199 , arg->arg
203 fprintf(out,
204 "};\n"
205 "\n"
208 if (funclistit->comment)
210 fprintf(out,
211 "/* %s */\n"
212 , funclistit->comment
216 fprintf(out,
217 "#define %s_%s(obj, args...) \\\n"
218 " ({OOP_Object *__obj = obj;\\\n"
219 " %s_%s_(%s, __obj ,##args); })\n"
220 "\n"
221 ,in->methodstub
222 ,funclistit->name
223 ,in->methodstub
224 ,funclistit->name
225 ,in->methodbase
228 fprintf(out,
229 "static inline %s %s_%s_(OOP_MethodID __%s, OOP_Object *__obj"
230 , funclistit->type
231 , in->methodstub
232 , funclistit->name
233 , in->methodbase
236 for (arg = funclistit->arguments; arg; arg = arg->next)
238 fprintf(out,
239 ", %s"
240 , arg->arg
244 fprintf(out,
245 ")\n"
246 "{\n"
247 " struct p%s_%s p;\n"
248 " p.mID = __%s + mo%s_%s;\n"
249 , in->interfacename
250 , funclistit->name
251 , in->methodbase
252 , in->interfacename
253 , funclistit->name
256 for (arg = funclistit->arguments; arg; arg = arg->next)
258 const char *ptr;
259 char *name;
261 ptr = arg->arg + strlen(arg->arg) - 1;
262 while (isspace(*ptr))
263 ptr--;
265 while (isalnum(*ptr) || (*ptr == '_'))
266 ptr--;
268 if (*ptr == ')') {
269 /* Function prototype */
270 const char *cp;
271 ptr = strchr(arg->arg, '(');
272 while (!(isalnum(*ptr) || (*ptr == '_'))) ptr++;
273 cp = ptr;
274 while (isalnum(*ptr) || (*ptr == '_')) ptr++;
275 name = malloc(ptr - cp + 1);
276 memcpy(name, cp, ptr - cp);
277 name[ptr-cp] = 0;
278 } else {
279 name = strdup(ptr + 1);
282 fprintf(out,
283 " p.%s = %s;\n"
284 , name
285 , name
288 free(name);
291 fprintf(out,
292 " %s(%s)OOP_DoMethod(__obj, &p.mID);\n"
293 "}\n"
294 "\n"
295 , (strcasecmp(funclistit->type, "void") == 0) ? "" : "return "
296 , funclistit->type
300 done:
301 fprintf(out,
302 "#endif /* INTERFACE_%s_H */\n"
303 , in->interfacename
306 fclose(out);
309 void writeincinterfaces(struct config *cfg)
311 struct interfaceinfo *in;
313 for (in = cfg->interfacelist; in ; in = in->next) {
314 writeincinterface(cfg, in);