Mercurial > projects > ldc
annotate dmd/idgen.c @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +0200 |
parents | def7a1d494fd |
children |
rev | line source |
---|---|
336 | 1 |
2 // Compiler implementation of the D programming language | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
3 // Copyright (c) 1999-2008 by Digital Mars |
336 | 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 { | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
25 const char *ident; // name to use in DMD source |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
26 const char *name; // name in D executable |
336 | 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 { "classInvariant", "__invariant" }, | |
40 { "unitTest", "_unitTest" }, | |
1587 | 41 { "require", "__require" }, |
42 { "ensure", "__ensure" }, | |
336 | 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 | |
95 { "LINE", "__LINE__" }, | |
96 { "FILE", "__FILE__" }, | |
97 { "DATE", "__DATE__" }, | |
98 { "TIME", "__TIME__" }, | |
99 { "TIMESTAMP", "__TIMESTAMP__" }, | |
100 { "VENDOR", "__VENDOR__" }, | |
101 { "VERSIONX", "__VERSION__" }, | |
102 | |
103 { "nan" }, | |
104 { "infinity" }, | |
105 { "dig" }, | |
106 { "epsilon" }, | |
107 { "mant_dig" }, | |
108 { "max_10_exp" }, | |
109 { "max_exp" }, | |
110 { "min_10_exp" }, | |
111 { "min_exp" }, | |
112 { "re" }, | |
113 { "im" }, | |
114 | |
115 { "C" }, | |
116 { "D" }, | |
117 { "Windows" }, | |
118 { "Pascal" }, | |
119 { "System" }, | |
120 | |
121 { "exit" }, | |
122 { "success" }, | |
123 { "failure" }, | |
124 | |
125 { "keys" }, | |
126 { "values" }, | |
127 { "rehash" }, | |
128 | |
129 { "sort" }, | |
130 { "reverse" }, | |
131 { "dup" }, | |
132 { "idup" }, | |
133 | |
134 // For inline assembler | |
135 { "___out", "out" }, | |
136 { "___in", "in" }, | |
137 { "__int", "int" }, | |
138 { "__dollar", "$" }, | |
139 { "__LOCAL_SIZE" }, | |
140 | |
141 // For operator overloads | |
142 { "uadd", "opPos" }, | |
143 { "neg", "opNeg" }, | |
144 { "com", "opCom" }, | |
145 { "add", "opAdd" }, | |
146 { "add_r", "opAdd_r" }, | |
147 { "sub", "opSub" }, | |
148 { "sub_r", "opSub_r" }, | |
149 { "mul", "opMul" }, | |
150 { "mul_r", "opMul_r" }, | |
151 { "div", "opDiv" }, | |
152 { "div_r", "opDiv_r" }, | |
153 { "mod", "opMod" }, | |
154 { "mod_r", "opMod_r" }, | |
155 { "eq", "opEquals" }, | |
156 { "cmp", "opCmp" }, | |
157 { "iand", "opAnd" }, | |
158 { "iand_r", "opAnd_r" }, | |
159 { "ior", "opOr" }, | |
160 { "ior_r", "opOr_r" }, | |
161 { "ixor", "opXor" }, | |
162 { "ixor_r", "opXor_r" }, | |
163 { "shl", "opShl" }, | |
164 { "shl_r", "opShl_r" }, | |
165 { "shr", "opShr" }, | |
166 { "shr_r", "opShr_r" }, | |
167 { "ushr", "opUShr" }, | |
168 { "ushr_r", "opUShr_r" }, | |
169 { "cat", "opCat" }, | |
170 { "cat_r", "opCat_r" }, | |
171 { "assign", "opAssign" }, | |
172 { "addass", "opAddAssign" }, | |
173 { "subass", "opSubAssign" }, | |
174 { "mulass", "opMulAssign" }, | |
175 { "divass", "opDivAssign" }, | |
176 { "modass", "opModAssign" }, | |
177 { "andass", "opAndAssign" }, | |
178 { "orass", "opOrAssign" }, | |
179 { "xorass", "opXorAssign" }, | |
180 { "shlass", "opShlAssign" }, | |
181 { "shrass", "opShrAssign" }, | |
182 { "ushrass", "opUShrAssign" }, | |
183 { "catass", "opCatAssign" }, | |
184 { "postinc", "opPostInc" }, | |
185 { "postdec", "opPostDec" }, | |
186 { "index", "opIndex" }, | |
187 { "indexass", "opIndexAssign" }, | |
188 { "slice", "opSlice" }, | |
189 { "sliceass", "opSliceAssign" }, | |
190 { "call", "opCall" }, | |
191 { "cast", "opCast" }, | |
192 { "match", "opMatch" }, | |
193 { "next", "opNext" }, | |
194 { "opIn" }, | |
195 { "opIn_r" }, | |
196 | |
197 { "classNew", "new" }, | |
198 { "classDelete", "delete" }, | |
199 | |
200 // For foreach | |
201 { "apply", "opApply" }, | |
202 { "applyReverse", "opApplyReverse" }, | |
203 | |
204 { "adDup", "_adDupT" }, | |
205 { "adReverse", "_adReverse" }, | |
206 | |
207 // For internal functions | |
208 { "aaLen", "_aaLen" }, | |
209 { "aaKeys", "_aaKeys" }, | |
210 { "aaValues", "_aaValues" }, | |
211 { "aaRehash", "_aaRehash" }, | |
1587 | 212 { "monitorenter", "_d_monitorenter" }, |
213 { "monitorexit", "_d_monitorexit" }, | |
214 { "criticalenter", "_d_criticalenter" }, | |
215 { "criticalexit", "_d_criticalexit" }, | |
336 | 216 |
217 // For pragma's | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
218 { "GNU_asm" }, |
336 | 219 { "lib" }, |
220 { "msg" }, | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
221 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
222 // LDC pragma's |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
223 { "intrinsic" }, |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
224 { "va_intrinsic" }, |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
225 { "no_typeinfo" }, |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
226 { "no_moduleinfo" }, |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
227 { "Alloca", "alloca" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
228 { "vastart", "va_start" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
229 { "vacopy", "va_copy" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
230 { "vaend", "va_end" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
231 { "vaarg", "va_arg" }, |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
232 { "ldc" }, |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
663
diff
changeset
|
233 { "allow_inline" }, |
1152
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
945
diff
changeset
|
234 { "llvm_inline_asm" }, |
336 | 235 |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
236 // For special functions |
336 | 237 { "tohash", "toHash" }, |
238 { "tostring", "toString" }, | |
239 | |
240 // Special functions | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
241 //{ "alloca" }, |
336 | 242 { "main" }, |
243 { "WinMain" }, | |
244 { "DllMain" }, | |
245 }; | |
246 | |
247 | |
248 int main() | |
249 { | |
250 FILE *fp; | |
251 unsigned i; | |
252 | |
253 { | |
254 fp = fopen("id.h","w"); | |
255 if (!fp) | |
256 { printf("can't open id.h\n"); | |
257 exit(EXIT_FAILURE); | |
258 } | |
259 | |
260 fprintf(fp, "// File generated by idgen.c\n"); | |
261 #if __DMC__ | |
262 fprintf(fp, "#pragma once\n"); | |
263 #endif | |
264 fprintf(fp, "#ifndef DMD_ID_H\n"); | |
265 fprintf(fp, "#define DMD_ID_H 1\n"); | |
266 fprintf(fp, "struct Identifier;\n"); | |
267 fprintf(fp, "struct Id\n"); | |
268 fprintf(fp, "{\n"); | |
269 | |
270 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
271 { const char *id = msgtable[i].ident; |
336 | 272 |
273 fprintf(fp," static Identifier *%s;\n", id); | |
274 } | |
275 | |
276 fprintf(fp, " static void initialize();\n"); | |
277 fprintf(fp, "};\n"); | |
278 fprintf(fp, "#endif\n"); | |
279 | |
280 fclose(fp); | |
281 } | |
282 | |
283 { | |
284 fp = fopen("id.c","w"); | |
285 if (!fp) | |
286 { printf("can't open id.c\n"); | |
287 exit(EXIT_FAILURE); | |
288 } | |
289 | |
290 fprintf(fp, "// File generated by idgen.c\n"); | |
291 fprintf(fp, "#include \"id.h\"\n"); | |
292 fprintf(fp, "#include \"identifier.h\"\n"); | |
293 fprintf(fp, "#include \"lexer.h\"\n"); | |
294 | |
295 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
296 { const char *id = msgtable[i].ident; |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
297 const char *p = msgtable[i].name; |
336 | 298 |
299 if (!p) | |
300 p = id; | |
301 fprintf(fp,"Identifier *Id::%s;\n", id); | |
302 } | |
303 | |
304 fprintf(fp, "void Id::initialize()\n"); | |
305 fprintf(fp, "{\n"); | |
306 | |
307 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
308 { const char *id = msgtable[i].ident; |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
309 const char *p = msgtable[i].name; |
336 | 310 |
311 if (!p) | |
312 p = id; | |
313 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p); | |
314 } | |
315 | |
316 fprintf(fp, "}\n"); | |
317 | |
318 fclose(fp); | |
319 } | |
320 | |
321 return EXIT_SUCCESS; | |
322 } |