Mercurial > projects > ldc
annotate dmd/idgen.c @ 945:03d7c4aac654
SWITCHED TO LLVM 2.5 !
Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel.
Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple.
Fixed return calling convention for complex numbers, ST and ST(1) were switched around.
Added some testcases.
I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 08 Feb 2009 05:26:54 +0100 |
parents | 6aaa3d3c1183 |
children | 521dd1626d76 |
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" }, |
336 | 228 |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
229 // For special functions |
336 | 230 { "tohash", "toHash" }, |
231 { "tostring", "toString" }, | |
232 | |
233 // 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
|
234 //{ "alloca" }, |
336 | 235 { "main" }, |
236 { "WinMain" }, | |
237 { "DllMain" }, | |
238 }; | |
239 | |
240 | |
241 int main() | |
242 { | |
243 FILE *fp; | |
244 unsigned i; | |
245 | |
246 { | |
247 fp = fopen("id.h","w"); | |
248 if (!fp) | |
249 { printf("can't open id.h\n"); | |
250 exit(EXIT_FAILURE); | |
251 } | |
252 | |
253 fprintf(fp, "// File generated by idgen.c\n"); | |
254 #if __DMC__ | |
255 fprintf(fp, "#pragma once\n"); | |
256 #endif | |
257 fprintf(fp, "#ifndef DMD_ID_H\n"); | |
258 fprintf(fp, "#define DMD_ID_H 1\n"); | |
259 fprintf(fp, "struct Identifier;\n"); | |
260 fprintf(fp, "struct Id\n"); | |
261 fprintf(fp, "{\n"); | |
262 | |
263 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
|
264 { const char *id = msgtable[i].ident; |
336 | 265 |
266 fprintf(fp," static Identifier *%s;\n", id); | |
267 } | |
268 | |
269 fprintf(fp, " static void initialize();\n"); | |
270 fprintf(fp, "};\n"); | |
271 fprintf(fp, "#endif\n"); | |
272 | |
273 fclose(fp); | |
274 } | |
275 | |
276 { | |
277 fp = fopen("id.c","w"); | |
278 if (!fp) | |
279 { printf("can't open id.c\n"); | |
280 exit(EXIT_FAILURE); | |
281 } | |
282 | |
283 fprintf(fp, "// File generated by idgen.c\n"); | |
284 fprintf(fp, "#include \"id.h\"\n"); | |
285 fprintf(fp, "#include \"identifier.h\"\n"); | |
286 fprintf(fp, "#include \"lexer.h\"\n"); | |
287 | |
288 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
|
289 { 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
|
290 const char *p = msgtable[i].name; |
336 | 291 |
292 if (!p) | |
293 p = id; | |
294 fprintf(fp,"Identifier *Id::%s;\n", id); | |
295 } | |
296 | |
297 fprintf(fp, "void Id::initialize()\n"); | |
298 fprintf(fp, "{\n"); | |
299 | |
300 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
|
301 { 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
|
302 const char *p = msgtable[i].name; |
336 | 303 |
304 if (!p) | |
305 p = id; | |
306 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p); | |
307 } | |
308 | |
309 fprintf(fp, "}\n"); | |
310 | |
311 fclose(fp); | |
312 } | |
313 | |
314 return EXIT_SUCCESS; | |
315 } |