Mercurial > projects > ldc
annotate dmd/idgen.c @ 650:aa6a0b7968f7
Added test case for bug #100
Removed dubious check for not emitting static private global in other modules without access. This should be handled properly somewhere else, it's causing unresolved global errors for stuff that should work (in MiniD)
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 05 Oct 2008 17:28:15 +0200 |
parents | a34078905d01 |
children | 50383e476c7e |
rev | line source |
---|---|
336 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2006 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 char *ident; // name to use in DMD source | |
26 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 { "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 | |
212 { "lib" }, | |
213 { "msg" }, | |
214 { "GNU_asm" }, | |
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 |
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
|
216 // LLVMDC pragma's |
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" }, |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
226 { "llvmdc" }, |
336 | 227 |
228 // For toHash/toString | |
229 { "tohash", "toHash" }, | |
230 { "tostring", "toString" }, | |
231 | |
232 // 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
|
233 //{ "alloca" }, |
336 | 234 { "main" }, |
235 { "WinMain" }, | |
236 { "DllMain" }, | |
237 }; | |
238 | |
239 | |
240 int main() | |
241 { | |
242 FILE *fp; | |
243 unsigned i; | |
244 | |
245 { | |
246 fp = fopen("id.h","w"); | |
247 if (!fp) | |
248 { printf("can't open id.h\n"); | |
249 exit(EXIT_FAILURE); | |
250 } | |
251 | |
252 fprintf(fp, "// File generated by idgen.c\n"); | |
253 #if __DMC__ | |
254 fprintf(fp, "#pragma once\n"); | |
255 #endif | |
256 fprintf(fp, "#ifndef DMD_ID_H\n"); | |
257 fprintf(fp, "#define DMD_ID_H 1\n"); | |
258 fprintf(fp, "struct Identifier;\n"); | |
259 fprintf(fp, "struct Id\n"); | |
260 fprintf(fp, "{\n"); | |
261 | |
262 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
263 { char *id = msgtable[i].ident; | |
264 | |
265 fprintf(fp," static Identifier *%s;\n", id); | |
266 } | |
267 | |
268 fprintf(fp, " static void initialize();\n"); | |
269 fprintf(fp, "};\n"); | |
270 fprintf(fp, "#endif\n"); | |
271 | |
272 fclose(fp); | |
273 } | |
274 | |
275 { | |
276 fp = fopen("id.c","w"); | |
277 if (!fp) | |
278 { printf("can't open id.c\n"); | |
279 exit(EXIT_FAILURE); | |
280 } | |
281 | |
282 fprintf(fp, "// File generated by idgen.c\n"); | |
283 fprintf(fp, "#include \"id.h\"\n"); | |
284 fprintf(fp, "#include \"identifier.h\"\n"); | |
285 fprintf(fp, "#include \"lexer.h\"\n"); | |
286 | |
287 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
288 { char *id = msgtable[i].ident; | |
289 char *p = msgtable[i].name; | |
290 | |
291 if (!p) | |
292 p = id; | |
293 fprintf(fp,"Identifier *Id::%s;\n", id); | |
294 } | |
295 | |
296 fprintf(fp, "void Id::initialize()\n"); | |
297 fprintf(fp, "{\n"); | |
298 | |
299 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
300 { char *id = msgtable[i].ident; | |
301 char *p = msgtable[i].name; | |
302 | |
303 if (!p) | |
304 p = id; | |
305 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p); | |
306 } | |
307 | |
308 fprintf(fp, "}\n"); | |
309 | |
310 fclose(fp); | |
311 } | |
312 | |
313 return EXIT_SUCCESS; | |
314 } |