annotate main.d @ 25:3f834bed4f13

FWindows linking issues fixed
author korDen
date Tue, 13 Apr 2010 00:38:04 +0400
parents fd4acc376c45
children 544b922227c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module main;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.VersionCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.DebugCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.FileName;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Library;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.glue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import std.stdarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import std.string : toStringz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import std.contracts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import core.stdc.ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import core.stdc.errno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import core.stdc.limits;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import core.memory;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dlib.CrashHandler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dbg.ui.CrashWindow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 bool loop = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 enum ExitCode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 EXIT_SUCCESS = 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 version (Windows)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 private import core.stdc.wchar_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 extern (C) void gc_init();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 extern (C) void gc_term();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 extern (C) void _minit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 extern (C) void _moduleCtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 extern (C) void _moduleDtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 extern (C) void thread_joinAll();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 shared bool _d_isHalting = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
60 version (Windows)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
61 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
62 import win32.windows;
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
63
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
64 /* Link to druntimes main() */
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
65
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
66 extern (C) int main(int argc, char **argv)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
67 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
68 char[][] args;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
69 int result;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
71 version (OSX)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
72 { /* OSX does not provide a way to get at the top of the
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
73 * stack, except for the magic value 0xC0000000.
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
74 * But as far as the gc is concerned, argv is at the top
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
75 * of the main thread's stack, so save the address of that.
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
76 */
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
77 __osx_stack_end = cast(void*)&argv;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
78 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
80 version (Posix)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
81 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
82 _STI_monitor_staticctor();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
83 _STI_critical_init();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
84 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
86 version (Windows)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
87 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
88 wchar_t* wcbuf = GetCommandLineW();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
89 size_t wclen = wcslen(wcbuf);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
90 int wargc = 0;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
91 wchar_t** wargs = CommandLineToArgvW(wcbuf, &wargc);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
92 assert(wargc == argc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
94 char* cargp = null;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
95 size_t cargl = WideCharToMultiByte(65001, 0, wcbuf, wclen, null, 0, null, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
97 cargp = cast(char*) alloca(cargl);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
98 args = ((cast(char[]*) alloca(wargc * (char[]).sizeof)))[0 .. wargc];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
100 for (size_t i = 0, p = 0; i < wargc; i++)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
101 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
102 int wlen = wcslen(wargs[i]);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
103 int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0, null, null);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
104 args[i] = cargp[p .. p+clen];
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
105 p += clen; assert(p <= cargl);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
106 WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, &args[i][0], clen, null, null);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
107 }
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
108 LocalFree(cast(HANDLE)wargs);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
109 wargs = null;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
110 wargc = 0;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
111 }
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
112 else version (Posix)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
113 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
114 char[]* am = cast(char[]*) malloc(argc * (char[]).sizeof);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
115 scope(exit) free(am);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
117 for (size_t i = 0; i < argc; i++)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
118 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
119 auto len = strlen(argv[i]);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
120 am[i] = argv[i][0 .. len];
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
121 }
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
122 args = am[0 .. argc];
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
123 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
125 gc_init();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
126 version (Windows)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
127 _minit();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
128 _moduleCtor();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
129
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
130 GC.disable();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
131 CrashHandlerInit();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
133 result = main(cast(string[])args);
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
134
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
135 thread_joinAll();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
136 _d_isHalting = true;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
137 _moduleDtor();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
138 gc_term();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
140 version (Posix)
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
141 {
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
142 _STD_critical_term();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
143 _STD_monitor_staticdtor();
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
144 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
146 return result;
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
147 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
25
3f834bed4f13 FWindows linking issues fixed
korDen
parents: 22
diff changeset
149
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 int main(string[] args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
152 GC.disable();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 Array files = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 Array libmodules = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 Module m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 int status = ExitCode.EXIT_SUCCESS;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 int argcstart = args.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 int setdebuglib = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 global = new Global();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 /// if (response_expand(&argc,&argv)) // expand response files
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 /// error("can't open response file");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 files.reserve(args.length - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 // Set default values
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 global.params.argv0 = args[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 global.params.link = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 global.params.useAssert = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 global.params.useInvariants = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 global.params.useIn = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 global.params.useOut = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 global.params.useArrayBounds = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 global.params.useSwitchError = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 global.params.useInline = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 global.params.obj = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 global.params.Dversion = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 global.params.quiet = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 global.params.linkswitches = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 global.params.libfiles = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 global.params.objfiles = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 global.params.ddocfiles = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 version (TARGET_WINDOS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 global.params.defaultlibname = "phobos";
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
188 } else version (POSIX) { //#elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 global.params.defaultlibname = "phobos2";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 } else version (TARGET_NET) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 static assert(false, "fix this");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 // Predefine version identifiers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 VersionCondition.addPredefinedGlobalIdent("DigitalMars");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 version (TARGET_WINDOS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 VersionCondition.addPredefinedGlobalIdent("Windows");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 global.params.isWindows = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 version (TARGET_NET) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 // TARGET_NET macro is NOT mutually-exclusive with TARGET_WINDOS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 VersionCondition.addPredefinedGlobalIdent("D_NET");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 } else version (TARGET_LINUX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 VersionCondition.addPredefinedGlobalIdent("Posix");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 VersionCondition.addPredefinedGlobalIdent("linux");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 global.params.isLinux = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 } else version (TARGET_OSX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 VersionCondition.addPredefinedGlobalIdent("Posix");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 VersionCondition.addPredefinedGlobalIdent("OSX");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 global.params.isOSX = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 // For legacy compatibility
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 VersionCondition.addPredefinedGlobalIdent("darwin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 } else version (TARGET_FREEBSD) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 VersionCondition.addPredefinedGlobalIdent("Posix");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 VersionCondition.addPredefinedGlobalIdent("FreeBSD");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 global.params.isFreeBSD = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 } else version (TARGET_SOLARIS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 VersionCondition.addPredefinedGlobalIdent("Posix");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 VersionCondition.addPredefinedGlobalIdent("Solaris");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 global.params.isSolaris = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 static assert (false, "fix this");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 VersionCondition.addPredefinedGlobalIdent("LittleEndian");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 //VersionCondition.addPredefinedGlobalIdent("D_Bits");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 VersionCondition.addPredefinedGlobalIdent("D_Version2");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 VersionCondition.addPredefinedGlobalIdent("all");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 inifile(args[0], "sc.ini");
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
237 } else version (POSIX) {///linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
238 inifile(args[0], "dmd.conf");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 static assert (false, "fix this");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 args = getenv_setargv("DFLAGS", args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 version (disabled) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 for (i = 0; i < argc; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 writef("argv[%d] = '%s'\n", i, argv[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 foreach(i; 1..args.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 auto arg = args[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 auto p = arg.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 if (*p == '-')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 arg = arg[1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (arg == "d")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 global.params.useDeprecated = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 else if (arg == "c")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 global.params.link = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 else if (arg == "cov")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 global.params.cov = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 ///version (XXX) {// TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 /// else if (arg == "fPIC")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 /// global.params.pic = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 else if (arg == "multiobj")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 global.params.multiobj = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 else if (arg == "g")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 global.params.symdebug = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 else if (arg == "gc")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 global.params.symdebug = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 else if (arg == "gt")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 { error("use -profile instead of -gt\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 global.params.trace = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 else if (arg == "m64")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 global.params.isX86_64 = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 else if (arg == "profile")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 global.params.trace = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 else if (arg == "v")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 global.params.verbose = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 else if (arg == "vtls")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 global.params.vtls = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 else if (arg == "v1")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 global.params.Dversion = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 error("use DMD 1.0 series compilers for -v1 switch");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 else if (arg == "w")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 global.params.warnings = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 else if (arg == "O")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 global.params.optimize = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 else if (p[1] == 'o')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 switch (p[2])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 case '-':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 global.params.obj = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 if (!p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 global.params.objdir = arg[(p - arg.ptr) + 3..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (!p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 global.params.objname = arg[(p - arg.ptr) + 3..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 case 'p':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 if (p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 global.params.preservePaths = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 error("-o no longer supported, use -of or -od");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 else if (p[1] == 'D')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 { global.params.doDocComments = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 switch (p[2])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 if (!p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 global.params.docdir = arg[(p - arg.ptr) + 3..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 if (!p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 global.params.docname = arg[(p - arg.ptr) + 3..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 ///version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 else if (p[1] == 'H')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 { global.params.doHdrGeneration = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 switch (p[2])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 if (!p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 global.params.hdrdir = arg[(p - arg.ptr) + 3..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 if (!p[3])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 global.params.hdrname = arg[(p - arg.ptr) + 3..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 else if (arg == "ignore")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 global.params.ignoreUnsupportedPragmas = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 else if (arg == "inline")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 global.params.useInline = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 else if (arg == "lib")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 global.params.lib = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 else if (arg == "nofloat")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 global.params.nofloat = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 else if (arg == "quiet")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 global.params.quiet = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 else if (arg == "release")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 global.params.release = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 else if (arg == "safe")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 global.params.safe = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 else if (arg == "unittest")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 global.params.useUnitTests = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 else if (p[1] == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 if (!global.params.imppath)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 global.params.imppath = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 global.params.imppath.push(cast(void*)new String(arg[(p - arg.ptr) + 2..$])); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 else if (p[1] == 'J')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (!global.params.fileImppath)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 global.params.fileImppath = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 global.params.fileImppath.push(cast(void*)new String(arg[(p - arg.ptr) + 2..$]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 else if (memcmp(p + 1, "debug".ptr, 5) == 0 && p[6] != 'l')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 // Parse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 // -debug
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 // -debug=number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 // -debug=identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 if (p[6] == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 if (isdigit(p[7]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 { long level;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 level = strtol(p + 7, cast(char**)&p, 10);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 if (*p || errno || level > INT_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 DebugCondition.setGlobalLevel(cast(int)level);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 else if (Lexer.isValidIdentifier(arg[(p - arg.ptr) + 7..$])) ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 DebugCondition.addGlobalIdent(p + 7);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 else if (p[6])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 global.params.debuglevel = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 else if (memcmp(p + 1, "version".ptr, 5) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 // Parse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 // -version=number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 // -version=identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 if (p[8] == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 if (isdigit(p[9]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 { long level;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 level = strtol(p + 9, cast(char**)&p, 10); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 if (*p || errno || level > INT_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 VersionCondition.setGlobalLevel(cast(int)level);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 else if (Lexer.isValidIdentifier(arg[(p - arg.ptr) + 9..$])) ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 VersionCondition.addGlobalIdent(arg[(p - arg.ptr) + 9..$]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 else if (arg == "-b")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 global.params.debugb = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 else if (arg == "-c")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 global.params.debugc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 else if (arg == "-f")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 global.params.debugf = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 else if (arg == "-help")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 { usage();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 exit(EXIT_SUCCESS);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 else if (arg == "-r")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 global.params.debugr = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 else if (arg == "-x")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 global.params.debugx = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 else if (arg == "-y")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 global.params.debugy = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 else if (p[1] == 'L')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 global.params.linkswitches.push(cast(void*)p + 2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 else if (memcmp(p + 1, "defaultlib=".ptr, 11) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 global.params.defaultlibname = p + 1 + 11;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 else if (memcmp(p + 1, "debuglib=".ptr, 9) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 setdebuglib = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 global.params.debuglibname = p + 1 + 9;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 else if (memcmp(p + 1, "deps=".ptr, 5) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 global.params.moduleDepsFile = arg[(p - arg.ptr) + 1 + 5..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 if (!global.params.moduleDepsFile[0])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 global.params.moduleDeps = new OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 else if (memcmp(p + 1, "man".ptr, 3) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 browse("http://www.digitalmars.com/d/1.0/dmd-windows.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 browse("http://www.digitalmars.com/d/2.0/dmd-windows.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 version (linux) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 browse("http://www.digitalmars.com/d/1.0/dmd-linux.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 browse("http://www.digitalmars.com/d/2.0/dmd-linux.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 version (__APPLE__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 browse("http://www.digitalmars.com/d/1.0/dmd-osx.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 browse("http://www.digitalmars.com/d/2.0/dmd-osx.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 version (__FreeBSD__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 browse("http://www.digitalmars.com/d/1.0/dmd-freebsd.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 browse("http://www.digitalmars.com/d/2.0/dmd-freebsd.html");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 exit(EXIT_SUCCESS);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 else if (arg == "run")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 { global.params.run = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 global.params.runargs_length = ((i >= argcstart) ? args.length : argcstart) - i - 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 if (global.params.runargs_length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 files.push(cast(void*)args[i + 1].ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 global.params.runargs = args[i + 2..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 i += global.params.runargs_length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 global.params.runargs_length--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 { global.params.run = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 goto Lnoarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 error("unrecognized switch '%s'", args[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 Lnoarg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 error("argument expected for switch '%s'", args[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 version (TARGET_WINDOS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 string ext = FileName.ext(p[0..arg.length]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 if (ext != null && FileName.compare(ext, "exe") == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 global.params.objname = arg[(p - arg.ptr)..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 files.push(cast(void*)new String(arg[(p - arg.ptr)..$]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 if (files.dim == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 { usage();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 return EXIT_FAILURE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 if (!setdebuglib)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 global.params.debuglibname = global.params.defaultlibname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 version (TARGET_OSX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 global.params.pic = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 if (global.params.release)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 { global.params.useInvariants = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 global.params.useIn = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 global.params.useOut = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 global.params.useAssert = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 global.params.useArrayBounds = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 global.params.useSwitchError = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 if (global.params.run)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 global.params.quiet = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 if (global.params.useUnitTests)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 global.params.useAssert = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 if (!global.params.obj || global.params.lib)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 global.params.link = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 if (global.params.link)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 global.params.exefile = global.params.objname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 global.params.oneobj = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 if (global.params.objname)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 /* Use this to name the one object file with the same
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 * name as the exe file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 global.params.objname = FileName.forceExt(global.params.objname, global.obj_ext).toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 /* If output directory is given, use that path rather than
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 * the exe file path.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 if (global.params.objdir)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 string name = FileName.name(global.params.objname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 global.params.objname = FileName.combine(global.params.objdir, name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 else if (global.params.lib)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 global.params.libname = global.params.objname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 global.params.objname = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 // Haven't investigated handling these options with multiobj
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 if (!global.params.cov && !global.params.trace)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 global.params.multiobj = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 else if (global.params.run)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 error("flags conflict with -run");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 if (global.params.objname && files.dim > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 global.params.oneobj = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 //error("multiple source files, but only one .obj name");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 //fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 if (global.params.isX86_64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 VersionCondition.addPredefinedGlobalIdent("D_InlineAsm_X86_64");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 VersionCondition.addPredefinedGlobalIdent("X86_64");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 VersionCondition.addPredefinedGlobalIdent("D_LP64");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 version (TARGET_WINDOS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 VersionCondition.addPredefinedGlobalIdent("Win64");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 VersionCondition.addPredefinedGlobalIdent("D_InlineAsm");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 VersionCondition.addPredefinedGlobalIdent("D_InlineAsm_X86");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 VersionCondition.addPredefinedGlobalIdent("X86");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 version (TARGET_WINDOS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 VersionCondition.addPredefinedGlobalIdent("Win32");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 if (global.params.doDocComments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 VersionCondition.addPredefinedGlobalIdent("D_Ddoc");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 if (global.params.cov)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 VersionCondition.addPredefinedGlobalIdent("D_Coverage");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 if (global.params.pic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 VersionCondition.addPredefinedGlobalIdent("D_PIC");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 if (global.params.useUnitTests)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 VersionCondition.addPredefinedGlobalIdent("unittest");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 // Initialization
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 Type.init();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 Id.initialize();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 Module.init();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 initPrecedence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 backend_init();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 //printf("%d source files\n",files.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 // Build import search path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 if (global.params.imppath)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 for (int i = 0; i < global.params.imppath.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 string path = (cast(String)global.params.imppath.data[i]).str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 string[] a = FileName.splitPath(path);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 global.path ~= a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 // Build string import search path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 if (global.params.fileImppath)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 for (int i = 0; i < global.params.fileImppath.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 string path = (cast(String)global.params.fileImppath.data[i]).str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 string[] a = FileName.splitPath(path);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 global.filePath ~= a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 // Create Modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 Array modules = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 modules.reserve(files.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 int firstmodule = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 for (int i = 0; i < files.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 string ext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 string name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 String s = cast(String) files.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 string mp = s.str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 char[] copy = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 // Convert / to \ so linker will work
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 foreach (j, c; mp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 if (c == '/') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 if (copy is null) copy = mp.dup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 copy[j] = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 if (copy !is null) mp = assumeUnique(copy);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 string p = mp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 p = FileName.name(p); // strip path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 ext = FileName.ext(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 if (ext.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 { /* Deduce what to do with a file based on its extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 if (FileName.equals(ext, global.obj_ext))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 global.params.objfiles.push(files.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 libmodules.push(files.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 if (FileName.equals(ext, global.lib_ext))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 global.params.libfiles.push(files.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 libmodules.push(files.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 if (ext == global.ddoc_ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 global.params.ddocfiles.push(files.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 version (TARGET_WINDOS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 if (FileName.equals(ext, "res"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 global.params.resfile = (cast(immutable(char)*)files.data[i])[0..0]; /// !!!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 if (FileName.equals(ext, "def"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 global.params.deffile = (cast(immutable(char)*)files.data[i])[0..0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 if (FileName.equals(ext, "exe"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 assert(0); // should have already been handled
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 /* Examine extension to see if it is a valid
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 * D source file extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 if (FileName.equals(ext, global.mars_ext) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 FileName.equals(ext, global.hdr_ext) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 FileName.equals(ext, "dd") ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 FileName.equals(ext, "htm") ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 FileName.equals(ext, "html") ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 FileName.equals(ext, "xhtml"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 immutable(char)* e = ext.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 e--; // skip onto '.'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 assert(*e == '.');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 immutable(char)* n = p.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 name = n[0..(e-n)]; // strip extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 if (name.length == 0 || name == ".." || name == ".")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 Linvalid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 error("invalid file name '%s'", (cast(String)files.data[i]).str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 { error("unrecognized file extension %s\n", ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 name = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 if (!*name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 goto Linvalid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 /* At this point, name is the D source file name stripped of
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 * its path and extension.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 Identifier id = new Identifier(name, TOK.TOKreserved);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 m = new Module((cast(String) files.data[i]).str, id, global.params.doDocComments, global.params.doHdrGeneration);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 modules.push(cast(void*)m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 if (firstmodule)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 global.params.objfiles.push(cast(void*)m.objfile.name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 firstmodule = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 // Read files
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 //version = ASYNCREAD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 version (ASYNCREAD) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 // Multi threaded
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 AsyncRead *aw = AsyncRead.create(modules.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 for (i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 m = cast(Module *)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 aw.addFile(m.srcfile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 aw.start();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 // Single threaded
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 m.read(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 // Parse files
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 int anydocfiles = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 writef("parse %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 if (!Module.rootModule)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 Module.rootModule = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 m.importedFrom = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 if (!global.params.oneobj || i == 0 || m.isDocFile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 m.deleteObjFile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 version (ASYNCREAD) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 if (aw.read(i))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 error("cannot read file %s", m.srcfile.name.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 //while (loop) {}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 m.parse();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 if (m.isDocFile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 anydocfiles = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 m.gendocfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 // Remove m from list of modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 modules.remove(i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 i--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 // Remove m's object file from list of object files
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 for (int j = 0; j < global.params.objfiles.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 if (m.objfile.name.str == (cast(FileName)global.params.objfiles.data[j]).str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 global.params.objfiles.remove(j);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 if (global.params.objfiles.dim == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 global.params.link = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 version (ASYNCREAD) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 AsyncRead.dispose(aw);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 if (anydocfiles && modules.dim &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 (global.params.oneobj || global.params.objname))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 error("conflicting Ddoc and obj generation options");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 if (global.params.doHdrGeneration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 /* Generate 'header' import files.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 * Since 'header' import files must be independent of command
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 * line switches and what else is imported, they are generated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 * before any semantic analysis.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 for (i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 m = cast(Module *)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 writef("import %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 m.genhdrfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 // Do semantic analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 writef("semantic %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 m.semantic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 // Do pass 2 semantic analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 writef("semantic2 %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 m.semantic2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 // Do pass 3 semantic analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 writef("semantic3 %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 m.semantic3();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 if (global.params.moduleDeps !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 assert(global.params.moduleDepsFile !is null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 File deps = new File(global.params.moduleDepsFile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 OutBuffer ob = global.params.moduleDeps;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 deps.setbuffer(cast(void*)ob.data, ob.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 deps.writev();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 // Scan for functions to inline
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 if (global.params.useInline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 /* The problem with useArrayBounds and useAssert is that the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 * module being linked to may not have generated them, so if
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 * we inline functions from those modules, the symbols for them will
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 * not be found at link time.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 if (!global.params.useArrayBounds && !global.params.useAssert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 // Do pass 3 semantic analysis on all imported modules,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 // since otherwise functions in them cannot be inlined
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 for (int i = 0; i < Module.amodules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 m = cast(Module)Module.amodules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 writef("semantic3 %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 m.semantic3();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 writef("inline scan %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 m.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 Library library = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 if (global.params.lib)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 library = new Library();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 library.setFilename(global.params.objdir, global.params.libname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 // Add input object and input library files to output library
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 for (int i = 0; i < libmodules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 string p = (cast(String)libmodules.data[i]).str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 library.addObject(p, null, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 // Generate output files
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 if (global.params.oneobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 writef("code %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 if (i == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 obj_start(cast(char*)toStringz(m.srcfile.toChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 m.genobjfile(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 if (!global.errors && global.params.doDocComments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 m.gendocfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 if (!global.errors && modules.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 obj_end(library, (cast(Module)modules.data[0]).objfile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 writef("code %s\n", m.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 if (global.params.obj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 obj_start(cast(char*)toStringz(m.srcfile.toChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 m.genobjfile(global.params.multiobj);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 obj_end(library, m.objfile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 obj_write_deferred(library);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 if (!global.params.lib)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 m.deleteObjFile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 if (global.params.doDocComments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 m.gendocfile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 if (global.params.lib && !global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 library.write();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 backend_term();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 if (!global.params.objfiles.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 if (global.params.link)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 error("no object files to link");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 if (global.params.link)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 status = runLINK();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 if (global.params.run)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 if (!status)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 status = runProgram();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 /* Delete .obj files and .exe file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 for (int i = 0; i < modules.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 m = cast(Module)modules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 m.deleteObjFile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 if (global.params.oneobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 deleteExeFile();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 return status;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1111 }