Mercurial > projects > ldc
annotate dmd/mars.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 | 9bf06e02070b |
children |
rev | line source |
---|---|
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
1 |
159 | 2 // Compiler implementation of the D programming language |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1628
diff
changeset
|
3 // Copyright (c) 1999-2010 by Digital Mars |
159 | 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 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <ctype.h> | |
14 #include <assert.h> | |
15 #include <limits.h> | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1628
diff
changeset
|
16 #if IN_LLVM |
159 | 17 #include <string> |
18 #include <cstdarg> | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1628
diff
changeset
|
19 #endif |
159 | 20 |
571
cbd6c8073a32
Changed all '#if linux || __APPLE__' to '#if POSIX' so we can support other platforms too, thanx for the suggestion anders.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
568
diff
changeset
|
21 #if POSIX |
159 | 22 #include <errno.h> |
432 | 23 #elif _WIN32 |
24 #include <windows.h> | |
159 | 25 #endif |
26 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1064
diff
changeset
|
27 #include "rmem.h" |
159 | 28 #include "root.h" |
29 | |
30 #include "mars.h" | |
31 #include "module.h" | |
32 #include "mtype.h" | |
33 #include "id.h" | |
34 #include "cond.h" | |
35 #include "expression.h" | |
36 #include "lexer.h" | |
1587 | 37 #include "json.h" |
159 | 38 |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1628
diff
changeset
|
39 #if IN_LLVM |
1064
f0b6549055ab
Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
40 #include "gen/revisions.h" |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1628
diff
changeset
|
41 #endif |
788
dce4b4ea2aee
Print llvm package string in version header. See #128.
Christian Kamm <kamm incasoftware de>
parents:
785
diff
changeset
|
42 |
159 | 43 Global global; |
44 | |
45 Global::Global() | |
46 { | |
47 mars_ext = "d"; | |
48 sym_ext = "d"; | |
49 hdr_ext = "di"; | |
50 doc_ext = "html"; | |
51 ddoc_ext = "ddoc"; | |
1587 | 52 json_ext = "json"; |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1628
diff
changeset
|
53 map_ext = "map"; |
159 | 54 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
55 // LDC |
159 | 56 ll_ext = "ll"; |
57 bc_ext = "bc"; | |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
58 s_ext = "s"; |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
59 obj_ext = "o"; |
374
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
60 #if _WIN32 |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
61 obj_ext_alt = "obj"; |
159 | 62 #endif |
63 | |
1640 | 64 copyright = "Copyright (c) 1999-2010 by Digital Mars and Tomas Lindquist Olsen"; |
159 | 65 written = "written by Walter Bright and Tomas Lindquist Olsen"; |
1640 | 66 version = "v1.057"; |
853
82ad6c0c601c
Add Elrood's patch to output LDC and LLVM source revs.
Christian Kamm <kamm incasoftware de>
parents:
849
diff
changeset
|
67 ldc_version = LDC_REV; |
1064
f0b6549055ab
Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
68 llvm_version = LLVM_REV_STR; |
159 | 69 global.structalign = 8; |
70 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
71 // This should only be used as a global, so the other fields are |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
72 // automatically initialized to zero when the program is loaded. |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
73 // In particular, DO NOT zero-initialize .params here (like DMD |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
74 // does) because command-line options initialize some of those |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
75 // fields to non-zero defaults, and do so from constructors that |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
76 // may run before this one. |
159 | 77 } |
78 | |
79 char *Loc::toChars() const | |
80 { | |
81 OutBuffer buf; | |
82 | |
83 if (filename) | |
84 { | |
85 buf.printf("%s", filename); | |
86 } | |
87 | |
88 if (linnum) | |
89 buf.printf("(%d)", linnum); | |
90 buf.writeByte(0); | |
91 return (char *)buf.extractData(); | |
92 } | |
93 | |
94 Loc::Loc(Module *mod, unsigned linnum) | |
95 { | |
96 this->linnum = linnum; | |
97 this->filename = mod ? mod->srcfile->toChars() : NULL; | |
98 } | |
99 | |
1587 | 100 bool Loc::equals(const Loc& loc) |
101 { | |
102 return linnum == loc.linnum && FileName::equals(filename, loc.filename); | |
103 } | |
104 | |
159 | 105 /************************************** |
106 * Print error message and exit. | |
107 */ | |
108 | |
109 void error(Loc loc, const char *format, ...) | |
110 { | |
111 va_list ap; | |
112 va_start(ap, format); | |
113 verror(loc, format, ap); | |
114 va_end( ap ); | |
115 } | |
116 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1064
diff
changeset
|
117 void warning(Loc loc, const char *format, ...) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1064
diff
changeset
|
118 { |
1640 | 119 va_list ap; |
120 va_start(ap, format); | |
121 vwarning(loc, format, ap); | |
122 va_end( ap ); | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1064
diff
changeset
|
123 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1064
diff
changeset
|
124 |
159 | 125 void verror(Loc loc, const char *format, va_list ap) |
126 { | |
127 if (!global.gag) | |
128 { | |
129 char *p = loc.toChars(); | |
130 | |
131 if (*p) | |
132 fprintf(stdmsg, "%s: ", p); | |
133 mem.free(p); | |
134 | |
135 fprintf(stdmsg, "Error: "); | |
136 vfprintf(stdmsg, format, ap); | |
137 fprintf(stdmsg, "\n"); | |
138 fflush(stdmsg); | |
139 } | |
140 global.errors++; | |
141 } | |
142 | |
1124
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
143 void vwarning(Loc loc, const char *format, va_list ap) |
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
144 { |
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
145 if (global.params.warnings && !global.gag) |
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
146 { |
1640 | 147 char *p = loc.toChars(); |
148 | |
149 if (*p) | |
150 fprintf(stdmsg, "%s: ", p); | |
151 mem.free(p); | |
1124
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
152 |
1640 | 153 fprintf(stdmsg, "Warning: "); |
154 #if _MSC_VER | |
155 // MS doesn't recognize %zu format | |
156 OutBuffer tmp; | |
157 tmp.vprintf(format, ap); | |
158 fprintf(stdmsg, "%s", tmp.toChars()); | |
159 #else | |
160 vfprintf(stdmsg, format, ap); | |
161 #endif | |
162 fprintf(stdmsg, "\n"); | |
163 fflush(stdmsg); | |
164 //halt(); | |
165 if (global.params.warnings == 1) | |
166 global.warnings++; // warnings don't count if gagged | |
1124
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
167 } |
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
168 } |
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
169 |
159 | 170 /*************************************** |
171 * Call this after printing out fatal error messages to clean up and exit | |
172 * the compiler. | |
173 */ | |
174 | |
175 void fatal() | |
176 { | |
177 #if 0 | |
178 halt(); | |
179 #endif | |
180 exit(EXIT_FAILURE); | |
181 } | |
182 | |
183 /************************************** | |
184 * Try to stop forgetting to remove the breakpoints from | |
185 * release builds. | |
186 */ | |
187 void halt() | |
188 { | |
189 #ifdef DEBUG | |
190 *(char*)0=0; | |
191 #endif | |
192 } | |
193 | |
1640 | 194 |
159 | 195 /*********************************** |
196 * Parse and append contents of environment variable envvar | |
197 * to argc and argv[]. | |
198 * The string is separated into arguments, processing \ and ". | |
199 */ | |
200 | |
201 void getenv_setargv(const char *envvar, int *pargc, char** *pargv) | |
202 { | |
203 char *p; | |
204 | |
205 int instring; | |
206 int slash; | |
207 char c; | |
208 | |
1587 | 209 char *env = getenv(envvar); |
159 | 210 if (!env) |
211 return; | |
212 | |
213 env = mem.strdup(env); // create our own writable copy | |
214 | |
1587 | 215 int argc = *pargc; |
216 Array *argv = new Array(); | |
159 | 217 argv->setDim(argc); |
218 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
219 int argc_left = 0; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
220 for (int i = 0; i < argc; i++) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
221 if (!strcmp((*pargv)[i], "-run") || !strcmp((*pargv)[i], "--run")) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
222 // HACK: set flag to indicate we saw '-run' here |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
223 global.params.run = true; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
224 // Don't eat -run yet so the program arguments don't get changed |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
225 argc_left = argc - i; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
226 argc = i; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
227 *pargv = &(*pargv)[i]; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
228 argv->setDim(i); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
229 break; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
230 } else { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
231 argv->data[i] = (void *)(*pargv)[i]; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
232 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
233 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
234 // HACK to stop required values from command line being drawn from DFLAGS |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
235 argv->push((char*)""); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
236 argc++; |
159 | 237 |
1587 | 238 int j = 1; // leave argv[0] alone |
159 | 239 while (1) |
240 { | |
1587 | 241 int wildcard = 1; // do wildcard expansion |
159 | 242 switch (*env) |
243 { | |
244 case ' ': | |
245 case '\t': | |
246 env++; | |
247 break; | |
248 | |
249 case 0: | |
250 goto Ldone; | |
251 | |
252 case '"': | |
253 wildcard = 0; | |
254 default: | |
255 argv->push(env); // append | |
256 //argv->insert(j, env); // insert at position j | |
257 j++; | |
258 argc++; | |
259 p = env; | |
260 slash = 0; | |
261 instring = 0; | |
262 c = 0; | |
263 | |
264 while (1) | |
265 { | |
266 c = *env++; | |
267 switch (c) | |
268 { | |
269 case '"': | |
270 p -= (slash >> 1); | |
271 if (slash & 1) | |
272 { p--; | |
273 goto Laddc; | |
274 } | |
275 instring ^= 1; | |
276 slash = 0; | |
277 continue; | |
278 | |
279 case ' ': | |
280 case '\t': | |
281 if (instring) | |
282 goto Laddc; | |
283 *p = 0; | |
284 //if (wildcard) | |
285 //wildcardexpand(); // not implemented | |
286 break; | |
287 | |
288 case '\\': | |
289 slash++; | |
290 *p++ = c; | |
291 continue; | |
292 | |
293 case 0: | |
294 *p = 0; | |
295 //if (wildcard) | |
296 //wildcardexpand(); // not implemented | |
297 goto Ldone; | |
298 | |
299 default: | |
300 Laddc: | |
301 slash = 0; | |
302 *p++ = c; | |
303 continue; | |
304 } | |
305 break; | |
306 } | |
307 } | |
308 } | |
309 | |
310 Ldone: | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
311 assert(argc == argv->dim); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
312 argv->reserve(argc_left); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
313 for (int i = 0; i < argc_left; i++) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
314 argv->data[argc++] = (void *)(*pargv)[i]; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
315 |
159 | 316 *pargc = argc; |
317 *pargv = (char **)argv->data; | |
318 } |