Mercurial > projects > ldc
comparison dmd2/mars.c @ 1452:638d16625da2
LDC 2 compiles again.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Sat, 30 May 2009 17:23:32 +0100 |
parents | 123812e02bc8 |
children | 54b3c1394d62 |
comparison
equal
deleted
inserted
replaced
1423:42bd767ec5a4 | 1452:638d16625da2 |
---|---|
1 | |
1 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
2 // Copyright (c) 1999-2009 by Digital Mars | 3 // Copyright (c) 1999-2009 by Digital Mars |
3 // All Rights Reserved | 4 // All Rights Reserved |
4 // written by Walter Bright | 5 // written by Walter Bright |
5 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
13 #include <assert.h> | 14 #include <assert.h> |
14 #include <limits.h> | 15 #include <limits.h> |
15 #include <string> | 16 #include <string> |
16 #include <cstdarg> | 17 #include <cstdarg> |
17 | 18 |
18 #if __DMC__ | |
19 #include <dos.h> | |
20 #endif | |
21 | |
22 #if POSIX | 19 #if POSIX |
23 #include <errno.h> | 20 #include <errno.h> |
24 #elif _WIN32 | 21 #elif _WIN32 |
25 #include <windows.h> | 22 #include <windows.h> |
26 #endif | 23 #endif |
27 | 24 |
28 #include "mem.h" | 25 #include "rmem.h" |
29 #include "root.h" | 26 #include "root.h" |
27 #if !IN_LLVM | |
28 #include "async.h" | |
29 #endif | |
30 | 30 |
31 #include "mars.h" | 31 #include "mars.h" |
32 #include "module.h" | 32 #include "module.h" |
33 #include "mtype.h" | 33 #include "mtype.h" |
34 #include "id.h" | 34 #include "id.h" |
35 #include "cond.h" | 35 #include "cond.h" |
36 #include "expression.h" | 36 #include "expression.h" |
37 #include "lexer.h" | 37 #include "lexer.h" |
38 | 38 #if IN_LLVM |
39 #include "revisions.h" | 39 #include "gen/revisions.h" |
40 #else | |
41 #include "lib.h" | |
42 | |
43 #if WINDOWS_SEH | |
44 #include <windows.h> | |
45 long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep); | |
46 #endif | |
47 | |
48 | |
49 int response_expand(int *pargc, char ***pargv); | |
50 void browse(const char *url); | |
51 void getenv_setargv(const char *envvar, int *pargc, char** *pargv); | |
52 | |
53 void obj_start(char *srcfile); | |
54 void obj_end(Library *library, File *objfile); | |
55 #endif | |
40 | 56 |
41 Global global; | 57 Global global; |
42 | 58 |
43 Global::Global() | 59 Global::Global() |
44 { | 60 { |
46 sym_ext = "d"; | 62 sym_ext = "d"; |
47 hdr_ext = "di"; | 63 hdr_ext = "di"; |
48 doc_ext = "html"; | 64 doc_ext = "html"; |
49 ddoc_ext = "ddoc"; | 65 ddoc_ext = "ddoc"; |
50 | 66 |
51 // LDC | 67 #if IN_LLVM |
52 ll_ext = "ll"; | 68 ll_ext = "ll"; |
53 bc_ext = "bc"; | 69 bc_ext = "bc"; |
54 s_ext = "s"; | 70 s_ext = "s"; |
55 obj_ext = "o"; | 71 obj_ext = "o"; |
56 #if _WIN32 | 72 #if _WIN32 |
57 obj_ext_alt = "obj"; | 73 obj_ext_alt = "obj"; |
58 #endif | 74 #endif |
59 | 75 #else |
60 copyright = "Copyright (c) 1999-2009 by Digital Mars and Tomas Lindquist Olsen"; | 76 #if TARGET_WINDOS |
61 written = "written by Walter Bright and Tomas Lindquist Olsen"; | 77 obj_ext = "obj"; |
62 version = "v2.021"; | 78 #elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
79 obj_ext = "o"; | |
80 #elif TARGET_NET | |
81 #else | |
82 #error "fix this" | |
83 #endif | |
84 | |
85 #if TARGET_WINDOS | |
86 lib_ext = "lib"; | |
87 #elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS | |
88 lib_ext = "a"; | |
89 #elif TARGET_NET | |
90 #else | |
91 #error "fix this" | |
92 #endif | |
93 #endif | |
94 | |
95 copyright = "Copyright (c) 1999-2009 by Digital Mars"; | |
96 written = "written by Walter Bright" | |
97 #if TARGET_NET | |
98 "\nMSIL back-end (alpha release) by Cristian L. Vlasceanu and associates."; | |
99 #endif | |
100 ; | |
101 version = "v2.030"; | |
102 #if IN_LLVM | |
63 ldc_version = LDC_REV; | 103 ldc_version = LDC_REV; |
64 llvm_version = LLVM_REV_STR; | 104 llvm_version = LLVM_REV_STR; |
105 #endif | |
65 global.structalign = 8; | 106 global.structalign = 8; |
66 | 107 |
67 // This should only be used as a global, so the other fields are | 108 // This should only be used as a global, so the other fields are |
68 // automatically initialized to zero when the program is loaded. | 109 // automatically initialized to zero when the program is loaded. |
69 // In particular, DO NOT zero-initialize .params here (like DMD | 110 // In particular, DO NOT zero-initialize .params here (like DMD |
70 // does) because command-line options initialize some of those | 111 // does) because command-line options initialize some of those |
71 // fields to non-zero defaults, and do so from constructors that | 112 // fields to non-zero defaults, and do so from constructors that |
72 // may run before this one. | 113 // may run before this one. |
73 } | 114 } |
74 | 115 |
75 char *Loc::toChars() const | 116 char *Loc::toChars() |
76 { | 117 { |
77 OutBuffer buf; | 118 OutBuffer buf; |
78 | 119 |
79 if (filename) | 120 if (filename) |
80 { | 121 { |
81 buf.printf("%s", filename); | 122 buf.printf("%s", filename); |
82 } | 123 } |
83 | 124 |
84 if (linnum) | 125 if (linnum) |
85 buf.printf("(%d)", linnum); | 126 buf.printf("(%d)", linnum); |
86 buf.writeByte(0); | 127 buf.writeByte(0); |
87 return (char *)buf.extractData(); | 128 return (char *)buf.extractData(); |
88 } | 129 } |
89 | 130 |
90 Loc::Loc(Module *mod, unsigned linnum) | 131 Loc::Loc(Module *mod, unsigned linnum) |
91 { | 132 { |
92 this->linnum = linnum; | 133 this->linnum = linnum; |
93 this->filename = mod ? mod->srcfile->toChars() : NULL; | 134 this->filename = mod ? mod->srcfile->toChars() : NULL; |
135 } | |
136 | |
137 bool Loc::equals(const Loc& loc) | |
138 { | |
139 return linnum == loc.linnum && FileName::equals(filename, loc.filename); | |
94 } | 140 } |
95 | 141 |
96 /************************************** | 142 /************************************** |
97 * Print error message and exit. | 143 * Print error message and exit. |
98 */ | 144 */ |
103 va_start(ap, format); | 149 va_start(ap, format); |
104 verror(loc, format, ap); | 150 verror(loc, format, ap); |
105 va_end( ap ); | 151 va_end( ap ); |
106 } | 152 } |
107 | 153 |
154 void warning(Loc loc, const char *format, ...) | |
155 { | |
156 if (global.params.warnings && !global.gag) | |
157 { | |
158 va_list ap; | |
159 va_start(ap, format); | |
160 vwarning(loc, format, ap); | |
161 va_end( ap ); | |
162 } | |
163 } | |
164 | |
108 void verror(Loc loc, const char *format, va_list ap) | 165 void verror(Loc loc, const char *format, va_list ap) |
109 { | 166 { |
110 if (!global.gag) | 167 if (!global.gag) |
111 { | 168 { |
112 char *p = loc.toChars(); | 169 char *p = loc.toChars(); |
113 | 170 |
114 if (*p) | 171 if (*p) |
115 fprintf(stdmsg, "%s: ", p); | 172 fprintf(stdmsg, "%s: ", p); |
116 mem.free(p); | 173 mem.free(p); |
117 | 174 |
118 fprintf(stdmsg, "Error: "); | 175 fprintf(stdmsg, "Error: "); |
119 vfprintf(stdmsg, format, ap); | 176 vfprintf(stdmsg, format, ap); |
120 fprintf(stdmsg, "\n"); | 177 fprintf(stdmsg, "\n"); |
121 fflush(stdmsg); | 178 fflush(stdmsg); |
122 } | 179 } |
123 global.errors++; | 180 global.errors++; |
181 } | |
182 | |
183 void vwarning(Loc loc, const char *format, va_list ap) | |
184 { | |
185 if (global.params.warnings && !global.gag) | |
186 { | |
187 char *p = loc.toChars(); | |
188 | |
189 if (*p) | |
190 fprintf(stdmsg, "%s: ", p); | |
191 mem.free(p); | |
192 | |
193 fprintf(stdmsg, "Warning: "); | |
194 vfprintf(stdmsg, format, ap); | |
195 fprintf(stdmsg, "\n"); | |
196 fflush(stdmsg); | |
197 } | |
124 } | 198 } |
125 | 199 |
126 /*************************************** | 200 /*************************************** |
127 * Call this after printing out fatal error messages to clean up and exit | 201 * Call this after printing out fatal error messages to clean up and exit |
128 * the compiler. | 202 * the compiler. |
158 char *env; | 232 char *env; |
159 char *p; | 233 char *p; |
160 Array *argv; | 234 Array *argv; |
161 int argc; | 235 int argc; |
162 | 236 |
163 int wildcard; // do wildcard expansion | 237 int wildcard; // do wildcard expansion |
164 int instring; | 238 int instring; |
165 int slash; | 239 int slash; |
166 char c; | 240 char c; |
167 int j; | 241 int j; |
168 | 242 |
169 env = getenv(envvar); | 243 env = getenv(envvar); |
170 if (!env) | 244 if (!env) |
171 return; | 245 return; |
172 | 246 |
173 env = mem.strdup(env); // create our own writable copy | 247 env = mem.strdup(env); // create our own writable copy |
174 | 248 |
175 argc = *pargc; | 249 argc = *pargc; |
176 argv = new Array(); | 250 argv = new Array(); |
177 argv->setDim(argc); | 251 argv->setDim(argc); |
178 | 252 |
193 } | 267 } |
194 // HACK to stop required values from command line being drawn from DFLAGS | 268 // HACK to stop required values from command line being drawn from DFLAGS |
195 argv->push((char*)""); | 269 argv->push((char*)""); |
196 argc++; | 270 argc++; |
197 | 271 |
198 j = 1; // leave argv[0] alone | 272 j = 1; // leave argv[0] alone |
199 while (1) | 273 while (1) |
200 { | 274 { |
201 wildcard = 1; | 275 wildcard = 1; |
202 switch (*env) | 276 switch (*env) |
203 { | 277 { |
204 case ' ': | 278 case ' ': |
205 case '\t': | 279 case '\t': |
206 env++; | 280 env++; |
207 break; | 281 break; |
208 | 282 |
209 case 0: | 283 case 0: |
210 goto Ldone; | 284 goto Ldone; |
211 | 285 |
212 case '"': | 286 case '"': |
213 wildcard = 0; | 287 wildcard = 0; |
214 default: | 288 default: |
215 argv->push(env); // append | 289 argv->push(env); // append |
216 //argv->insert(j, env); // insert at position j | 290 //argv->insert(j, env); // insert at position j |
217 j++; | 291 j++; |
218 argc++; | 292 argc++; |
219 p = env; | 293 p = env; |
220 slash = 0; | 294 slash = 0; |
221 instring = 0; | 295 instring = 0; |
222 c = 0; | 296 c = 0; |
223 | 297 |
224 while (1) | 298 while (1) |
225 { | 299 { |
226 c = *env++; | 300 c = *env++; |
227 switch (c) | 301 switch (c) |
228 { | 302 { |
229 case '"': | 303 case '"': |
230 p -= (slash >> 1); | 304 p -= (slash >> 1); |
231 if (slash & 1) | 305 if (slash & 1) |
232 { p--; | 306 { p--; |
233 goto Laddc; | 307 goto Laddc; |
234 } | 308 } |
235 instring ^= 1; | 309 instring ^= 1; |
236 slash = 0; | 310 slash = 0; |
237 continue; | 311 continue; |
238 | 312 |
239 case ' ': | 313 case ' ': |
240 case '\t': | 314 case '\t': |
241 if (instring) | 315 if (instring) |
242 goto Laddc; | 316 goto Laddc; |
243 *p = 0; | 317 *p = 0; |
244 //if (wildcard) | 318 //if (wildcard) |
245 //wildcardexpand(); // not implemented | 319 //wildcardexpand(); // not implemented |
246 break; | 320 break; |
247 | 321 |
248 case '\\': | 322 case '\\': |
249 slash++; | 323 slash++; |
250 *p++ = c; | 324 *p++ = c; |
251 continue; | 325 continue; |
252 | 326 |
253 case 0: | 327 case 0: |
254 *p = 0; | 328 *p = 0; |
255 //if (wildcard) | 329 //if (wildcard) |
256 //wildcardexpand(); // not implemented | 330 //wildcardexpand(); // not implemented |
257 goto Ldone; | 331 goto Ldone; |
258 | 332 |
259 default: | 333 default: |
260 Laddc: | 334 Laddc: |
261 slash = 0; | 335 slash = 0; |
262 *p++ = c; | 336 *p++ = c; |
263 continue; | 337 continue; |
264 } | 338 } |
265 break; | 339 break; |
266 } | 340 } |
267 } | 341 } |
268 } | 342 } |
269 | 343 |
270 Ldone: | 344 Ldone: |
271 assert(argc == argv->dim); | 345 assert(argc == argv->dim); |
272 argv->reserve(argc_left); | 346 argv->reserve(argc_left); |