annotate dmd/mars.c @ 205:9d44ec83acd1 trunk

[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 . Fixed: Implemented volatile statements. Uses the LLVM memory barrier intrinsic, closes #21 .
author lindquist
date Tue, 13 May 2008 17:58:11 +0200
parents 5acec6b2eef8
children 0806379a5eca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
159
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1 // Compiler implementation of the D programming language
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
2 // Copyright (c) 1999-2008 by Digital Mars
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
3 // All Rights Reserved
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
4 // written by Walter Bright
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
5 // http://www.digitalmars.com
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
6 // License for redistribution is by either the Artistic License
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
8 // See the included readme.txt for details.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
9
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
10 #include "llvm/Target/TargetMachineRegistry.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
11
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
12 #include <stdio.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
13 #include <stdlib.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
14 #include <ctype.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
15 #include <assert.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
16 #include <limits.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
17 #include <string>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
18 #include <cstdarg>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
19
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
20 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
21 #include <windows.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
22 long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
23 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
24
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
25 #if __DMC__
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
26 #include <dos.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
27 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
28
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
29 #if linux
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
30 #include <errno.h>
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
31 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
33 #include "mem.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
34 #include "root.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
35
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
36 #include "mars.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
37 #include "module.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
38 #include "mtype.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
39 #include "id.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
40 #include "cond.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
41 #include "expression.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
42 #include "lexer.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
43
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
44 #include "gen/logger.h"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
45
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
46 void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
47
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
48 Global global;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
49
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
50 Global::Global()
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
51 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
52 mars_ext = "d";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
53 sym_ext = "d";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
54 hdr_ext = "di";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
55 doc_ext = "html";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
56 ddoc_ext = "ddoc";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
57
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
58 #if IN_LLVM
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
59 obj_ext = "bc";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
60 ll_ext = "ll";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
61 bc_ext = "bc";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
62 nativeobj_ext = "o";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
63 #elif _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
64 obj_ext = "obj";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
65 #elif linux
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
66 obj_ext = "o";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
67 #else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
68 #error "fix this"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
69 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
70
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
71 copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
72 written = "written by Walter Bright and Tomas Lindquist Olsen";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
73 version = "v1.029";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
74 llvmdc_version = "0.1";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
75 global.structalign = 8;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
76
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
77 memset(&params, 0, sizeof(Param));
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
78 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
79
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
80 char *Loc::toChars() const
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
81 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
82 OutBuffer buf;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
83 char *p;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
84
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
85 if (filename)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
86 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
87 buf.printf("%s", filename);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
88 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
89
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
90 if (linnum)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
91 buf.printf("(%d)", linnum);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
92 buf.writeByte(0);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
93 return (char *)buf.extractData();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
94 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
95
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
96 Loc::Loc(Module *mod, unsigned linnum)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
97 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
98 this->linnum = linnum;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
99 this->filename = mod ? mod->srcfile->toChars() : NULL;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
100 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
101
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
102 /**************************************
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
103 * Print error message and exit.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
104 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
105
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
106 void error(Loc loc, const char *format, ...)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
107 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
108 va_list ap;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
109 va_start(ap, format);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
110 verror(loc, format, ap);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
111 va_end( ap );
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
112 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
113
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
114 void verror(Loc loc, const char *format, va_list ap)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
115 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
116 if (!global.gag)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
117 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
118 char *p = loc.toChars();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
119
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
120 if (*p)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
121 fprintf(stdmsg, "%s: ", p);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
122 mem.free(p);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
123
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
124 fprintf(stdmsg, "Error: ");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
125 vfprintf(stdmsg, format, ap);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
126 fprintf(stdmsg, "\n");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
127 fflush(stdmsg);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
128 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
129 global.errors++;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
130 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
131
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
132 /***************************************
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
133 * Call this after printing out fatal error messages to clean up and exit
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
134 * the compiler.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
135 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
136
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
137 void fatal()
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
138 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
139 #if 0
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
140 halt();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
141 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
142 exit(EXIT_FAILURE);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
143 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
144
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
145 /**************************************
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
146 * Try to stop forgetting to remove the breakpoints from
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
147 * release builds.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
148 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
149 void halt()
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
150 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
151 #ifdef DEBUG
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
152 *(char*)0=0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
153 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
154 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
155
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
156 extern void backend_init();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
157 extern void backend_term();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
158
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
159 void usage()
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
160 {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 159
diff changeset
161 printf("LLVM D Compiler %s (based on DMD %s and LLVM 2.3)\n%s\n%s\n",
159
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
162 global.llvmdc_version, global.version, global.copyright, global.written);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
163 printf("\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
164 D Language Documentation: http://www.digitalmars.com/d/1.0/index.html\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
165 LLVMDC Homepage: http://www.dsource.org/projects/llvmdc\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
166 Usage:\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
167 dmd files.d ... { -switch }\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
168 \n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
169 files.d D source files\n%s\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
170 -annotate annotate the bitcode with human readable source code\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
171 -c do not link\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
172 -cov do code coverage analysis\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
173 -D generate documentation\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
174 -Dd<docdir> write documentation file to <docdir> directory\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
175 -Df<filename> write documentation file to <filename>\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
176 -d allow deprecated features\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
177 -debug compile in debug code\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
178 -debug=level compile in debug code <= level\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
179 -debug=ident compile in debug code identified by ident\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
180 -debuglib=name set symbolic debug library to name\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
181 -defaultlib=name set default library to name\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
182 -dis disassemble module after compiling\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
183 -g add symbolic debug info\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
184 -gc add symbolic debug info, pretend to be C\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
185 -H generate 'header' file\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
186 -Hd<hdrdir> write 'header' file to <hdrdir> directory\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
187 -Hf<filename> write 'header' file to <filename>\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
188 --help print help\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
189 -I<path> where to look for imports\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
190 -J<path> where to look for string imports\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
191 -ignore ignore unsupported pragmas\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
192 -inline do function inlining\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
193 -Llinkerflag pass linkerflag to link\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
194 -m<arch> emit code specific to <arch>\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
195 x86 x86-64 ppc32 ppc64\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
196 -nofloat do not emit reference to floating point\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
197 -noruntime do not allow code that generates implicit runtime calls\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
198 -noverify do not run the validation pass before writing bitcode\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
199 -O optimize, same as -O2\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
200 -O<n> optimize at level <n> (0-5)\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
201 -o- do not write object file\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
202 -od<objdir> write object files to directory <objdir>\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
203 -of<filename> name output file to <filename>\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
204 -op do not strip paths from source file\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
205 -profile profile runtime performance of generated code\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
206 -quiet suppress unnecessary messages\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
207 -release compile release version\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
208 -run srcfile args... run resulting program, passing args\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
209 -R<path> provide path to the directory containing the runtime library\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
210 -unittest compile in unit tests\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
211 -v verbose\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
212 -vv very verbose (does not include -v)\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
213 -v1 D language version 1\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
214 -version=level compile in version code >= level\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
215 -version=ident compile in version code identified by ident\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
216 -w enable warnings\n\
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
217 ",
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
218 #if WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
219 " @cmdfile read arguments from cmdfile\n"
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
220 #else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
221 ""
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
222 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
223 );
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
224 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
225
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
226 int main(int argc, char *argv[])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
227 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
228 int i;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
229 Array files;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
230 char *p;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
231 Module *m;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
232 int status = EXIT_SUCCESS;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
233 int argcstart = argc;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
234 char* tt_arch = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
235 char* tt_os = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
236 char* data_layout = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
237 bool very_verbose = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
238
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
239 // Check for malformed input
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
240 if (argc < 1 || !argv)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
241 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
242 Largs:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
243 error("missing or null command line arguments");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
244 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
245 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
246 for (i = 0; i < argc; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
247 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
248 if (!argv[i])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
249 goto Largs;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
250 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
251
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
252 #if __DMC__ // DMC unique support for response files
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
253 if (response_expand(&argc,&argv)) // expand response files
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
254 error("can't open response file");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
255 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
256
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
257 files.reserve(argc - 1);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
258
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
259 // Set default values
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
260 global.params.argv0 = argv[0];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
261 global.params.link = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
262 global.params.useAssert = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
263 global.params.useInvariants = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
264 global.params.useIn = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
265 global.params.useOut = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
266 global.params.useArrayBounds = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
267 global.params.useSwitchError = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
268 global.params.useInline = 0; // this one messes things up to a point where codegen breaks
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
269 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
270 global.params.obj = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
271 global.params.Dversion = 2;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
272 global.params.quiet = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
273
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
274 global.params.linkswitches = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
275 global.params.libfiles = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
276 global.params.objfiles = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
277 global.params.ddocfiles = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
278
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
279 global.params.is64bit = sizeof(void*) == 8 ? 1 : 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
280
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
281 uint16_t endiantest = 0xFF00;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
282 uint8_t endianres = ((uint8_t*)&endiantest)[0];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
283 if (endianres == 0x00)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
284 global.params.isLE = true;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
285 else if (endianres == 0xFF)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
286 global.params.isLE = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
287 else {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
288 error("Endian test is broken");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
289 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
290 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
291
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
292 global.params.llvmArch = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
293 global.params.forceBE = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
294 global.params.noruntime = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
295 global.params.novalidate = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
296 global.params.optimizeLevel = -1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
297 global.params.runtimeImppath = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
298
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
299 global.params.defaultlibname = "phobos";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
300 global.params.debuglibname = global.params.defaultlibname;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
301
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
302 // Predefine version identifiers
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
303 #if IN_LLVM
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
304 VersionCondition::addPredefinedGlobalIdent("LLVM");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
305 VersionCondition::addPredefinedGlobalIdent("LLVMDC");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
306 VersionCondition::addPredefinedGlobalIdent("Posix");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
307 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
308 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
309 VersionCondition::addPredefinedGlobalIdent("Windows");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
310 VersionCondition::addPredefinedGlobalIdent("Win32");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
311 global.params.isWindows = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
312 #elif linux
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
313 VersionCondition::addPredefinedGlobalIdent("linux");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
314 global.params.isLinux = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
315 tt_os = "-unknown-linux-gnu";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
316 #else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
317 #error
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
318 #endif /* linux */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
319
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
320 //VersionCondition::addPredefinedGlobalIdent("D_Bits");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
321 //VersionCondition::addPredefinedGlobalIdent("D_InlineAsm");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
322 //VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
323 VersionCondition::addPredefinedGlobalIdent("all");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
324
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
325 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
326 inifile(argv[0], "llvmdc.ini");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
327 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
328 #if linux
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
329 inifile(argv[0], "llvmdc.conf");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
330 #else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
331 #error
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
332 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
333 getenv_setargv("DFLAGS", &argc, &argv);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
334
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
335 #if 0
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
336 for (i = 0; i < argc; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
337 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
338 printf("argv[%d] = '%s'\n", i, argv[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
339 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
340 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
341
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
342 for (i = 1; i < argc; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
343 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
344 p = argv[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
345 if (*p == '-')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
346 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
347 if (strcmp(p + 1, "d") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
348 global.params.useDeprecated = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
349 else if (strcmp(p + 1, "c") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
350 global.params.link = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
351 else if (strcmp(p + 1, "cov") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
352 global.params.cov = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
353 else if (strcmp(p + 1, "fPIC") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
354 global.params.pic = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
355 else if (strcmp(p + 1, "g") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
356 global.params.symdebug = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
357 else if (strcmp(p + 1, "gc") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
358 global.params.symdebug = 2;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
359 else if (strcmp(p + 1, "gt") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
360 { error("use -profile instead of -gt\n");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
361 global.params.trace = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
362 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
363 else if (strcmp(p + 1, "profile") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
364 global.params.trace = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
365 else if (strcmp(p + 1, "v") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
366 global.params.verbose = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
367 else if (strcmp(p + 1, "vv") == 0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
368 Logger::enable();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
369 very_verbose = true;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
370 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
371 else if (strcmp(p + 1, "v1") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
372 global.params.Dversion = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
373 else if (strcmp(p + 1, "w") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
374 global.params.warnings = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
375 else if (p[1] == 'O')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
376 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
377 global.params.optimize = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
378 global.params.optimizeLevel = 2;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
379 if (p[2] != 0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
380 int optlevel = atoi(p+2);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
381 if (optlevel < 0 || optlevel > 5) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
382 error("Optimization level must be between 0 and 5. Using default (%d)",
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
383 global.params.optimizeLevel);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
384 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
385 else {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
386 global.params.optimizeLevel = optlevel;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
387 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
388 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
389 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
390 else if (strcmp(p + 1, "forcebe") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
391 global.params.forceBE = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
392 else if (strcmp(p + 1, "noruntime") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
393 global.params.noruntime = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
394 else if (strcmp(p + 1, "noverify") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
395 global.params.novalidate = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
396 else if (strcmp(p + 1, "dis") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
397 global.params.disassemble = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
398 else if (strcmp(p + 1, "annotate") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
399 global.params.llvmAnnotate = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
400 else if (p[1] == 'o')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
401 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
402 switch (p[2])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
403 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
404 case '-':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
405 global.params.obj = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
406 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
407
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
408 case 'd':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
409 if (!p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
410 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
411 global.params.objdir = p + 3;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
412 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
413
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
414 case 'f':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
415 if (!p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
416 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
417 global.params.objname = p + 3;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
418 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
419
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
420 case 'p':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
421 if (p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
422 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
423 global.params.preservePaths = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
424 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
425
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
426 case 0:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
427 error("-o no longer supported, use -of or -od");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
428 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
429
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
430 default:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
431 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
432 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
433 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
434 else if (p[1] == 'D')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
435 { global.params.doDocComments = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
436 switch (p[2])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
437 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
438 case 'd':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
439 if (!p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
440 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
441 global.params.docdir = p + 3;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
442 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
443 case 'f':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
444 if (!p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
445 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
446 global.params.docname = p + 3;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
447 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
448
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
449 case 0:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
450 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
451
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
452 default:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
453 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
454 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
455 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
456 #ifdef _DH
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
457 else if (p[1] == 'H')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
458 { global.params.doHdrGeneration = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
459 switch (p[2])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
460 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
461 case 'd':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
462 if (!p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
463 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
464 global.params.hdrdir = p + 3;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
465 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
466
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
467 case 'f':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
468 if (!p[3])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
469 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
470 global.params.hdrname = p + 3;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
471 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
472
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
473 case 0:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
474 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
475
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
476 default:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
477 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
478 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
479 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
480 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
481 else if (strcmp(p + 1, "ignore") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
482 global.params.ignoreUnsupportedPragmas = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
483 else if (strcmp(p + 1, "inline") == 0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
484 // TODO
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
485 // the ast rewrites dmd does for inlining messes up the ast.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
486 // someday maybe we can support it, for now llvm does an excellent job at inlining
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
487 global.params.useInline = 0; //1
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
488 global.params.llvmInline = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
489 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
490 else if (strcmp(p + 1, "nofloat") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
491 global.params.nofloat = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
492 else if (strcmp(p + 1, "quiet") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
493 global.params.quiet = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
494 else if (strcmp(p + 1, "release") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
495 global.params.release = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
496 else if (strcmp(p + 1, "unittest") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
497 global.params.useUnitTests = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
498 else if (p[1] == 'I')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
499 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
500 if (!global.params.imppath)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
501 global.params.imppath = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
502 global.params.imppath->push(p + 2);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
503 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
504 else if (p[1] == 'J')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
505 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
506 if (!global.params.fileImppath)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
507 global.params.fileImppath = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
508 global.params.fileImppath->push(p + 2);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
509 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
510 else if (p[1] == 'R')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
511 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
512 global.params.runtimePath = p+2;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
513 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
514 else if (memcmp(p + 1, "debug", 5) == 0 && p[6] != 'l')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
515 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
516 // Parse:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
517 // -debug
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
518 // -debug=number
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
519 // -debug=identifier
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
520 if (p[6] == '=')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
521 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
522 if (isdigit(p[7]))
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
523 { long level;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
524
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
525 errno = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
526 level = strtol(p + 7, &p, 10);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
527 if (*p || errno || level > INT_MAX)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
528 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
529 DebugCondition::setGlobalLevel((int)level);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
530 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
531 else if (Lexer::isValidIdentifier(p + 7))
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
532 DebugCondition::addGlobalIdent(p + 7);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
533 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
534 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
535 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
536 else if (p[6])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
537 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
538 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
539 global.params.debuglevel = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
540 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
541 else if (memcmp(p + 1, "version", 5) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
542 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
543 // Parse:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
544 // -version=number
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
545 // -version=identifier
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
546 if (p[8] == '=')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
547 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
548 if (isdigit(p[9]))
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
549 { long level;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
550
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
551 errno = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
552 level = strtol(p + 9, &p, 10);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
553 if (*p || errno || level > INT_MAX)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
554 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
555 VersionCondition::setGlobalLevel((int)level);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
556 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
557 else if (Lexer::isValidIdentifier(p + 9))
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
558 VersionCondition::addGlobalIdent(p + 9);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
559 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
560 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
561 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
562 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
563 goto Lerror;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
564 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
565 else if (strcmp(p + 1, "-b") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
566 global.params.debugb = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
567 else if (strcmp(p + 1, "-c") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
568 global.params.debugc = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
569 else if (strcmp(p + 1, "-f") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
570 global.params.debugf = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
571 else if (strcmp(p + 1, "-help") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
572 { usage();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
573 exit(EXIT_SUCCESS);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
574 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
575 else if (strcmp(p + 1, "-r") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
576 global.params.debugr = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
577 else if (strcmp(p + 1, "-x") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
578 global.params.debugx = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
579 else if (strcmp(p + 1, "-y") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
580 global.params.debugy = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
581 else if (p[1] == 'L')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
582 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
583 global.params.linkswitches->push(p + 2);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
584 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
585 else if (memcmp(p + 1, "defaultlib=", 11) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
586 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
587 global.params.defaultlibname = p + 1 + 11;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
588 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
589 else if (memcmp(p + 1, "debuglib=", 9) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
590 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
591 global.params.debuglibname = p + 1 + 9;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
592 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
593 else if (strcmp(p + 1, "run") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
594 { global.params.run = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
595 global.params.runargs_length = ((i >= argcstart) ? argc : argcstart) - i - 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
596 if (global.params.runargs_length)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
597 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
598 files.push(argv[i + 1]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
599 global.params.runargs = &argv[i + 2];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
600 i += global.params.runargs_length;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
601 global.params.runargs_length--;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
602 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
603 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
604 { global.params.run = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
605 goto Lnoarg;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
606 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
607 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
608 else if (p[1] == 'm')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
609 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
610 global.params.llvmArch = p+2;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
611 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
612 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
613 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
614 Lerror:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
615 error("unrecognized switch '%s'", argv[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
616 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
617
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
618 Lnoarg:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
619 error("argument expected for switch '%s'", argv[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
620 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
621 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
622 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
623 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
624 files.push(p);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
625 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
626 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
627 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
628 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
629 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
630 if (files.dim == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
631 { usage();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
632 return EXIT_FAILURE;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
633 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
634
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
635 if (global.params.release)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
636 { global.params.useInvariants = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
637 global.params.useIn = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
638 global.params.useOut = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
639 global.params.useAssert = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
640 global.params.useArrayBounds = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
641 global.params.useSwitchError = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
642 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
643
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
644 if (global.params.run)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
645 global.params.quiet = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
646
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
647 if (global.params.useUnitTests)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
648 global.params.useAssert = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
649
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
650 if (!global.params.obj)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
651 global.params.link = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
652
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
653 if (global.params.link)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
654 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
655 global.params.exefile = global.params.objname;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
656 global.params.objname = NULL;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
657 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
658 else if (global.params.run)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
659 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
660 error("flags conflict with -run");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
661 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
662 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
663 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
664 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
665 if (global.params.objname && files.dim > 1)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
666 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
667 error("multiple source files, but only one .obj name");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
668 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
669 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
670 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
671 if (global.params.cov)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
672 VersionCondition::addPredefinedGlobalIdent("D_Coverage");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
673
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
674 bool allowForceEndianness = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
675
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
676 if (global.params.llvmArch == 0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
677 std::string err_str;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
678 const llvm::TargetMachineRegistry::entry* e = llvm::TargetMachineRegistry::getClosestTargetForJIT(err_str);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
679 if (e == 0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
680 error("Failed to find a default target machine: %s", err_str.c_str());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
681 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
682 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
683 else {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
684 global.params.llvmArch = const_cast<char*>(e->Name);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
685 if (global.params.verbose || very_verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
686 printf("Default target found: %s\n", global.params.llvmArch);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
687 if (very_verbose) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
688 int X = sizeof(va_list);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
689 printf("valist.sizeof = %d\n", X);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
690 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
691 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
692 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
693
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
694 if (strcmp(global.params.llvmArch,"x86")==0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
695 VersionCondition::addPredefinedGlobalIdent("X86");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
696 //VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
697 global.params.isLE = true;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
698 global.params.is64bit = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
699 tt_arch = "i686";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
700 data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:8";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
701 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
702 else if (strcmp(global.params.llvmArch,"x86-64")==0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
703 VersionCondition::addPredefinedGlobalIdent("X86_64");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
704 //VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86_64");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
705 global.params.isLE = true;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
706 global.params.is64bit = true;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
707 tt_arch = "x86_64";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
708 data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:8";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
709 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
710 else if (strcmp(global.params.llvmArch,"ppc32")==0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
711 VersionCondition::addPredefinedGlobalIdent("PPC");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
712 global.params.isLE = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
713 global.params.is64bit = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
714 tt_arch = "powerpc";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
715 data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:8";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
716 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
717 else if (strcmp(global.params.llvmArch,"ppc64")==0) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
718 VersionCondition::addPredefinedGlobalIdent("PPC64");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
719 global.params.isLE = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
720 global.params.is64bit = true;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
721 tt_arch = "powerpc64";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
722 data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:8";
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
723 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
724 else {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
725 assert(0 && "Invalid arch");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
726 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
727
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
728 if (allowForceEndianness && global.params.forceBE) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
729 VersionCondition::addPredefinedGlobalIdent("BigEndian");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
730 global.params.isLE = false;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
731 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
732 else if (global.params.isLE) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
733 VersionCondition::addPredefinedGlobalIdent("LittleEndian");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
734 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
735 else {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
736 VersionCondition::addPredefinedGlobalIdent("BigEndian");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
737 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
738
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
739 if (global.params.is64bit) {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
740 VersionCondition::addPredefinedGlobalIdent("LLVM64");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
741 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
742
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
743 assert(tt_arch != 0);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
744 assert(tt_os != 0);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
745 assert(data_layout != 0);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
746 global.params.tt_arch = tt_arch;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
747 global.params.tt_os = tt_os;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
748 global.params.data_layout = data_layout;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
749
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
750 // Initialization
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
751 Type::init();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
752 Id::initialize();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
753 Module::init();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
754 initPrecedence();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
755
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
756 backend_init();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
757
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
758 //printf("%d source files\n",files.dim);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
759
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
760 // Build import search path
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
761 if (global.params.imppath)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
762 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
763 for (i = 0; i < global.params.imppath->dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
764 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
765 char *path = (char *)global.params.imppath->data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
766 Array *a = FileName::splitPath(path);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
767
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
768 if (a)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
769 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
770 if (!global.path)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
771 global.path = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
772 global.path->append(a);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
773 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
774 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
775 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
776
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
777 // Build string import search path
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
778 if (global.params.fileImppath)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
779 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
780 for (i = 0; i < global.params.fileImppath->dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
781 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
782 char *path = (char *)global.params.fileImppath->data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
783 Array *a = FileName::splitPath(path);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
784
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
785 if (a)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
786 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
787 if (!global.filePath)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
788 global.filePath = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
789 global.filePath->append(a);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
790 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
791 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
792 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
793
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
794 // Create Modules
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
795 Array modules;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
796 modules.reserve(files.dim);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
797 for (i = 0; i < files.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
798 { Identifier *id;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
799 char *ext;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
800 char *name;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
801
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
802 p = (char *) files.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
803
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
804 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
805 // Convert / to \ so linker will work
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
806 for (int i = 0; p[i]; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
807 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
808 if (p[i] == '/')
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
809 p[i] = '\\';
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
810 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
811 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
812
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
813 p = FileName::name(p); // strip path
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
814 ext = FileName::ext(p);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
815 if (ext)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
816 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
817 #if IN_LLVM
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
818 if (strcmp(ext, global.nativeobj_ext) == 0 ||
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
819 strcmp(ext, global.obj_ext) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
820 #elif TARGET_LINUX
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
821 if (strcmp(ext, global.obj_ext) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
822 #else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
823 if (stricmp(ext, global.obj_ext) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
824 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
825 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
826 global.params.objfiles->push(files.data[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
827 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
828 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
829
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
830 #if TARGET_LINUX
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
831 if (strcmp(ext, "a") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
832 #else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
833 if (stricmp(ext, "lib") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
834 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
835 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
836 global.params.libfiles->push(files.data[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
837 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
838 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
839
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
840 if (strcmp(ext, global.ddoc_ext) == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
841 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
842 global.params.ddocfiles->push(files.data[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
843 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
844 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
845
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
846 #if !TARGET_LINUX
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
847 if (stricmp(ext, "res") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
848 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
849 global.params.resfile = (char *)files.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
850 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
851 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
852
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
853 if (stricmp(ext, "def") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
854 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
855 global.params.deffile = (char *)files.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
856 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
857 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
858
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
859 if (stricmp(ext, "exe") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
860 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
861 global.params.exefile = (char *)files.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
862 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
863 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
864 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
865
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
866 if (stricmp(ext, global.mars_ext) == 0 ||
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
867 stricmp(ext, "htm") == 0 ||
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
868 stricmp(ext, "html") == 0 ||
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
869 stricmp(ext, "xhtml") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
870 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
871 ext--; // skip onto '.'
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
872 assert(*ext == '.');
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
873 name = (char *)mem.malloc((ext - p) + 1);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
874 memcpy(name, p, ext - p);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
875 name[ext - p] = 0; // strip extension
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
876
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
877 if (name[0] == 0 ||
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
878 strcmp(name, "..") == 0 ||
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
879 strcmp(name, ".") == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
880 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
881 Linvalid:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
882 error("invalid file name '%s'", (char *)files.data[i]);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
883 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
884 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
885 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
886 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
887 { error("unrecognized file extension %s\n", ext);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
888 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
889 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
890 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
891 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
892 { name = p;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
893 if (!*name)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
894 goto Linvalid;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
895 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
896
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
897 id = new Identifier(name, 0);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
898 m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
899 modules.push(m);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
900
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
901 global.params.objfiles->push(m->objfile->name->str);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
902 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
903
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
904 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
905 __try
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
906 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
907 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
908 // Read files, parse them
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
909 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
910 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
911 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
912 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
913 printf("parse %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
914 if (!Module::rootModule)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
915 Module::rootModule = m;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
916 m->importedFrom = m;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
917 m->deleteObjFile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
918 m->read(0);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
919 m->parse();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
920 if (m->isDocFile)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
921 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
922 m->gendocfile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
923
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
924 // Remove m from list of modules
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
925 modules.remove(i);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
926 i--;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
927
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
928 // Remove m's object file from list of object files
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
929 for (int j = 0; j < global.params.objfiles->dim; j++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
930 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
931 if (m->objfile->name->str == global.params.objfiles->data[j])
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
932 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
933 global.params.objfiles->remove(j);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
934 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
935 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
936 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
937
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
938 if (global.params.objfiles->dim == 0)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
939 global.params.link = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
940 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
941 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
942 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
943 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
944 #ifdef _DH
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
945 if (global.params.doHdrGeneration)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
946 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
947 /* Generate 'header' import files.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
948 * Since 'header' import files must be independent of command
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
949 * line switches and what else is imported, they are generated
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
950 * before any semantic analysis.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
951 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
952 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
953 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
954 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
955 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
956 printf("import %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
957 m->genhdrfile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
958 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
959 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
960 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
961 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
962 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
963
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
964 // Do semantic analysis
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
965 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
966 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
967 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
968 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
969 printf("semantic %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
970 m->semantic();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
971 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
972 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
973 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
974
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
975 // Do pass 2 semantic analysis
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
976 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
977 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
978 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
979 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
980 printf("semantic2 %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
981 m->semantic2();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
982 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
983 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
984 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
985
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
986 // Do pass 3 semantic analysis
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
987 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
988 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
989 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
990 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
991 printf("semantic3 %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
992 m->semantic3();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
993 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
994 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
995 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
996
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
997 #if !IN_LLVM
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
998 // Scan for functions to inline
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
999 if (global.params.useInline)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1000 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1001 /* The problem with useArrayBounds and useAssert is that the
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1002 * module being linked to may not have generated them, so if
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1003 * we inline functions from those modules, the symbols for them will
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1004 * not be found at link time.
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1005 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1006 if (!global.params.useArrayBounds && !global.params.useAssert)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1007 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1008 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1009 // Do pass 3 semantic analysis on all imported modules,
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1010 // since otherwise functions in them cannot be inlined
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1011 for (i = 0; i < Module::amodules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1012 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1013 m = (Module *)Module::amodules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1014 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1015 printf("semantic3 %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1016 m->semantic3();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1017 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1018 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1019 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1020 #if !IN_LLVM
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1021 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1022
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1023 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1024 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1025 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1026 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1027 printf("inline scan %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1028 m->inlineScan();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1029 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1030 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1031 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1032 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1033 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1034
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1035 // Generate output files
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1036 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1037 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1038 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1039 if (global.params.verbose)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1040 printf("code %s\n", m->toChars());
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1041 if (global.params.obj)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1042 m->genobjfile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1043 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1044 m->deleteObjFile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1045 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1046 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1047 if (global.params.doDocComments)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1048 m->gendocfile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1049 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1050 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1051 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1052 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1053 __except (__ehfilter(GetExceptionInformation()))
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1054 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1055 printf("Stack overflow\n");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1056 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1057 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1058 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1059 backend_term();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1060 if (global.errors)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1061 fatal();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1062
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1063 if (!global.params.objfiles->dim)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1064 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1065 if (global.params.link)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1066 error("no object files to link");
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1067 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1068 else
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1069 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1070 if (global.params.link)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1071 status = runLINK();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1072
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1073 if (global.params.run)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1074 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1075 if (!status)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1076 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1077 status = runProgram();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1078
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1079 /* Delete .obj files and .exe file
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1080 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1081 for (i = 0; i < modules.dim; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1082 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1083 m = (Module *)modules.data[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1084 m->deleteObjFile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1085 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1086 deleteExeFile();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1087 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1088 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1089 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1090
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1091 return status;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1092 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1093
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1094
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1095
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1096 /***********************************
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1097 * Parse and append contents of environment variable envvar
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1098 * to argc and argv[].
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1099 * The string is separated into arguments, processing \ and ".
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1100 */
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1101
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1102 void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1103 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1104 char *env;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1105 char *p;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1106 Array *argv;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1107 int argc;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1108
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1109 int wildcard; // do wildcard expansion
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1110 int instring;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1111 int slash;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1112 char c;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1113 int j;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1114
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1115 env = getenv(envvar);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1116 if (!env)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1117 return;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1118
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1119 env = mem.strdup(env); // create our own writable copy
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1120
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1121 argc = *pargc;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1122 argv = new Array();
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1123 argv->setDim(argc);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1124
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1125 for (int i = 0; i < argc; i++)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1126 argv->data[i] = (void *)(*pargv)[i];
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1127
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1128 j = 1; // leave argv[0] alone
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1129 while (1)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1130 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1131 wildcard = 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1132 switch (*env)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1133 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1134 case ' ':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1135 case '\t':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1136 env++;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1137 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1138
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1139 case 0:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1140 goto Ldone;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1141
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1142 case '"':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1143 wildcard = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1144 default:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1145 argv->push(env); // append
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1146 //argv->insert(j, env); // insert at position j
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1147 j++;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1148 argc++;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1149 p = env;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1150 slash = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1151 instring = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1152 c = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1153
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1154 while (1)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1155 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1156 c = *env++;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1157 switch (c)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1158 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1159 case '"':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1160 p -= (slash >> 1);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1161 if (slash & 1)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1162 { p--;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1163 goto Laddc;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1164 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1165 instring ^= 1;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1166 slash = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1167 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1168
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1169 case ' ':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1170 case '\t':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1171 if (instring)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1172 goto Laddc;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1173 *p = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1174 //if (wildcard)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1175 //wildcardexpand(); // not implemented
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1176 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1177
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1178 case '\\':
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1179 slash++;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1180 *p++ = c;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1181 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1182
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1183 case 0:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1184 *p = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1185 //if (wildcard)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1186 //wildcardexpand(); // not implemented
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1187 goto Ldone;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1188
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1189 default:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1190 Laddc:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1191 slash = 0;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1192 *p++ = c;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1193 continue;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1194 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1195 break;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1196 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1197 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1198 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1199
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1200 Ldone:
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1201 *pargc = argc;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1202 *pargv = (char **)argv->data;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1203 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1204
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1205 #if _WIN32
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1206
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1207 long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1208 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1209 //printf("%x\n", ep->ExceptionRecord->ExceptionCode);
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1210 if (ep->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW)
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1211 {
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1212 #ifndef DEBUG
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1213 return EXCEPTION_EXECUTE_HANDLER;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1214 #endif
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1215 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1216 return EXCEPTION_CONTINUE_SEARCH;
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1217 }
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1218
5acec6b2eef8 [svn r175] merged dmd 1.029
ChristianK
parents: 151
diff changeset
1219 #endif