Mercurial > projects > ldc
annotate dmd/idgen.c @ 1351:8d501abecd24
Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Thu, 14 May 2009 17:20:17 +0200 |
parents | 521dd1626d76 |
children | def7a1d494fd |
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" }, | |
41 { "init" }, | |
42 { "size" }, | |
43 { "__sizeof", "sizeof" }, | |
44 { "alignof" }, | |
45 { "mangleof" }, | |
46 { "stringof" }, | |
47 { "tupleof" }, | |
48 { "length" }, | |
49 { "remove" }, | |
50 { "ptr" }, | |
51 { "funcptr" }, | |
52 { "dollar", "__dollar" }, | |
53 { "offset" }, | |
54 { "offsetof" }, | |
55 { "ModuleInfo" }, | |
56 { "ClassInfo" }, | |
57 { "classinfo" }, | |
58 { "typeinfo" }, | |
59 { "outer" }, | |
60 { "Exception" }, | |
61 { "withSym", "__withSym" }, | |
62 { "result", "__result" }, | |
63 { "returnLabel", "__returnLabel" }, | |
64 { "delegate" }, | |
65 { "line" }, | |
66 { "empty", "" }, | |
67 { "p" }, | |
68 { "coverage", "__coverage" }, | |
69 { "__vptr" }, | |
70 { "__monitor" }, | |
71 | |
72 { "TypeInfo" }, | |
73 { "TypeInfo_Class" }, | |
74 { "TypeInfo_Interface" }, | |
75 { "TypeInfo_Struct" }, | |
76 { "TypeInfo_Enum" }, | |
77 { "TypeInfo_Typedef" }, | |
78 { "TypeInfo_Pointer" }, | |
79 { "TypeInfo_Array" }, | |
80 { "TypeInfo_StaticArray" }, | |
81 { "TypeInfo_AssociativeArray" }, | |
82 { "TypeInfo_Function" }, | |
83 { "TypeInfo_Delegate" }, | |
84 { "TypeInfo_Tuple" }, | |
85 { "TypeInfo_Const" }, | |
86 { "TypeInfo_Invariant" }, | |
87 { "elements" }, | |
88 { "_arguments_typeinfo" }, | |
89 { "_arguments" }, | |
90 { "_argptr" }, | |
91 { "_match" }, | |
92 | |
93 { "LINE", "__LINE__" }, | |
94 { "FILE", "__FILE__" }, | |
95 { "DATE", "__DATE__" }, | |
96 { "TIME", "__TIME__" }, | |
97 { "TIMESTAMP", "__TIMESTAMP__" }, | |
98 { "VENDOR", "__VENDOR__" }, | |
99 { "VERSIONX", "__VERSION__" }, | |
100 | |
101 { "nan" }, | |
102 { "infinity" }, | |
103 { "dig" }, | |
104 { "epsilon" }, | |
105 { "mant_dig" }, | |
106 { "max_10_exp" }, | |
107 { "max_exp" }, | |
108 { "min_10_exp" }, | |
109 { "min_exp" }, | |
110 { "re" }, | |
111 { "im" }, | |
112 | |
113 { "C" }, | |
114 { "D" }, | |
115 { "Windows" }, | |
116 { "Pascal" }, | |
117 { "System" }, | |
118 | |
119 { "exit" }, | |
120 { "success" }, | |
121 { "failure" }, | |
122 | |
123 { "keys" }, | |
124 { "values" }, | |
125 { "rehash" }, | |
126 | |
127 { "sort" }, | |
128 { "reverse" }, | |
129 { "dup" }, | |
130 { "idup" }, | |
131 | |
132 // For inline assembler | |
133 { "___out", "out" }, | |
134 { "___in", "in" }, | |
135 { "__int", "int" }, | |
136 { "__dollar", "$" }, | |
137 { "__LOCAL_SIZE" }, | |
138 | |
139 // For operator overloads | |
140 { "uadd", "opPos" }, | |
141 { "neg", "opNeg" }, | |
142 { "com", "opCom" }, | |
143 { "add", "opAdd" }, | |
144 { "add_r", "opAdd_r" }, | |
145 { "sub", "opSub" }, | |
146 { "sub_r", "opSub_r" }, | |
147 { "mul", "opMul" }, | |
148 { "mul_r", "opMul_r" }, | |
149 { "div", "opDiv" }, | |
150 { "div_r", "opDiv_r" }, | |
151 { "mod", "opMod" }, | |
152 { "mod_r", "opMod_r" }, | |
153 { "eq", "opEquals" }, | |
154 { "cmp", "opCmp" }, | |
155 { "iand", "opAnd" }, | |
156 { "iand_r", "opAnd_r" }, | |
157 { "ior", "opOr" }, | |
158 { "ior_r", "opOr_r" }, | |
159 { "ixor", "opXor" }, | |
160 { "ixor_r", "opXor_r" }, | |
161 { "shl", "opShl" }, | |
162 { "shl_r", "opShl_r" }, | |
163 { "shr", "opShr" }, | |
164 { "shr_r", "opShr_r" }, | |
165 { "ushr", "opUShr" }, | |
166 { "ushr_r", "opUShr_r" }, | |
167 { "cat", "opCat" }, | |
168 { "cat_r", "opCat_r" }, | |
169 { "assign", "opAssign" }, | |
170 { "addass", "opAddAssign" }, | |
171 { "subass", "opSubAssign" }, | |
172 { "mulass", "opMulAssign" }, | |
173 { "divass", "opDivAssign" }, | |
174 { "modass", "opModAssign" }, | |
175 { "andass", "opAndAssign" }, | |
176 { "orass", "opOrAssign" }, | |
177 { "xorass", "opXorAssign" }, | |
178 { "shlass", "opShlAssign" }, | |
179 { "shrass", "opShrAssign" }, | |
180 { "ushrass", "opUShrAssign" }, | |
181 { "catass", "opCatAssign" }, | |
182 { "postinc", "opPostInc" }, | |
183 { "postdec", "opPostDec" }, | |
184 { "index", "opIndex" }, | |
185 { "indexass", "opIndexAssign" }, | |
186 { "slice", "opSlice" }, | |
187 { "sliceass", "opSliceAssign" }, | |
188 { "call", "opCall" }, | |
189 { "cast", "opCast" }, | |
190 { "match", "opMatch" }, | |
191 { "next", "opNext" }, | |
192 { "opIn" }, | |
193 { "opIn_r" }, | |
194 | |
195 { "classNew", "new" }, | |
196 { "classDelete", "delete" }, | |
197 | |
198 // For foreach | |
199 { "apply", "opApply" }, | |
200 { "applyReverse", "opApplyReverse" }, | |
201 | |
202 { "adDup", "_adDupT" }, | |
203 { "adReverse", "_adReverse" }, | |
204 | |
205 // For internal functions | |
206 { "aaLen", "_aaLen" }, | |
207 { "aaKeys", "_aaKeys" }, | |
208 { "aaValues", "_aaValues" }, | |
209 { "aaRehash", "_aaRehash" }, | |
210 | |
211 // For pragma's | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
212 { "GNU_asm" }, |
336 | 213 { "lib" }, |
214 { "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
|
215 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
216 // 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
|
217 { "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
|
218 { "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
|
219 { "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
|
220 { "no_moduleinfo" }, |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
221 { "Alloca", "alloca" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
222 { "vastart", "va_start" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
223 { "vacopy", "va_copy" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
224 { "vaend", "va_end" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
225 { "vaarg", "va_arg" }, |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
226 { "ldc" }, |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
663
diff
changeset
|
227 { "allow_inline" }, |
1152
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
945
diff
changeset
|
228 { "llvm_inline_asm" }, |
336 | 229 |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
230 // For special functions |
336 | 231 { "tohash", "toHash" }, |
232 { "tostring", "toString" }, | |
233 | |
234 // 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
|
235 //{ "alloca" }, |
336 | 236 { "main" }, |
237 { "WinMain" }, | |
238 { "DllMain" }, | |
239 }; | |
240 | |
241 | |
242 int main() | |
243 { | |
244 FILE *fp; | |
245 unsigned i; | |
246 | |
247 { | |
248 fp = fopen("id.h","w"); | |
249 if (!fp) | |
250 { printf("can't open id.h\n"); | |
251 exit(EXIT_FAILURE); | |
252 } | |
253 | |
254 fprintf(fp, "// File generated by idgen.c\n"); | |
255 #if __DMC__ | |
256 fprintf(fp, "#pragma once\n"); | |
257 #endif | |
258 fprintf(fp, "#ifndef DMD_ID_H\n"); | |
259 fprintf(fp, "#define DMD_ID_H 1\n"); | |
260 fprintf(fp, "struct Identifier;\n"); | |
261 fprintf(fp, "struct Id\n"); | |
262 fprintf(fp, "{\n"); | |
263 | |
264 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
|
265 { const char *id = msgtable[i].ident; |
336 | 266 |
267 fprintf(fp," static Identifier *%s;\n", id); | |
268 } | |
269 | |
270 fprintf(fp, " static void initialize();\n"); | |
271 fprintf(fp, "};\n"); | |
272 fprintf(fp, "#endif\n"); | |
273 | |
274 fclose(fp); | |
275 } | |
276 | |
277 { | |
278 fp = fopen("id.c","w"); | |
279 if (!fp) | |
280 { printf("can't open id.c\n"); | |
281 exit(EXIT_FAILURE); | |
282 } | |
283 | |
284 fprintf(fp, "// File generated by idgen.c\n"); | |
285 fprintf(fp, "#include \"id.h\"\n"); | |
286 fprintf(fp, "#include \"identifier.h\"\n"); | |
287 fprintf(fp, "#include \"lexer.h\"\n"); | |
288 | |
289 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
|
290 { 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
|
291 const char *p = msgtable[i].name; |
336 | 292 |
293 if (!p) | |
294 p = id; | |
295 fprintf(fp,"Identifier *Id::%s;\n", id); | |
296 } | |
297 | |
298 fprintf(fp, "void Id::initialize()\n"); | |
299 fprintf(fp, "{\n"); | |
300 | |
301 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
|
302 { 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
|
303 const char *p = msgtable[i].name; |
336 | 304 |
305 if (!p) | |
306 p = id; | |
307 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p); | |
308 } | |
309 | |
310 fprintf(fp, "}\n"); | |
311 | |
312 fclose(fp); | |
313 } | |
314 | |
315 return EXIT_SUCCESS; | |
316 } |