comparison dmd2/idgen.c @ 758:f04dde6e882c

Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:38:48 +0100
parents
children 356e65836fb5
comparison
equal deleted inserted replaced
757:2c730d530c98 758:f04dde6e882c
1
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars
4 // All Rights Reserved
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
10
11 // Program to generate string files in d data structures.
12 // Saves much tedious typing, and eliminates typo problems.
13 // Generates:
14 // id.h
15 // id.c
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdarg.h>
21 #include <assert.h>
22
23 struct Msgtable
24 {
25 const char *ident; // name to use in DMD source
26 const char *name; // name in D executable
27 };
28
29 Msgtable msgtable[] =
30 {
31 { "IUnknown" },
32 { "Object" },
33 { "object" },
34 { "max" },
35 { "min" },
36 { "This", "this" },
37 { "ctor", "__ctor" },
38 { "dtor", "__dtor" },
39 { "cpctor", "__cpctor" },
40 { "_postblit", "__postblit" },
41 { "classInvariant", "__invariant" },
42 { "unitTest", "__unitTest" },
43 { "init" },
44 { "size" },
45 { "__sizeof", "sizeof" },
46 { "alignof" },
47 { "mangleof" },
48 { "stringof" },
49 { "tupleof" },
50 { "length" },
51 { "remove" },
52 { "ptr" },
53 { "funcptr" },
54 { "dollar", "__dollar" },
55 { "offset" },
56 { "offsetof" },
57 { "ModuleInfo" },
58 { "ClassInfo" },
59 { "classinfo" },
60 { "typeinfo" },
61 { "outer" },
62 { "Exception" },
63 { "withSym", "__withSym" },
64 { "result", "__result" },
65 { "returnLabel", "__returnLabel" },
66 { "delegate" },
67 { "line" },
68 { "empty", "" },
69 { "p" },
70 { "coverage", "__coverage" },
71 { "__vptr" },
72 { "__monitor" },
73
74 { "TypeInfo" },
75 { "TypeInfo_Class" },
76 { "TypeInfo_Interface" },
77 { "TypeInfo_Struct" },
78 { "TypeInfo_Enum" },
79 { "TypeInfo_Typedef" },
80 { "TypeInfo_Pointer" },
81 { "TypeInfo_Array" },
82 { "TypeInfo_StaticArray" },
83 { "TypeInfo_AssociativeArray" },
84 { "TypeInfo_Function" },
85 { "TypeInfo_Delegate" },
86 { "TypeInfo_Tuple" },
87 { "TypeInfo_Const" },
88 { "TypeInfo_Invariant" },
89 { "elements" },
90 { "_arguments_typeinfo" },
91 { "_arguments" },
92 { "_argptr" },
93 { "_match" },
94 { "destroy" },
95 { "postblit" },
96
97 { "LINE", "__LINE__" },
98 { "FILE", "__FILE__" },
99 { "DATE", "__DATE__" },
100 { "TIME", "__TIME__" },
101 { "TIMESTAMP", "__TIMESTAMP__" },
102 { "VENDOR", "__VENDOR__" },
103 { "VERSIONX", "__VERSION__" },
104 { "EOFX", "__EOF__" },
105
106 { "nan" },
107 { "infinity" },
108 { "dig" },
109 { "epsilon" },
110 { "mant_dig" },
111 { "max_10_exp" },
112 { "max_exp" },
113 { "min_10_exp" },
114 { "min_exp" },
115 { "re" },
116 { "im" },
117
118 { "C" },
119 { "D" },
120 { "Windows" },
121 { "Pascal" },
122 { "System" },
123
124 { "exit" },
125 { "success" },
126 { "failure" },
127
128 { "keys" },
129 { "values" },
130 { "rehash" },
131
132 { "sort" },
133 { "reverse" },
134 { "dup" },
135 { "idup" },
136
137 // For inline assembler
138 { "___out", "out" },
139 { "___in", "in" },
140 { "__int", "int" },
141 { "__dollar", "$" },
142 { "__LOCAL_SIZE" },
143
144 // For operator overloads
145 { "uadd", "opPos" },
146 { "neg", "opNeg" },
147 { "com", "opCom" },
148 { "add", "opAdd" },
149 { "add_r", "opAdd_r" },
150 { "sub", "opSub" },
151 { "sub_r", "opSub_r" },
152 { "mul", "opMul" },
153 { "mul_r", "opMul_r" },
154 { "div", "opDiv" },
155 { "div_r", "opDiv_r" },
156 { "mod", "opMod" },
157 { "mod_r", "opMod_r" },
158 { "eq", "opEquals" },
159 { "cmp", "opCmp" },
160 { "iand", "opAnd" },
161 { "iand_r", "opAnd_r" },
162 { "ior", "opOr" },
163 { "ior_r", "opOr_r" },
164 { "ixor", "opXor" },
165 { "ixor_r", "opXor_r" },
166 { "shl", "opShl" },
167 { "shl_r", "opShl_r" },
168 { "shr", "opShr" },
169 { "shr_r", "opShr_r" },
170 { "ushr", "opUShr" },
171 { "ushr_r", "opUShr_r" },
172 { "cat", "opCat" },
173 { "cat_r", "opCat_r" },
174 { "assign", "opAssign" },
175 { "addass", "opAddAssign" },
176 { "subass", "opSubAssign" },
177 { "mulass", "opMulAssign" },
178 { "divass", "opDivAssign" },
179 { "modass", "opModAssign" },
180 { "andass", "opAndAssign" },
181 { "orass", "opOrAssign" },
182 { "xorass", "opXorAssign" },
183 { "shlass", "opShlAssign" },
184 { "shrass", "opShrAssign" },
185 { "ushrass", "opUShrAssign" },
186 { "catass", "opCatAssign" },
187 { "postinc", "opPostInc" },
188 { "postdec", "opPostDec" },
189 { "index", "opIndex" },
190 { "indexass", "opIndexAssign" },
191 { "slice", "opSlice" },
192 { "sliceass", "opSliceAssign" },
193 { "call", "opCall" },
194 { "cast", "opCast" },
195 { "match", "opMatch" },
196 { "next", "opNext" },
197 { "opIn" },
198 { "opIn_r" },
199 { "opStar" },
200 { "opDot" },
201 { "opImplicitCast" },
202
203 { "classNew", "new" },
204 { "classDelete", "delete" },
205
206 // For foreach
207 { "apply", "opApply" },
208 { "applyReverse", "opApplyReverse" },
209
210 { "adDup", "_adDupT" },
211 { "adReverse", "_adReverse" },
212
213 // For internal functions
214 { "aaLen", "_aaLen" },
215 { "aaKeys", "_aaKeys" },
216 { "aaValues", "_aaValues" },
217 { "aaRehash", "_aaRehash" },
218
219 // For pragma's
220 { "GNU_asm" },
221 { "lib" },
222 { "msg" },
223 { "startaddress" },
224
225 // LDC pragma's
226 { "intrinsic" },
227 { "va_intrinsic" },
228 { "no_typeinfo" },
229 { "no_moduleinfo" },
230 { "Alloca", "alloca" },
231 { "vastart", "va_start" },
232 { "vacopy", "va_copy" },
233 { "vaend", "va_end" },
234 { "vaarg", "va_arg" },
235 { "ldc" },
236
237 // For special functions
238 { "tohash", "toHash" },
239 { "tostring", "toString" },
240 { "getmembers", "getMembers" },
241
242 // Special functions
243 //{ "alloca" },
244 { "main" },
245 { "WinMain" },
246 { "DllMain" },
247
248 // Builtin functions
249 { "std" },
250 { "math" },
251 { "sin" },
252 { "cos" },
253 { "tan" },
254 { "_sqrt", "sqrt" },
255 { "fabs" },
256
257 // Traits
258 { "isAbstractClass" },
259 { "isArithmetic" },
260 { "isAssociativeArray" },
261 { "isFinalClass" },
262 { "isFloating" },
263 { "isIntegral" },
264 { "isScalar" },
265 { "isStaticArray" },
266 { "isUnsigned" },
267 { "isVirtualFunction" },
268 { "isAbstractFunction" },
269 { "isFinalFunction" },
270 { "hasMember" },
271 { "getMember" },
272 { "getVirtualFunctions" },
273 { "classInstanceSize" },
274 { "allMembers" },
275 { "derivedMembers" },
276 { "isSame" },
277 { "compiles" },
278 };
279
280
281 int main()
282 {
283 FILE *fp;
284 unsigned i;
285
286 {
287 fp = fopen("id.h","w");
288 if (!fp)
289 { printf("can't open id.h\n");
290 exit(EXIT_FAILURE);
291 }
292
293 fprintf(fp, "// File generated by idgen.c\n");
294 #if __DMC__
295 fprintf(fp, "#pragma once\n");
296 #endif
297 fprintf(fp, "#ifndef DMD_ID_H\n");
298 fprintf(fp, "#define DMD_ID_H 1\n");
299 fprintf(fp, "struct Identifier;\n");
300 fprintf(fp, "struct Id\n");
301 fprintf(fp, "{\n");
302
303 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
304 { const char *id = msgtable[i].ident;
305
306 fprintf(fp," static Identifier *%s;\n", id);
307 }
308
309 fprintf(fp, " static void initialize();\n");
310 fprintf(fp, "};\n");
311 fprintf(fp, "#endif\n");
312
313 fclose(fp);
314 }
315
316 {
317 fp = fopen("id.c","w");
318 if (!fp)
319 { printf("can't open id.c\n");
320 exit(EXIT_FAILURE);
321 }
322
323 fprintf(fp, "// File generated by idgen.c\n");
324 fprintf(fp, "#include \"id.h\"\n");
325 fprintf(fp, "#include \"identifier.h\"\n");
326 fprintf(fp, "#include \"lexer.h\"\n");
327
328 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
329 { const char *id = msgtable[i].ident;
330 const char *p = msgtable[i].name;
331
332 if (!p)
333 p = id;
334 fprintf(fp,"Identifier *Id::%s;\n", id);
335 }
336
337 fprintf(fp, "void Id::initialize()\n");
338 fprintf(fp, "{\n");
339
340 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
341 { const char *id = msgtable[i].ident;
342 const char *p = msgtable[i].name;
343
344 if (!p)
345 p = id;
346 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
347 }
348
349 fprintf(fp, "}\n");
350
351 fclose(fp);
352 }
353
354 return EXIT_SUCCESS;
355 }