annotate dmd/mars.c @ 986:a8cb25d478c4

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