Mercurial > projects > ldc
annotate dmd/mars.c @ 986:a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Note: For a backward compatible interface, use the new bin/ldmd script. It
supports all old options while passing on anything it doesn't recognize.
Some changes caused by this:
* -debug and -version are now -d-debug and -d-version due to a conflict with
standard LLVM options.
* All "flag" options now allow an optional =true/=1/=false/=0 suffix.
* Some "hidden debug switches" starting with "--" were renamed because LLVM
doesn't care about the number of dashes, so they were conflicting with other
options (such as -c).
The new versions start with "-hidden-debug-" instead of "--"
* --help works, but has a non-zero exit code. This breaks some Tango scripts
which use it to test for compiler existence. See tango.patch.
Some changes not (directly) caused by this;
* (-enable/-disable)-FOO options are now available for pre- and postconditions.
* -march is used instead of -m (like other LLVM programs), but -m is an alias
for it.
* -defaultlib, -debuglib, -d-debug and -d-version allow comma-separated values.
The effect should be identical to specifying the same option multiple times.
I decided against allowing these for some other options because paths might
contain commas on some systems.
* -fPIC is removed in favor of the standard LLVM option -relocation-model=pic
Bug:
* If -run is specified as the last argument in DFLAGS, no error is generated.
(Not very serious IMHO)
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Wed, 25 Feb 2009 17:34:51 +0100 |
parents | 0b38b64f62c7 |
children | 2667e3a145be |
rev | line source |
---|---|
159 | 1 // Compiler implementation of the D programming language |
876
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
2 // Copyright (c) 1999-2009 by Digital Mars |
159 | 3 // All Rights Reserved |
4 // written by Walter Bright | |
5 // http://www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <ctype.h> | |
13 #include <assert.h> | |
14 #include <limits.h> | |
15 #include <string> | |
16 #include <cstdarg> | |
17 | |
18 #if __DMC__ | |
19 #include <dos.h> | |
20 #endif | |
21 | |
571
cbd6c8073a32
Changed all '#if linux || __APPLE__' to '#if POSIX' so we can support other platforms too, thanx for the suggestion anders.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
568
diff
changeset
|
22 #if POSIX |
159 | 23 #include <errno.h> |
432 | 24 #elif _WIN32 |
25 #include <windows.h> | |
159 | 26 #endif |
27 | |
28 #include "mem.h" | |
29 #include "root.h" | |
30 | |
31 #include "mars.h" | |
32 #include "module.h" | |
33 #include "mtype.h" | |
34 #include "id.h" | |
35 #include "cond.h" | |
36 #include "expression.h" | |
37 #include "lexer.h" | |
38 | |
39 #include "gen/logger.h" | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
40 #include "gen/linker.h" |
853
82ad6c0c601c
Add Elrood's patch to output LDC and LLVM source revs.
Christian Kamm <kamm incasoftware de>
parents:
849
diff
changeset
|
41 #include "revisions.h" |
788
dce4b4ea2aee
Print llvm package string in version header. See #128.
Christian Kamm <kamm incasoftware de>
parents:
785
diff
changeset
|
42 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
43 #include "gen/cl_options.h" |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
44 #include "gen/cl_helpers.h" |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
45 using namespace opts; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
46 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
47 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
48 static cl::opt<bool> forceBE("forcebe", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
49 cl::desc("Force big-endian"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
50 cl::Hidden, |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
51 cl::ZeroOrMore); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
52 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
53 static cl::opt<bool> noDefaultLib("nodefaultlib", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
54 cl::desc("Don't add a default library for linking implicitly"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
55 cl::ZeroOrMore); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
56 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
57 static ArrayAdapter impPathsStore("I", global.params.imppath); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
58 static cl::list<std::string, ArrayAdapter> importPaths("I", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
59 cl::desc("Where to look for imports"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
60 cl::value_desc("path"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
61 cl::location(impPathsStore), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
62 cl::Prefix); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
63 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
64 static ArrayAdapter defaultLibStore("defaultlib", global.params.defaultlibnames); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
65 static cl::list<std::string, ArrayAdapter> defaultlibs("defaultlib", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
66 cl::desc("Set default libraries for non-debug build"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
67 cl::value_desc("lib,..."), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
68 cl::location(defaultLibStore), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
69 cl::CommaSeparated); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
70 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
71 static ArrayAdapter debugLibStore("debuglib", global.params.debuglibnames); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
72 static cl::list<std::string, ArrayAdapter> debuglibs("debuglib", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
73 cl::desc("Set default libraries for debug build"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
74 cl::value_desc("lib,..."), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
75 cl::location(debugLibStore), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
76 cl::CommaSeparated); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
77 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
78 |
159 | 79 void getenv_setargv(const char *envvar, int *pargc, char** *pargv); |
80 | |
81 Global global; | |
82 | |
83 Global::Global() | |
84 { | |
85 mars_ext = "d"; | |
86 sym_ext = "d"; | |
87 hdr_ext = "di"; | |
88 doc_ext = "html"; | |
89 ddoc_ext = "ddoc"; | |
90 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
91 // LDC |
159 | 92 ll_ext = "ll"; |
93 bc_ext = "bc"; | |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
94 s_ext = "s"; |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
95 obj_ext = "o"; |
374
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
96 #if _WIN32 |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
97 obj_ext_alt = "obj"; |
159 | 98 #endif |
99 | |
876
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
100 copyright = "Copyright (c) 1999-2009 by Digital Mars and Tomas Lindquist Olsen"; |
159 | 101 written = "written by Walter Bright and Tomas Lindquist Olsen"; |
876
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
102 version = "v1.039"; |
853
82ad6c0c601c
Add Elrood's patch to output LDC and LLVM source revs.
Christian Kamm <kamm incasoftware de>
parents:
849
diff
changeset
|
103 ldc_version = LDC_REV; |
82ad6c0c601c
Add Elrood's patch to output LDC and LLVM source revs.
Christian Kamm <kamm incasoftware de>
parents:
849
diff
changeset
|
104 llvm_version = LLVM_REV; |
159 | 105 global.structalign = 8; |
106 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
107 // This should only be used as a global, so the other fields are |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
108 // automatically initialized to zero when the program is loaded. |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
109 // In particular, DO NOT zero-initialize .params here (like DMD |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
110 // does) because command-line options initialize some of those |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
111 // fields to non-zero defaults, and do so from constructors that |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
112 // may run before this one. |
159 | 113 } |
114 | |
115 char *Loc::toChars() const | |
116 { | |
117 OutBuffer buf; | |
118 | |
119 if (filename) | |
120 { | |
121 buf.printf("%s", filename); | |
122 } | |
123 | |
124 if (linnum) | |
125 buf.printf("(%d)", linnum); | |
126 buf.writeByte(0); | |
127 return (char *)buf.extractData(); | |
128 } | |
129 | |
130 Loc::Loc(Module *mod, unsigned linnum) | |
131 { | |
132 this->linnum = linnum; | |
133 this->filename = mod ? mod->srcfile->toChars() : NULL; | |
134 } | |
135 | |
136 /************************************** | |
137 * Print error message and exit. | |
138 */ | |
139 | |
140 void error(Loc loc, const char *format, ...) | |
141 { | |
142 va_list ap; | |
143 va_start(ap, format); | |
144 verror(loc, format, ap); | |
145 va_end( ap ); | |
146 } | |
147 | |
148 void verror(Loc loc, const char *format, va_list ap) | |
149 { | |
150 if (!global.gag) | |
151 { | |
152 char *p = loc.toChars(); | |
153 | |
154 if (*p) | |
155 fprintf(stdmsg, "%s: ", p); | |
156 mem.free(p); | |
157 | |
158 fprintf(stdmsg, "Error: "); | |
159 vfprintf(stdmsg, format, ap); | |
160 fprintf(stdmsg, "\n"); | |
161 fflush(stdmsg); | |
162 } | |
163 global.errors++; | |
164 } | |
165 | |
166 /*************************************** | |
167 * Call this after printing out fatal error messages to clean up and exit | |
168 * the compiler. | |
169 */ | |
170 | |
171 void fatal() | |
172 { | |
173 #if 0 | |
174 halt(); | |
175 #endif | |
176 exit(EXIT_FAILURE); | |
177 } | |
178 | |
179 /************************************** | |
180 * Try to stop forgetting to remove the breakpoints from | |
181 * release builds. | |
182 */ | |
183 void halt() | |
184 { | |
185 #ifdef DEBUG | |
186 *(char*)0=0; | |
187 #endif | |
188 } | |
189 | |
190 extern void backend_init(); | |
191 extern void backend_term(); | |
192 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
193 void printVersion() { |
853
82ad6c0c601c
Add Elrood's patch to output LDC and LLVM source revs.
Christian Kamm <kamm incasoftware de>
parents:
849
diff
changeset
|
194 printf("LLVM D Compiler %s\nbased on DMD %s and %s\n%s\n%s\n", |
82ad6c0c601c
Add Elrood's patch to output LDC and LLVM source revs.
Christian Kamm <kamm incasoftware de>
parents:
849
diff
changeset
|
195 global.ldc_version, global.version, global.llvm_version, global.copyright, global.written); |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
196 printf("D Language Documentation: http://www.digitalmars.com/d/1.0/index.html\n" |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
197 "LDC Homepage: http://www.dsource.org/projects/ldc\n"); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
198 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
199 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
200 // Helper function to handle -d-debug=* and -d-version=* |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
201 static void processVersions(std::vector<std::string>& list, char* type, |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
202 void (*setLevel)(unsigned), void (*addIdent)(char*)) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
203 typedef std::vector<std::string>::iterator It; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
204 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
205 for(It I = list.begin(), E = list.end(); I != E; ++I) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
206 const char* value = I->c_str(); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
207 if (isdigit(value[0])) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
208 errno = 0; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
209 char* end; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
210 long level = strtol(value, &end, 10); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
211 if (*end || errno || level > INT_MAX) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
212 error("Invalid %s level: %s", type, I->c_str()); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
213 } else { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
214 setLevel((unsigned)level); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
215 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
216 } else { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
217 char* cstr = mem.strdup(value); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
218 if (Lexer::isValidIdentifier(cstr)) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
219 addIdent(cstr); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
220 continue; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
221 } else { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
222 error("Invalid %s identifier or level: '%s'", type, I->c_str()); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
223 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
224 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
225 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
226 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
227 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
228 // Helper function to handle -of, -od, etc. |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
229 static void initFromString(char*& dest, const cl::opt<std::string>& src) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
230 dest = 0; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
231 if (src.getNumOccurrences() != 0) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
232 if (src.empty()) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
233 error("Expected argument to '-%s'", src.ArgStr); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
234 dest = mem.strdup(src.c_str()); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
235 } |
159 | 236 } |
237 | |
849
ba390e5e9150
Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
238 int main(int argc, char *argv[]) |
159 | 239 { |
240 int i; | |
241 Array files; | |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
242 char *p, *ext; |
159 | 243 Module *m; |
244 int status = EXIT_SUCCESS; | |
245 | |
246 // Set default values | |
432 | 247 #if _WIN32 |
248 char buf[MAX_PATH]; | |
249 GetModuleFileName(NULL, buf, MAX_PATH); | |
250 global.params.argv0 = buf; | |
251 #else | |
159 | 252 global.params.argv0 = argv[0]; |
432 | 253 #endif |
331
04e1b4930975
[svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents:
327
diff
changeset
|
254 global.params.useSwitchError = 1; |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
255 |
159 | 256 global.params.linkswitches = new Array(); |
257 global.params.libfiles = new Array(); | |
258 global.params.objfiles = new Array(); | |
259 global.params.ddocfiles = new Array(); | |
260 | |
261 global.params.is64bit = sizeof(void*) == 8 ? 1 : 0; | |
262 | |
263 uint16_t endiantest = 0xFF00; | |
264 uint8_t endianres = ((uint8_t*)&endiantest)[0]; | |
265 if (endianres == 0x00) | |
266 global.params.isLE = true; | |
267 else if (endianres == 0xFF) | |
268 global.params.isLE = false; | |
269 else { | |
270 error("Endian test is broken"); | |
271 fatal(); | |
272 } | |
273 | |
274 // Predefine version identifiers | |
275 #if IN_LLVM | |
276 VersionCondition::addPredefinedGlobalIdent("LLVM"); | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
277 VersionCondition::addPredefinedGlobalIdent("LDC"); |
159 | 278 #endif |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
484
diff
changeset
|
279 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
280 // setup default target os to be build os |
159 | 281 #if _WIN32 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
282 global.params.os = OSWindows; |
159 | 283 #elif linux |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
284 global.params.os = OSLinux; |
541
4b7925bc1605
Fixed some osx mistakes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
536
diff
changeset
|
285 #elif __APPLE__ |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
286 global.params.os = OSMacOSX; |
637
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
287 #elif __FreeBSD__ |
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
288 global.params.os = OSFreeBSD; |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
853
diff
changeset
|
289 #elif defined (__SVR4) && defined (__sun) |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
853
diff
changeset
|
290 global.params.os = OSSolaris; |
159 | 291 #else |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
853
diff
changeset
|
292 #error Unsupported OS |
159 | 293 #endif /* linux */ |
294 | |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
295 assert(global.params.os != OSinvalid); |
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
296 |
159 | 297 //VersionCondition::addPredefinedGlobalIdent("D_Bits"); |
298 VersionCondition::addPredefinedGlobalIdent("all"); | |
299 | |
785
ac39e5449ca5
Apply Elrood's CMake changes from #124. Thanks a lot!
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
300 //#if _WIN32 |
ac39e5449ca5
Apply Elrood's CMake changes from #124. Thanks a lot!
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
301 // inifile(global.params.argv0, "ldc.ini"); |
ac39e5449ca5
Apply Elrood's CMake changes from #124. Thanks a lot!
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
302 //#elif POSIX |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
303 inifile(global.params.argv0, "ldc.conf"); |
785
ac39e5449ca5
Apply Elrood's CMake changes from #124. Thanks a lot!
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
304 //#else |
ac39e5449ca5
Apply Elrood's CMake changes from #124. Thanks a lot!
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
305 //#error |
ac39e5449ca5
Apply Elrood's CMake changes from #124. Thanks a lot!
Christian Kamm <kamm incasoftware de>
parents:
741
diff
changeset
|
306 //#endif |
159 | 307 getenv_setargv("DFLAGS", &argc, &argv); |
308 | |
309 #if 0 | |
310 for (i = 0; i < argc; i++) | |
311 { | |
312 printf("argv[%d] = '%s'\n", i, argv[i]); | |
313 } | |
314 #endif | |
315 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
316 cl::SetVersionPrinter(&printVersion); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
317 cl::ParseCommandLineOptions(argc, argv, "LLVM-based D Compiler\n"); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
318 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
319 global.params.optimize = (global.params.optimizeLevel >= 0); |
159 | 320 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
321 // Negated options |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
322 global.params.link = !compileOnly; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
323 global.params.obj = !dontWriteObj; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
324 global.params.useInlineAsm = !noAsm; |
159 | 325 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
326 // String options: std::string --> char* |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
327 initFromString(global.params.objname, objectFile); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
328 initFromString(global.params.objdir, objectDir); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
329 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
330 initFromString(global.params.docdir, ddocDir); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
331 initFromString(global.params.docname, ddocFile); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
332 global.params.doDocComments |= |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
333 global.params.docdir || global.params.docname; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
334 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
335 #ifdef _DH |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
336 initFromString(global.params.hdrdir, hdrDir); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
337 initFromString(global.params.hdrname, hdrFile); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
338 global.params.doHdrGeneration |= |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
339 global.params.hdrdir || global.params.hdrname; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
340 #endif |
159 | 341 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
342 processVersions(debugArgs, "debug", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
343 DebugCondition::setGlobalLevel, |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
344 DebugCondition::addGlobalIdent); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
345 processVersions(versions, "version", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
346 VersionCondition::setGlobalLevel, |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
347 VersionCondition::addGlobalIdent); |
159 | 348 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
349 global.params.output_o = |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
350 opts::output_o == cl::BOU_UNSET |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
351 ? OUTPUTFLAGdefault |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
352 : opts::output_o == cl::BOU_TRUE |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
353 ? OUTPUTFLAGset |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
354 : OUTPUTFLAGno; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
355 global.params.output_bc = opts::output_bc ? OUTPUTFLAGset : OUTPUTFLAGno; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
356 global.params.output_ll = opts::output_ll ? OUTPUTFLAGset : OUTPUTFLAGno; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
357 global.params.output_s = opts::output_s ? OUTPUTFLAGset : OUTPUTFLAGno; |
159 | 358 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
359 if (global.params.run || !runargs.empty()) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
360 // FIXME: how to properly detect the presence of a PositionalEatsArgs |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
361 // option without parameters? We want to emit an error in that case... |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
362 // You'd think getNumOccurrences would do it, but it just returns the |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
363 // number of parameters) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
364 // NOTE: Hacked around it by detecting -run in getenv_setargv(), where |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
365 // we're looking for it anyway, and pre-setting the flag... |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
366 global.params.run = true; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
367 if (!runargs.empty()) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
368 files.push(mem.strdup(runargs[0].c_str())); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
369 } else { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
370 global.params.run = false; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
371 error("Expected at least one argument to '-run'\n"); |
159 | 372 } |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
373 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
374 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
375 if (mArch) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
376 global.params.llvmArch = mArch->Name; |
159 | 377 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
378 files.reserve(fileList.size()); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
379 typedef std::vector<std::string>::iterator It; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
380 for(It I = fileList.begin(), E = fileList.end(); I != E; ++I) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
381 if (!I->empty()) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
382 files.push(mem.strdup(I->c_str())); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
383 |
159 | 384 if (global.errors) |
385 { | |
386 fatal(); | |
387 } | |
388 if (files.dim == 0) | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
389 { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
390 cl::PrintHelpMessage(); |
159 | 391 return EXIT_FAILURE; |
392 } | |
393 | |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
394 Array* libs; |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
395 if (global.params.symdebug) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
396 libs = global.params.debuglibnames; |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
397 else |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
398 libs = global.params.defaultlibnames; |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
399 |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
400 if (libs) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
401 { |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
402 for (int i = 0; i < libs->dim; i++) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
403 { |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
404 char *arg = (char *)mem.malloc(64); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
405 strcpy(arg, "-l"); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
406 strncat(arg, (char *)libs->data[i], 64); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
407 global.params.linkswitches->push(arg); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
408 } |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
409 } |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
410 else if (!noDefaultLib) |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
411 { |
569
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
412 char *arg; |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
413 arg = (char *)mem.malloc(64); |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
414 strcpy(arg, "-lldc-runtime"); |
569
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
415 global.params.linkswitches->push(arg); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
416 arg = (char *)mem.malloc(64); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
417 strcpy(arg, "-ltango-cc-tango"); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
418 global.params.linkswitches->push(arg); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
419 arg = (char *)mem.malloc(64); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
420 strcpy(arg, "-ltango-gc-basic"); |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
421 global.params.linkswitches->push(arg); |
679
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
422 // pass the runtime again to resolve issues |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
423 // with linking order |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
424 arg = (char *)mem.malloc(64); |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
425 strcpy(arg, "-lldc-runtime"); |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
426 global.params.linkswitches->push(arg); |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
427 } |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
428 |
159 | 429 if (global.params.run) |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
430 quiet = 1; |
159 | 431 |
432 if (global.params.useUnitTests) | |
433 global.params.useAssert = 1; | |
434 | |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
435 // LDC output determination |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
436 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
437 // if we don't link, autodetect target from extension |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
438 if(!global.params.link && global.params.objname) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
439 ext = FileName::ext(global.params.objname); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
440 bool autofound = false; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
441 if (!ext) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
442 // keep things as they are |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
443 } else if (strcmp(ext, global.ll_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
444 global.params.output_ll = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
445 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
446 } else if (strcmp(ext, global.bc_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
447 global.params.output_bc = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
448 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
449 } else if (strcmp(ext, global.s_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
450 global.params.output_s = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
451 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
452 } else if (strcmp(ext, global.obj_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
453 global.params.output_o = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
454 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
455 } else { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
456 // append dot, so forceExt won't change existing name even if it contains dots |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
457 size_t len = strlen(global.params.objname); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
458 size_t extlen = strlen("."); |
713
b3dc22526289
Use malloc instead of alloca.
Christian Kamm <kamm incasoftware de>
parents:
712
diff
changeset
|
459 char* s = (char *)mem.malloc(len + 1 + extlen + 1); |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
460 memcpy(s, global.params.objname, len); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
461 s[len] = '.'; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
462 s[len+1+extlen] = 0; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
463 global.params.objname = s; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
464 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
465 } |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
466 if(autofound && global.params.output_o == OUTPUTFLAGdefault) |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
467 global.params.output_o = OUTPUTFLAGno; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
468 } |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
469 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
470 // only link if possible |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
471 if (!global.params.obj || !global.params.output_o) |
159 | 472 global.params.link = 0; |
473 | |
474 if (global.params.link) | |
475 { | |
476 global.params.exefile = global.params.objname; | |
712
8c0d3ec8dbbb
Fix -of with multiple input files.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
477 if (files.dim > 1) |
8c0d3ec8dbbb
Fix -of with multiple input files.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
478 global.params.objname = NULL; |
159 | 479 } |
480 else if (global.params.run) | |
481 { | |
482 error("flags conflict with -run"); | |
483 fatal(); | |
484 } | |
485 else | |
486 { | |
487 if (global.params.objname && files.dim > 1) | |
488 { | |
489 error("multiple source files, but only one .obj name"); | |
490 fatal(); | |
491 } | |
492 } | |
493 | |
494 bool allowForceEndianness = false; | |
495 | |
496 if (global.params.llvmArch == 0) { | |
583
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
497 #if defined(__x86_64__) || defined(_M_X64) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
498 global.params.llvmArch = "x86-64"; |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
499 #elif defined(__i386__) || defined(_M_IX86) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
500 global.params.llvmArch = "x86"; |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
501 #elif defined(__ppc__) || defined(_M_PPC) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
502 if (global.params.is64bit) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
503 global.params.llvmArch = "ppc64"; |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
504 else |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
505 global.params.llvmArch = "ppc32"; |
734
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
506 #elif defined(__arm__) |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
507 global.params.llvmArch = "arm"; |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
508 #elif defined(__thumb__) |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
509 global.params.llvmArch = "thumb"; |
583
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
510 #else |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
511 #error |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
512 #endif |
159 | 513 } |
514 | |
515 if (strcmp(global.params.llvmArch,"x86")==0) { | |
516 VersionCondition::addPredefinedGlobalIdent("X86"); | |
517 global.params.isLE = true; | |
518 global.params.is64bit = false; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
519 global.params.cpu = ARCHx86; |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
520 if (global.params.useInlineAsm) { |
942
55559220ad72
Reverted back to the LLVM_InlineAsm_X86 versions, a few more things still needs to be sorted out first.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
941
diff
changeset
|
521 VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86"); |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
522 } |
159 | 523 } |
524 else if (strcmp(global.params.llvmArch,"x86-64")==0) { | |
525 VersionCondition::addPredefinedGlobalIdent("X86_64"); | |
526 global.params.isLE = true; | |
527 global.params.is64bit = true; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
528 global.params.cpu = ARCHx86_64; |
741
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
735
diff
changeset
|
529 if (global.params.useInlineAsm) { |
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
735
diff
changeset
|
530 VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86_64"); |
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
735
diff
changeset
|
531 } |
159 | 532 } |
533 else if (strcmp(global.params.llvmArch,"ppc32")==0) { | |
534 VersionCondition::addPredefinedGlobalIdent("PPC"); | |
535 global.params.isLE = false; | |
536 global.params.is64bit = false; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
537 global.params.cpu = ARCHppc; |
159 | 538 } |
539 else if (strcmp(global.params.llvmArch,"ppc64")==0) { | |
540 VersionCondition::addPredefinedGlobalIdent("PPC64"); | |
541 global.params.isLE = false; | |
542 global.params.is64bit = true; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
543 global.params.cpu = ARCHppc_64; |
159 | 544 } |
734
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
545 else if (strcmp(global.params.llvmArch,"arm")==0) { |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
546 VersionCondition::addPredefinedGlobalIdent("ARM"); |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
547 global.params.isLE = true; |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
548 global.params.is64bit = false; |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
549 global.params.cpu = ARCHarm; |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
550 } |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
551 else if (strcmp(global.params.llvmArch,"thumb")==0) { |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
552 VersionCondition::addPredefinedGlobalIdent("Thumb"); |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
553 global.params.isLE = true; |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
554 global.params.is64bit = false; |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
555 global.params.cpu = ARCHthumb; |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
556 } |
159 | 557 else { |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
917
diff
changeset
|
558 error("invalid cpu architecture specified: %s", global.params.llvmArch); |
159 | 559 } |
560 | |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
561 assert(global.params.cpu != ARCHinvalid); |
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
562 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
563 if (allowForceEndianness && forceBE) { |
159 | 564 VersionCondition::addPredefinedGlobalIdent("BigEndian"); |
565 global.params.isLE = false; | |
566 } | |
567 else if (global.params.isLE) { | |
568 VersionCondition::addPredefinedGlobalIdent("LittleEndian"); | |
569 } | |
570 else { | |
571 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
572 } | |
573 | |
574 if (global.params.is64bit) { | |
575 VersionCondition::addPredefinedGlobalIdent("LLVM64"); | |
576 } | |
577 | |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
578 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
579 // setup version idents and tt_os for chosen target os |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
580 switch(global.params.os) |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
581 { |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
582 case OSWindows: |
876
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
583 // TODO Win64 stuff! |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
584 VersionCondition::addPredefinedGlobalIdent("Windows"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
585 VersionCondition::addPredefinedGlobalIdent("Win32"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
586 VersionCondition::addPredefinedGlobalIdent("mingw32"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
587 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
588 |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
589 case OSLinux: |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
590 VersionCondition::addPredefinedGlobalIdent("linux"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
591 VersionCondition::addPredefinedGlobalIdent("Posix"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
592 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
593 |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
594 case OSMacOSX: |
960
0b38b64f62c7
Add OSX version declaration for Mac OS X to improve dmd-mac compatibility.
Christian Kamm <kamm incasoftware de>
parents:
942
diff
changeset
|
595 VersionCondition::addPredefinedGlobalIdent("OSX"); |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
596 VersionCondition::addPredefinedGlobalIdent("darwin"); |
909
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
597 VersionCondition::addPredefinedGlobalIdent("Posix"); |
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
598 break; |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
599 |
637
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
600 case OSFreeBSD: |
909
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
601 VersionCondition::addPredefinedGlobalIdent("freebsd"); |
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
602 VersionCondition::addPredefinedGlobalIdent("Posix"); |
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
603 break; |
637
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
604 |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
853
diff
changeset
|
605 case OSSolaris: |
909
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
606 VersionCondition::addPredefinedGlobalIdent("solaris"); |
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
607 VersionCondition::addPredefinedGlobalIdent("Posix"); |
52dad07846be
Port some LDC1 portability fixes to LDC2. Fixes #196.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
608 break; |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
853
diff
changeset
|
609 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
610 default: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
611 assert(false && "Target OS not supported"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
612 } |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
613 |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
614 if (!global.params.targetTriple) |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
615 global.params.targetTriple = DEFAULT_TARGET_TRIPLE; |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
616 |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
617 Logger::println("Target triple: %s", global.params.targetTriple); |
159 | 618 |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
619 // build a minimal data layout so llvm can find the target |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
620 global.params.dataLayout = global.params.isLE |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
621 ? (char*)(global.params.is64bit ? "e-p:64:64" : "e-p:32:32") |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
622 : (char*)(global.params.is64bit ? "E-p:64:64" : "E-p:32:32"); |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
623 Logger::println("Layout: %s", global.params.dataLayout); |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
624 |
876
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
625 // added in 1.039 |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
626 if (global.params.doDocComments) |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
627 VersionCondition::addPredefinedGlobalIdent("D_Ddoc"); |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
628 |
159 | 629 // Initialization |
630 Type::init(); | |
631 Id::initialize(); | |
632 Module::init(); | |
633 initPrecedence(); | |
634 | |
635 backend_init(); | |
636 | |
637 //printf("%d source files\n",files.dim); | |
638 | |
639 // Build import search path | |
640 if (global.params.imppath) | |
641 { | |
642 for (i = 0; i < global.params.imppath->dim; i++) | |
643 { | |
644 char *path = (char *)global.params.imppath->data[i]; | |
645 Array *a = FileName::splitPath(path); | |
646 | |
647 if (a) | |
648 { | |
649 if (!global.path) | |
650 global.path = new Array(); | |
651 global.path->append(a); | |
652 } | |
653 } | |
654 } | |
655 | |
656 // Build string import search path | |
657 if (global.params.fileImppath) | |
658 { | |
659 for (i = 0; i < global.params.fileImppath->dim; i++) | |
660 { | |
661 char *path = (char *)global.params.fileImppath->data[i]; | |
662 Array *a = FileName::splitPath(path); | |
663 | |
664 if (a) | |
665 { | |
666 if (!global.filePath) | |
667 global.filePath = new Array(); | |
668 global.filePath->append(a); | |
669 } | |
670 } | |
671 } | |
672 | |
673 // Create Modules | |
674 Array modules; | |
675 modules.reserve(files.dim); | |
676 for (i = 0; i < files.dim; i++) | |
677 { Identifier *id; | |
678 char *ext; | |
679 char *name; | |
680 | |
681 p = (char *) files.data[i]; | |
682 | |
683 p = FileName::name(p); // strip path | |
684 ext = FileName::ext(p); | |
685 if (ext) | |
686 { | |
917
7e272f2b4fc3
Removed use of TARGET_LINUX and replaced with POSIX, fixes bug [172]
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
909
diff
changeset
|
687 #if POSIX |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
688 if (strcmp(ext, global.obj_ext) == 0 || |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
689 strcmp(ext, global.bc_ext) == 0) |
159 | 690 #else |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
691 if (stricmp(ext, global.obj_ext) == 0 || |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
692 stricmp(ext, global.bc_ext) == 0) |
159 | 693 #endif |
694 { | |
695 global.params.objfiles->push(files.data[i]); | |
696 continue; | |
697 } | |
698 | |
917
7e272f2b4fc3
Removed use of TARGET_LINUX and replaced with POSIX, fixes bug [172]
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
909
diff
changeset
|
699 #if POSIX |
159 | 700 if (strcmp(ext, "a") == 0) |
917
7e272f2b4fc3
Removed use of TARGET_LINUX and replaced with POSIX, fixes bug [172]
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
909
diff
changeset
|
701 #elif __MINGW32__ |
7e272f2b4fc3
Removed use of TARGET_LINUX and replaced with POSIX, fixes bug [172]
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
909
diff
changeset
|
702 if (stricmp(ext, "a") == 0) |
159 | 703 #else |
704 if (stricmp(ext, "lib") == 0) | |
705 #endif | |
706 { | |
707 global.params.libfiles->push(files.data[i]); | |
708 continue; | |
709 } | |
710 | |
711 if (strcmp(ext, global.ddoc_ext) == 0) | |
712 { | |
713 global.params.ddocfiles->push(files.data[i]); | |
714 continue; | |
715 } | |
716 | |
917
7e272f2b4fc3
Removed use of TARGET_LINUX and replaced with POSIX, fixes bug [172]
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
909
diff
changeset
|
717 #if !POSIX |
159 | 718 if (stricmp(ext, "res") == 0) |
719 { | |
720 global.params.resfile = (char *)files.data[i]; | |
721 continue; | |
722 } | |
723 | |
724 if (stricmp(ext, "def") == 0) | |
725 { | |
726 global.params.deffile = (char *)files.data[i]; | |
727 continue; | |
728 } | |
729 | |
730 if (stricmp(ext, "exe") == 0) | |
731 { | |
732 global.params.exefile = (char *)files.data[i]; | |
733 continue; | |
734 } | |
735 #endif | |
736 | |
737 if (stricmp(ext, global.mars_ext) == 0 || | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
738 stricmp(ext, global.hdr_ext) == 0 || |
159 | 739 stricmp(ext, "htm") == 0 || |
740 stricmp(ext, "html") == 0 || | |
741 stricmp(ext, "xhtml") == 0) | |
742 { | |
743 ext--; // skip onto '.' | |
744 assert(*ext == '.'); | |
745 name = (char *)mem.malloc((ext - p) + 1); | |
746 memcpy(name, p, ext - p); | |
747 name[ext - p] = 0; // strip extension | |
748 | |
749 if (name[0] == 0 || | |
750 strcmp(name, "..") == 0 || | |
751 strcmp(name, ".") == 0) | |
752 { | |
753 Linvalid: | |
754 error("invalid file name '%s'", (char *)files.data[i]); | |
755 fatal(); | |
756 } | |
757 } | |
758 else | |
759 { error("unrecognized file extension %s\n", ext); | |
760 fatal(); | |
761 } | |
762 } | |
763 else | |
764 { name = p; | |
765 if (!*name) | |
766 goto Linvalid; | |
767 } | |
768 | |
769 id = new Identifier(name, 0); | |
770 m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); | |
771 modules.push(m); | |
772 } | |
773 | |
774 // Read files, parse them | |
775 for (i = 0; i < modules.dim; i++) | |
776 { | |
777 m = (Module *)modules.data[i]; | |
778 if (global.params.verbose) | |
779 printf("parse %s\n", m->toChars()); | |
780 if (!Module::rootModule) | |
781 Module::rootModule = m; | |
782 m->importedFrom = m; | |
783 m->read(0); | |
784 m->parse(); | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
785 m->buildTargetFiles(); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
786 m->deleteObjFile(); |
159 | 787 if (m->isDocFile) |
788 { | |
789 m->gendocfile(); | |
790 | |
791 // Remove m from list of modules | |
792 modules.remove(i); | |
793 i--; | |
794 } | |
795 } | |
796 if (global.errors) | |
797 fatal(); | |
798 #ifdef _DH | |
799 if (global.params.doHdrGeneration) | |
800 { | |
801 /* Generate 'header' import files. | |
802 * Since 'header' import files must be independent of command | |
803 * line switches and what else is imported, they are generated | |
804 * before any semantic analysis. | |
805 */ | |
806 for (i = 0; i < modules.dim; i++) | |
807 { | |
808 m = (Module *)modules.data[i]; | |
809 if (global.params.verbose) | |
810 printf("import %s\n", m->toChars()); | |
811 m->genhdrfile(); | |
812 } | |
813 } | |
814 if (global.errors) | |
815 fatal(); | |
816 #endif | |
817 | |
818 // Do semantic analysis | |
819 for (i = 0; i < modules.dim; i++) | |
820 { | |
821 m = (Module *)modules.data[i]; | |
822 if (global.params.verbose) | |
823 printf("semantic %s\n", m->toChars()); | |
824 m->semantic(); | |
825 } | |
826 if (global.errors) | |
827 fatal(); | |
828 | |
829 // Do pass 2 semantic analysis | |
830 for (i = 0; i < modules.dim; i++) | |
831 { | |
832 m = (Module *)modules.data[i]; | |
833 if (global.params.verbose) | |
834 printf("semantic2 %s\n", m->toChars()); | |
835 m->semantic2(); | |
836 } | |
837 if (global.errors) | |
838 fatal(); | |
839 | |
840 // Do pass 3 semantic analysis | |
841 for (i = 0; i < modules.dim; i++) | |
842 { | |
843 m = (Module *)modules.data[i]; | |
844 if (global.params.verbose) | |
845 printf("semantic3 %s\n", m->toChars()); | |
846 m->semantic3(); | |
847 } | |
848 if (global.errors) | |
849 fatal(); | |
850 | |
851 #if !IN_LLVM | |
852 // Scan for functions to inline | |
853 if (global.params.useInline) | |
854 { | |
855 /* The problem with useArrayBounds and useAssert is that the | |
856 * module being linked to may not have generated them, so if | |
857 * we inline functions from those modules, the symbols for them will | |
858 * not be found at link time. | |
859 */ | |
860 if (!global.params.useArrayBounds && !global.params.useAssert) | |
861 { | |
862 #endif | |
863 // Do pass 3 semantic analysis on all imported modules, | |
864 // since otherwise functions in them cannot be inlined | |
865 for (i = 0; i < Module::amodules.dim; i++) | |
866 { | |
867 m = (Module *)Module::amodules.data[i]; | |
868 if (global.params.verbose) | |
869 printf("semantic3 %s\n", m->toChars()); | |
870 m->semantic3(); | |
871 } | |
872 if (global.errors) | |
873 fatal(); | |
874 #if !IN_LLVM | |
875 } | |
876 | |
877 for (i = 0; i < modules.dim; i++) | |
878 { | |
879 m = (Module *)modules.data[i]; | |
880 if (global.params.verbose) | |
881 printf("inline scan %s\n", m->toChars()); | |
882 m->inlineScan(); | |
883 } | |
884 } | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
788
diff
changeset
|
885 #endif |
159 | 886 if (global.errors) |
887 fatal(); | |
888 | |
889 // Generate output files | |
890 for (i = 0; i < modules.dim; i++) | |
891 { | |
892 m = (Module *)modules.data[i]; | |
893 if (global.params.verbose) | |
894 printf("code %s\n", m->toChars()); | |
895 if (global.params.obj) | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
896 { |
849
ba390e5e9150
Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
897 m->genobjfile(0); |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
898 global.params.objfiles->push(m->objfile->name->str); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
899 } |
159 | 900 if (global.errors) |
901 m->deleteObjFile(); | |
902 else | |
903 { | |
904 if (global.params.doDocComments) | |
905 m->gendocfile(); | |
906 } | |
907 } | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
908 |
159 | 909 backend_term(); |
910 if (global.errors) | |
911 fatal(); | |
912 | |
913 if (!global.params.objfiles->dim) | |
914 { | |
915 if (global.params.link) | |
916 error("no object files to link"); | |
917 } | |
918 else | |
919 { | |
920 if (global.params.link) | |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
262
diff
changeset
|
921 //status = runLINK(); |
677
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
922 linkObjToExecutable(global.params.argv0); |
159 | 923 |
924 if (global.params.run) | |
925 { | |
926 if (!status) | |
927 { | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
928 status = runExectuable(); |
159 | 929 |
930 /* Delete .obj files and .exe file | |
931 */ | |
932 for (i = 0; i < modules.dim; i++) | |
933 { | |
934 m = (Module *)modules.data[i]; | |
935 m->deleteObjFile(); | |
936 } | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
937 deleteExecutable(); |
159 | 938 } |
939 } | |
940 } | |
941 | |
942 return status; | |
943 } | |
944 | |
945 | |
946 | |
947 /*********************************** | |
948 * Parse and append contents of environment variable envvar | |
949 * to argc and argv[]. | |
950 * The string is separated into arguments, processing \ and ". | |
951 */ | |
952 | |
953 void getenv_setargv(const char *envvar, int *pargc, char** *pargv) | |
954 { | |
955 char *env; | |
956 char *p; | |
957 Array *argv; | |
958 int argc; | |
959 | |
960 int wildcard; // do wildcard expansion | |
961 int instring; | |
962 int slash; | |
963 char c; | |
964 int j; | |
965 | |
966 env = getenv(envvar); | |
967 if (!env) | |
968 return; | |
969 | |
970 env = mem.strdup(env); // create our own writable copy | |
971 | |
972 argc = *pargc; | |
973 argv = new Array(); | |
974 argv->setDim(argc); | |
975 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
976 int argc_left = 0; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
977 for (int i = 0; i < argc; i++) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
978 if (!strcmp((*pargv)[i], "-run") || !strcmp((*pargv)[i], "--run")) { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
979 // HACK: set flag to indicate we saw '-run' here |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
980 global.params.run = true; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
981 // Don't eat -run yet so the program arguments don't get changed |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
982 argc_left = argc - i; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
983 argc = i; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
984 *pargv = &(*pargv)[i]; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
985 argv->setDim(i); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
986 break; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
987 } else { |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
988 argv->data[i] = (void *)(*pargv)[i]; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
989 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
990 } |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
991 // HACK to stop required values from command line being drawn from DFLAGS |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
992 argv->push((char*)""); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
993 argc++; |
159 | 994 |
995 j = 1; // leave argv[0] alone | |
996 while (1) | |
997 { | |
998 wildcard = 1; | |
999 switch (*env) | |
1000 { | |
1001 case ' ': | |
1002 case '\t': | |
1003 env++; | |
1004 break; | |
1005 | |
1006 case 0: | |
1007 goto Ldone; | |
1008 | |
1009 case '"': | |
1010 wildcard = 0; | |
1011 default: | |
1012 argv->push(env); // append | |
1013 //argv->insert(j, env); // insert at position j | |
1014 j++; | |
1015 argc++; | |
1016 p = env; | |
1017 slash = 0; | |
1018 instring = 0; | |
1019 c = 0; | |
1020 | |
1021 while (1) | |
1022 { | |
1023 c = *env++; | |
1024 switch (c) | |
1025 { | |
1026 case '"': | |
1027 p -= (slash >> 1); | |
1028 if (slash & 1) | |
1029 { p--; | |
1030 goto Laddc; | |
1031 } | |
1032 instring ^= 1; | |
1033 slash = 0; | |
1034 continue; | |
1035 | |
1036 case ' ': | |
1037 case '\t': | |
1038 if (instring) | |
1039 goto Laddc; | |
1040 *p = 0; | |
1041 //if (wildcard) | |
1042 //wildcardexpand(); // not implemented | |
1043 break; | |
1044 | |
1045 case '\\': | |
1046 slash++; | |
1047 *p++ = c; | |
1048 continue; | |
1049 | |
1050 case 0: | |
1051 *p = 0; | |
1052 //if (wildcard) | |
1053 //wildcardexpand(); // not implemented | |
1054 goto Ldone; | |
1055 | |
1056 default: | |
1057 Laddc: | |
1058 slash = 0; | |
1059 *p++ = c; | |
1060 continue; | |
1061 } | |
1062 break; | |
1063 } | |
1064 } | |
1065 } | |
1066 | |
1067 Ldone: | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
1068 assert(argc == argv->dim); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
1069 argv->reserve(argc_left); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
1070 for (int i = 0; i < argc_left; i++) |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
1071 argv->data[argc++] = (void *)(*pargv)[i]; |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
960
diff
changeset
|
1072 |
159 | 1073 *pargc = argc; |
1074 *pargv = (char **)argv->data; | |
1075 } |