annotate gen/toobj.cpp @ 1299:847b767b2d0b

Factor out the code to find gcc, and add a command-line option to override the default executable name. This should help cross-compilation by allowing a cross-gcc to be specified from the configuration file instead of only through the CC environment variable.
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 04 May 2009 13:32:16 +0200
parents 00a307a393f2
children 681dd955c53b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2 // Copyright (c) 1999-2004 by Digital Mars
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3 // All Rights Reserved
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 // written by Walter Bright
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 // www.digitalmars.com
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 // License for redistribution is by either the Artistic License
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8 // See the included readme.txt for details.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10 #include <cstddef>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11 #include <fstream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
12
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
13 #include "gen/llvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
14 #include "llvm/Analysis/Verifier.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
15 #include "llvm/Bitcode/ReaderWriter.h"
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
16 #include "llvm/Module.h"
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
17 #include "llvm/ModuleProvider.h"
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
18 #include "llvm/PassManager.h"
689
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
19 #include "llvm/LinkAllPasses.h"
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
20 #include "llvm/System/Program.h"
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
21 #include "llvm/Support/raw_ostream.h"
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
22 #include "llvm/Support/CommandLine.h"
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
23 #include "llvm/Target/TargetMachine.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
24
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
25 #include "mars.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
26 #include "module.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
27 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 #include "statement.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 #include "enum.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33 #include "attrib.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
34 #include "id.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
35 #include "import.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36 #include "template.h"
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
37 #include "scope.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
38
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
39 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
40 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
41 #include "gen/tollvm.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
42 #include "gen/llvmhelpers.h"
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 63
diff changeset
43 #include "gen/arrays.h"
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
44 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
45 #include "gen/classes.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
46 #include "gen/functions.h"
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
47 #include "gen/todebug.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
48 #include "gen/runtime.h"
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
49 #include "gen/abi.h"
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
50 #include "gen/cl_options.h"
1170
e40c65bd8c5d Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents: 1163
diff changeset
51 #include "gen/optimizer.h"
1276
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
52 #include "gen/llvm-version.h"
1299
847b767b2d0b Factor out the code to find gcc, and add a command-line option to override the
Frits van Bommel <fvbommel wxs.nl>
parents: 1280
diff changeset
53 #include "gen/programs.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
55 #include "ir/irvar.h"
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 137
diff changeset
56 #include "ir/irmodule.h"
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
57
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
58 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
60 static llvm::cl::opt<bool> noVerify("noverify",
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
61 llvm::cl::desc("Do not run the validation pass before writing bitcode"),
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
62 llvm::cl::ZeroOrMore);
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
63
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
64 //////////////////////////////////////////////////////////////////////////////////////////
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
65
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
66 // fwd decl
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
67 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out);
849
ba390e5e9150 Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents: 824
diff changeset
68 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath);
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
69
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
70 //////////////////////////////////////////////////////////////////////////////////////////
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
71
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
72 llvm::Module* Module::genLLVMModule(Ir* sir)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
73 {
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: 393
diff changeset
74 bool logenabled = Logger::enabled();
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: 393
diff changeset
75 if (llvmForceLogging && !logenabled)
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: 393
diff changeset
76 {
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: 393
diff changeset
77 Logger::enable();
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: 393
diff changeset
78 }
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: 393
diff changeset
79
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 605
diff changeset
80 Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars()));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
81 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
82
722
bd56056a581f Commented that codegen: <modulename> printf ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
83 //printf("codegen: %s\n", srcfile->toChars());
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: 393
diff changeset
84
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
85 assert(!global.errors);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
86
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
87 // name the module
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
88 std::string mname(toChars());
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
89 if (md != 0)
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
90 mname = md->toChars();
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
91
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
92 // create a new ir state
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 137
diff changeset
93 // TODO look at making the instance static and moving most functionality into IrModule where it belongs
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
94 IRState ir(new llvm::Module(mname));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 gIR = &ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 ir.dmodule = this;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97
1247
2a92c115461d Disabled resetting types between modules MAO (more at once). Fixes guaranteed MOA compilation segfault.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1241
diff changeset
98 // reset all IR data stored in Dsymbols
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
99 IrDsymbol::resetAll();
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
100
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
101 sir->setState(&ir);
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
102
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
103 // set target triple
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
104 ir.module->setTargetTriple(global.params.targetTriple);
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: 733
diff changeset
105
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: 733
diff changeset
106 // set final data layout
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
107 ir.module->setDataLayout(global.params.dataLayout);
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: 733
diff changeset
108 if (Logger::enabled())
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
109 Logger::cout() << "Final data layout: " << global.params.dataLayout << '\n';
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
110
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
111 // allocate the target abi
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 986
diff changeset
112 gABI = TargetABI::getTarget();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
113
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
114 // debug info
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
115 if (global.params.symdebug) {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
116 RegisterDwarfSymbols(ir.module);
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 137
diff changeset
117 DtoDwarfCompileUnit(this);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
118 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
119
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
120 // handle invalid 'objectø module
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
121 if (!ClassDeclaration::object) {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
122 error("is missing 'class Object'");
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
123 fatal();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
124 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
125 if (!ClassDeclaration::classinfo) {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
126 error("is missing 'class ClassInfo'");
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
127 fatal();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
128 }
1161
f528e55fb32f Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents: 1148
diff changeset
129
f528e55fb32f Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents: 1148
diff changeset
130 LLVM_D_InitRuntime();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 751
diff changeset
131
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
132 // process module members
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
133 for (int k=0; k < members->dim; k++) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
134 Dsymbol* dsym = (Dsymbol*)(members->data[k]);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
135 assert(dsym);
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
136 dsym->codegen(sir);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
137 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
138
1163
ea52660f828b Emit function bodies before generating the module info to make sure static
Christian Kamm <kamm incasoftware de>
parents: 1161
diff changeset
139 // emit function bodies
ea52660f828b Emit function bodies before generating the module info to make sure static
Christian Kamm <kamm incasoftware de>
parents: 1161
diff changeset
140 sir->emitFunctionBodies();
ea52660f828b Emit function bodies before generating the module info to make sure static
Christian Kamm <kamm incasoftware de>
parents: 1161
diff changeset
141
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
142 // generate ModuleInfo
1241
fc579f389f9a !ClassInfo instances were not mutable, this is necessary for .classinfo based locking to work. !ModuleInfo generation was commented out as well.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
143 genmoduleinfo();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
144
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 248
diff changeset
145 // emit usedArray
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
146 if (!ir.usedArray.empty())
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
147 {
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
148 const LLArrayType* usedTy = LLArrayType::get(getVoidPtrType(), ir.usedArray.size());
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
149 LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
150 LLGlobalVariable* usedArray = new LLGlobalVariable(usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used", ir.module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
151 usedArray->setSection("llvm.metadata");
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
152 }
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 248
diff changeset
153
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
154 // verify the llvm
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents: 951
diff changeset
155 if (!noVerify) {
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
156 std::string verifyErr;
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
157 Logger::println("Verifying module...");
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
158 LOG_SCOPE;
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
159 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
160 {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
161 error("%s", verifyErr.c_str());
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
162 fatal();
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
163 }
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
164 else {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
165 Logger::println("Verification passed!");
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
166 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
168
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
169 gIR = NULL;
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
170
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
171 if (llvmForceLogging && !logenabled)
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
172 {
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
173 Logger::disable();
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
174 }
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
175
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
176 sir->setState(NULL);
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
177
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
178 return ir.module;
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
179 }
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
180
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
181 void writeModule(llvm::Module* m, std::string filename)
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
182 {
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
183 // run optimizer
1170
e40c65bd8c5d Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents: 1163
diff changeset
184 bool reverify = ldc_optimize_module(m);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
185
605
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
186 // verify the llvm
1170
e40c65bd8c5d Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents: 1163
diff changeset
187 if (!noVerify && reverify) {
605
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
188 std::string verifyErr;
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
189 Logger::println("Verifying module... again...");
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
190 LOG_SCOPE;
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
191 if (llvm::verifyModule(*m,llvm::ReturnStatusAction,&verifyErr))
605
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
192 {
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
193 //error("%s", verifyErr.c_str());
605
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
194 fatal();
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
195 }
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
196 else {
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
197 Logger::println("Verification passed!");
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
198 }
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
199 }
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
200
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
201 // eventually do our own path stuff, dmd's is a bit strange.
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
202 typedef llvm::sys::Path LLPath;
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
203
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
204 // write LLVM bitcode
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
205 if (global.params.output_bc) {
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
206 LLPath bcpath = LLPath(filename);
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
207 bcpath.eraseSuffix();
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
208 bcpath.appendSuffix(std::string(global.bc_ext));
393
a3f3c2770a0d Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 363
diff changeset
209 Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
210 std::ofstream bos(bcpath.c_str(), std::ios::binary);
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
211 llvm::WriteBitcodeToFile(m, bos);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
212 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
213
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
214 // write LLVM IR
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
215 if (global.params.output_ll) {
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
216 LLPath llpath = LLPath(filename);
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
217 llpath.eraseSuffix();
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
218 llpath.appendSuffix(std::string(global.ll_ext));
580
7824c21a58e3 Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents: 565
diff changeset
219 Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
220 std::ofstream aos(llpath.c_str());
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
221 m->print(aos, NULL);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
222 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
223
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
224 // write native assembly
694
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
225 if (global.params.output_s || global.params.output_o) {
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
226 LLPath spath = LLPath(filename);
694
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
227 spath.eraseSuffix();
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
228 spath.appendSuffix(std::string(global.s_ext));
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
229 if (!global.params.output_s) {
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
230 spath.createTemporaryFileOnDisk();
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
231 }
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
232 Logger::println("Writing native asm to: %s\n", spath.c_str());
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
233 std::string err;
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
234 {
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
235 llvm::raw_fd_ostream out(spath.c_str(), false, err);
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
236 write_asm_to_file(*gTargetMachine, *m, out);
694
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
237 }
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
238
694
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
239 // call gcc to convert assembly to object file
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
240 if (global.params.output_o) {
1052
12ea38902e83 Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents: 1026
diff changeset
241 LLPath objpath = LLPath(filename);
849
ba390e5e9150 Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents: 824
diff changeset
242 assemble(spath, objpath);
694
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
243 }
675
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
244
694
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
245 if (!global.params.output_s) {
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
246 spath.eraseFromDisk();
931333ea35c6 Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents: 689
diff changeset
247 }
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
248 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
249 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
250
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
251 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
252
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
253 // based on llc code, University of Illinois Open Source License
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
254 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& out)
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
255 {
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
256 using namespace llvm;
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
257
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
258 // Build up all of the passes that we want to do to the module.
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
259 ExistingModuleProvider Provider(&m);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
260 FunctionPassManager Passes(&Provider);
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
261
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
262 Passes.add(new TargetData(*Target.getTargetData()));
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
263
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
264 // Ask the target to add backend passes as necessary.
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
265 MachineCodeEmitter *MCE = 0;
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
266
1276
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
267 #if LLVM_REV < 70343
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
268 // Last argument is bool Fast
1266
17d4d554300a Force 'fast' compilation when debug info is requested. LLVM trunk seems to
Christian Kamm <kamm incasoftware de>
parents: 1247
diff changeset
269 // debug info doesn't work properly without fast!
1276
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
270 bool LastArg = !optimize() || global.params.symdebug;
1280
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
271 #elif LLVM_REV < 70459
1276
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
272 // Last argument is unsigned OptLevel
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
273 // debug info doesn't work properly with OptLevel > 0!
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
274 unsigned LastArg = global.params.symdebug ? 0 : optLevel();
1280
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
275 #else
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
276 // Last argument is enum CodeGenOpt::Level OptLevel
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
277 // debug info doesn't work properly with OptLevel != None!
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
278 CodeGenOpt::Level LastArg = CodeGenOpt::Default;
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
279 if (global.params.symdebug)
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
280 LastArg = CodeGenOpt::None;
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
281 else if (optLevel() >= 3)
00a307a393f2 Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents: 1276
diff changeset
282 LastArg = CodeGenOpt::Aggressive;
1276
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
283 #endif
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
284 FileModel::Model mod = Target.addPassesToEmitFile(Passes, out, TargetMachine::AssemblyFile, LastArg);
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
285 assert(mod == FileModel::AsmFile);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
286
1276
fa20726fe074 Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents: 1271
diff changeset
287 bool err = Target.addPassesToEmitFileFinish(Passes, MCE, LastArg);
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
288 assert(!err);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
289
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
290 Passes.doInitialization();
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
291
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
292 // Run our queue of passes all at once now, efficiently.
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
293 for (llvm::Module::iterator I = m.begin(), E = m.end(); I != E; ++I)
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
294 if (!I->isDeclaration())
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
295 Passes.run(*I);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
296
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
297 Passes.doFinalization();
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
298
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
299 // release module from module provider so we can delete it ourselves
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
300 std::string Err;
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
301 llvm::Module* rmod = Provider.releaseModule(&Err);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
302 assert(rmod);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
303 }
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
304
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
305 /* ================================================================== */
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
306
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
307 // uses gcc to make an obj out of an assembly file
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
308 // based on llvm-ld code, University of Illinois Open Source License
849
ba390e5e9150 Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents: 824
diff changeset
309 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath)
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
310 {
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
311 using namespace llvm;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
312
1299
847b767b2d0b Factor out the code to find gcc, and add a command-line option to override the
Frits van Bommel <fvbommel wxs.nl>
parents: 1280
diff changeset
313 sys::Path gcc = getGcc();
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
314
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
315 // Run GCC to assemble and link the program into native code.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
316 //
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
317 // Note:
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
318 // We can't just assemble and link the file with the system assembler
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
319 // and linker because we don't know where to put the _start symbol.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
320 // GCC mysteriously knows how to do it.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
321 std::vector<std::string> args;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
322 args.push_back(gcc.toString());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
323 args.push_back("-fno-strict-aliasing");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
324 args.push_back("-O3");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
325 args.push_back("-c");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
326 args.push_back("-xassembler");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
327 args.push_back(asmpath.toString());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
328 args.push_back("-o");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
329 args.push_back(objpath.toString());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
330
677
075c1272a01d Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents: 676
diff changeset
331 //FIXME: only use this if needed?
075c1272a01d Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents: 676
diff changeset
332 args.push_back("-fpic");
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
333
902
893d72ab95d0 Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents: 890
diff changeset
334 //FIXME: enforce 64 bit
893d72ab95d0 Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents: 890
diff changeset
335 if (global.params.is64bit)
893d72ab95d0 Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents: 890
diff changeset
336 args.push_back("-m64");
1026
f756c47f310a Pass -m32/-m64 on to gcc when assembling and linking
Frits van Bommel <fvbommel wxs.nl>
parents: 1005
diff changeset
337 else
f756c47f310a Pass -m32/-m64 on to gcc when assembling and linking
Frits van Bommel <fvbommel wxs.nl>
parents: 1005
diff changeset
338 // Assume 32-bit?
f756c47f310a Pass -m32/-m64 on to gcc when assembling and linking
Frits van Bommel <fvbommel wxs.nl>
parents: 1005
diff changeset
339 args.push_back("-m32");
902
893d72ab95d0 Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents: 890
diff changeset
340
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
341 // Now that "args" owns all the std::strings for the arguments, call the c_str
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
342 // method to get the underlying string array. We do this game so that the
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
343 // std::string array is guaranteed to outlive the const char* array.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
344 std::vector<const char *> Args;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
345 for (unsigned i = 0, e = args.size(); i != e; ++i)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
346 Args.push_back(args[i].c_str());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
347 Args.push_back(0);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
348
994
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
349 if (Logger::enabled()) {
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
350 Logger::println("Assembling with: ");
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
351 std::vector<const char*>::const_iterator I = Args.begin(), E = Args.end();
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
352 std::ostream& logstr = *Logger::cout().stream();
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
353 for (; I != E; ++I)
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
354 if (*I)
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
355 logstr << "'" << *I << "'" << " ";
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
356 logstr << "\n" << std::flush;
18ad5601dff7 Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents: 993
diff changeset
357 }
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
358
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
359 // Run the compiler to assembly the program.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
360 std::string ErrMsg;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
361 int R = sys::Program::ExecuteAndWait(
849
ba390e5e9150 Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents: 824
diff changeset
362 gcc, &Args[0], 0, 0, 0, 0, &ErrMsg);
814
05f2651caa6c Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 811
diff changeset
363 if (R)
05f2651caa6c Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 811
diff changeset
364 {
1062
b9f9bde1707e Make error message on assembler failure more informative (hopefully)
Frits van Bommel <fvbommel wxs.nl>
parents: 1052
diff changeset
365 error("Failed to invoke gcc. %s", ErrMsg.c_str());
814
05f2651caa6c Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 811
diff changeset
366 fatal();
05f2651caa6c Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 811
diff changeset
367 }
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
368 }
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
369
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
370
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
371 /* ================================================================== */
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
372
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
373 // the following code generates functions and needs to output
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
374 // debug info. these macros are useful for that
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
375 #define DBG_TYPE ( getPtrToType(llvm::StructType::get(NULL,NULL)) )
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
376 #define DBG_CAST(X) ( llvm::ConstantExpr::getBitCast(X, DBG_TYPE) )
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
377
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
378 // build module ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
379
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
380 llvm::Function* build_module_ctor()
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
381 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
382 if (gIR->ctors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
383 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
384
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
385 size_t n = gIR->ctors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
386 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
387 return gIR->ctors[0]->ir.irFunc->func;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
388
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
389 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
390 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
391 name.append("6__ctorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
392
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
393 std::vector<const LLType*> argsTy;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
394 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
395 assert(gIR->module->getFunction(name) == NULL);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 184
diff changeset
396 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
397 fn->setCallingConv(DtoCallingConv(0, LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
398
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 184
diff changeset
399 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
400 IRBuilder<> builder(bb);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
401
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
402 // debug info
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
403 LLGlobalVariable* subprog;
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
404 if(global.params.symdebug) {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
405 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV();
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
406 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
407 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
408
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
409 for (size_t i=0; i<n; i++) {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
410 llvm::Function* f = gIR->ctors[i]->ir.irFunc->func;
316
163cad969791 [svn r337] Reverted changes to toobj.cpp: Module constructor calls can never be invokes.
ChristianK
parents: 315
diff changeset
411 llvm::CallInst* call = builder.CreateCall(f,"");
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
412 call->setCallingConv(DtoCallingConv(0, LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
413 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
414
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
415 // debug info end
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
416 if(global.params.symdebug)
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
417 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
418
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
419 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
420 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
421 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
422
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
423 // build module dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
424
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
425 static llvm::Function* build_module_dtor()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
426 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
427 if (gIR->dtors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
428 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
429
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
430 size_t n = gIR->dtors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
431 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
432 return gIR->dtors[0]->ir.irFunc->func;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
433
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
434 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
435 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
436 name.append("6__dtorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
437
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
438 std::vector<const LLType*> argsTy;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
439 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
440 assert(gIR->module->getFunction(name) == NULL);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 184
diff changeset
441 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
442 fn->setCallingConv(DtoCallingConv(0, LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
443
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 184
diff changeset
444 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
445 IRBuilder<> builder(bb);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
446
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
447 // debug info
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
448 LLGlobalVariable* subprog;
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
449 if(global.params.symdebug) {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
450 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV();
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
451 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
452 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
453
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
454 for (size_t i=0; i<n; i++) {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
455 llvm::Function* f = gIR->dtors[i]->ir.irFunc->func;
316
163cad969791 [svn r337] Reverted changes to toobj.cpp: Module constructor calls can never be invokes.
ChristianK
parents: 315
diff changeset
456 llvm::CallInst* call = builder.CreateCall(f,"");
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
457 call->setCallingConv(DtoCallingConv(0, LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
458 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
459
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
460 // debug info end
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
461 if(global.params.symdebug)
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
462 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
463
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
464 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
465 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
466 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
467
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
468 // build module unittest
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
469
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
470 static llvm::Function* build_module_unittest()
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
471 {
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
472 if (gIR->unitTests.empty())
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
473 return NULL;
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
474
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
475 size_t n = gIR->unitTests.size();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
476 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
477 return gIR->unitTests[0]->ir.irFunc->func;
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
478
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
479 std::string name("_D");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
480 name.append(gIR->dmodule->mangle());
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
481 name.append("10__unittestZ");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
482
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
483 std::vector<const LLType*> argsTy;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
484 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
485 assert(gIR->module->getFunction(name) == NULL);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 184
diff changeset
486 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
487 fn->setCallingConv(DtoCallingConv(0, LINKd));
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
488
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 184
diff changeset
489 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
490 IRBuilder<> builder(bb);
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
491
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
492 // debug info
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
493 LLGlobalVariable* subprog;
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
494 if(global.params.symdebug) {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
495 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV();
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
496 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
497 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
498
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
499 for (size_t i=0; i<n; i++) {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
500 llvm::Function* f = gIR->unitTests[i]->ir.irFunc->func;
316
163cad969791 [svn r337] Reverted changes to toobj.cpp: Module constructor calls can never be invokes.
ChristianK
parents: 315
diff changeset
501 llvm::CallInst* call = builder.CreateCall(f,"");
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
502 call->setCallingConv(DtoCallingConv(0, LINKd));
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
503 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
504
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
505 // debug info end
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
506 if(global.params.symdebug)
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
507 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
508
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
509 builder.CreateRetVoid();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
510 return fn;
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
511 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
512
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
513 // build ModuleReference and register function, to register the module info in the global linked list
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
514 static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
515 {
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
516 // build ctor type
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
517 const LLFunctionType* fty = LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
518
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
519 // build ctor name
324
c542d12017e5 [svn r345] Fixed the new moduleinfo stuff to have consistent symbol names with the D style.
lindquist
parents: 323
diff changeset
520 std::string fname = "_D";
c542d12017e5 [svn r345] Fixed the new moduleinfo stuff to have consistent symbol names with the D style.
lindquist
parents: 323
diff changeset
521 fname += gIR->dmodule->mangle();
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
522 fname += "16__moduleinfoCtorZ";
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
523
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
524 // build a function that registers the moduleinfo in the global moduleinfo linked list
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
525 LLFunction* ctor = LLFunction::Create(fty, LLGlobalValue::InternalLinkage, fname, gIR->module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
526
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
527 // provide the default initializer
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
528 const LLStructType* modulerefTy = DtoModuleReferenceType();
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
529 std::vector<LLConstant*> mrefvalues;
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
530 mrefvalues.push_back(LLConstant::getNullValue(modulerefTy->getContainedType(0)));
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
531 mrefvalues.push_back(llvm::ConstantExpr::getBitCast(moduleinfo, modulerefTy->getContainedType(1)));
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
532 LLConstant* thismrefinit = LLConstantStruct::get(modulerefTy, mrefvalues);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
533
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
534 // create the ModuleReference node for this module
324
c542d12017e5 [svn r345] Fixed the new moduleinfo stuff to have consistent symbol names with the D style.
lindquist
parents: 323
diff changeset
535 std::string thismrefname = "_D";
c542d12017e5 [svn r345] Fixed the new moduleinfo stuff to have consistent symbol names with the D style.
lindquist
parents: 323
diff changeset
536 thismrefname += gIR->dmodule->mangle();
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
537 thismrefname += "11__moduleRefZ";
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
538 LLGlobalVariable* thismref = new LLGlobalVariable(modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname, gIR->module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
539
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
540 // make sure _Dmodule_ref is declared
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
541 LLGlobalVariable* mref = gIR->module->getNamedGlobal("_Dmodule_ref");
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
542 if (!mref)
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
543 mref = new LLGlobalVariable(getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref", gIR->module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
544
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
545 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
546 llvm::BasicBlock* bb = llvm::BasicBlock::Create("moduleinfoCtorEntry", ctor);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
547 IRBuilder<> builder(bb);
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
548
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
549 // debug info
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
550 LLGlobalVariable* subprog;
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
551 if(global.params.symdebug) {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
552 subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str()).getGV();
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
553 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
554 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
555
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
556 // get current beginning
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
557 LLValue* curbeg = builder.CreateLoad(mref, "current");
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
558
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
559 // put current beginning as the next of this one
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
560 LLValue* gep = builder.CreateStructGEP(thismref, 0, "next");
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
561 builder.CreateStore(curbeg, gep);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
562
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
563 // replace beginning
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
564 builder.CreateStore(thismref, mref);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
565
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
566 // debug info end
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
567 if(global.params.symdebug)
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
568 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog));
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
569
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
570 // return
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
571 builder.CreateRetVoid();
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
572
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
573 return ctor;
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
574 }
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
575
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
576 // Put out instance of ModuleInfo for this Module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
577
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
578 void Module::genmoduleinfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
579 {
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
580 // The layout is:
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
581 // {
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
582 // char[] name;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
583 // ModuleInfo[] importedModules;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
584 // ClassInfo[] localClasses;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
585 // uint flags;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
586 //
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
587 // void function() ctor;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
588 // void function() dtor;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
589 // void function() unitTest;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
590 //
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
591 // void* xgetMembers;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
592 // void function() ictor;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
593 // }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
594
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
595 // resolve ModuleInfo
919
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
596 if (!moduleinfo)
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
597 {
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
598 error("object.d is missing the ModuleInfo class");
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
599 fatal();
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
600 }
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
601
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
602 moduleinfo->codegen(Type::sir);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
603
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
604 // check for patch
810
67fcd9df8b79 Fixed ModuleInfo patch check, failed on 64bit
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
605 if (moduleinfo->fields.dim != 9)
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
606 {
919
c76f74d09fb1 Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 902
diff changeset
607 error("object.d ModuleInfo class is incorrect");
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
608 fatal();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
609 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
610
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
611 // moduleinfo llvm struct type
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
612 const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
613 // classinfo llvm struct type
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
614 const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
615
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
616 // initializer vector
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
617 std::vector<LLConstant*> initVec;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
618 LLConstant* c = 0;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
619
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
620 // vtable
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1184
diff changeset
621 c = moduleinfo->ir.irStruct->getVtblSymbol();
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
622 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
623
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
624 // monitor
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
625 c = getNullPtr(getPtrToType(LLType::Int8Ty));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
626 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
627
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
628 // name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
629 char *name = toPrettyChars();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
630 c = DtoConstString(name);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
631 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
632
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
633 // importedModules[]
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
634 int aimports_dim = aimports.dim;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
635 std::vector<LLConstant*> importInits;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
636 for (size_t i = 0; i < aimports.dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
637 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
638 Module *m = (Module *)aimports.data[i];
824
b972fec8a5f5 Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 815
diff changeset
639 if (!m->needModuleInfo() || m == this)
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
640 continue;
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
641
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
642 // declare the imported module info
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
643 std::string m_name("_D");
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
644 m_name.append(m->mangle());
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
645 m_name.append("8__ModuleZ");
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
646 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
647 if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
648 importInits.push_back(m_gvar);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
649 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
650 // has import array?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
651 if (!importInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
652 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
653 const llvm::ArrayType* importArrTy = llvm::ArrayType::get(getPtrToType(moduleinfoTy), importInits.size());
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
654 c = llvm::ConstantArray::get(importArrTy, importInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
655 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
656 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
657 m_name.append("9__importsZ");
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
658 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
659 if (!m_gvar) m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
660 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType()));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
661 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
662 }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
663 else
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
664 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) );
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
665 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
666
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
667 // localClasses[]
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
668 ClassDeclarations aclasses;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
669 //printf("members->dim = %d\n", members->dim);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
670 for (size_t i = 0; i < members->dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
671 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
672 Dsymbol *member;
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
673
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
674 member = (Dsymbol *)members->data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
675 //printf("\tmember '%s'\n", member->toChars());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
676 member->addLocalClass(&aclasses);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
677 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
678 // fill inits
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
679 std::vector<LLConstant*> classInits;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
680 for (size_t i = 0; i < aclasses.dim; i++)
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
681 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
682 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i];
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
683 cd->codegen(Type::sir);
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
684
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
685 if (cd->isInterfaceDeclaration())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
686 {
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
687 Logger::println("skipping interface '%s' in moduleinfo", cd->toPrettyChars());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
688 continue;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
689 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
690 else if (cd->sizeok != 1)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
691 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
692 Logger::println("skipping opaque class declaration '%s' in moduleinfo", cd->toPrettyChars());
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
693 continue;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
694 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
695 Logger::println("class: %s", cd->toPrettyChars());
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1184
diff changeset
696 c = DtoBitCast(cd->ir.irStruct->getClassInfoSymbol(), getPtrToType(classinfoTy));
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
697 classInits.push_back(c);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
698 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
699 // has class array?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
700 if (!classInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
701 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
702 const llvm::ArrayType* classArrTy = llvm::ArrayType::get(getPtrToType(classinfoTy), classInits.size());
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
703 c = llvm::ConstantArray::get(classArrTy, classInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
704 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
705 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
706 m_name.append("9__classesZ");
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
707 assert(gIR->module->getGlobalVariable(m_name) == NULL);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
708 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
709 c = DtoBitCast(m_gvar, getPtrToType(classinfoTy));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
710 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
711 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
712 else
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
713 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) );
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
714 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
715
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
716 // flags
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
717 c = DtoConstUint(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
718 if (!needmoduleinfo)
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
719 c = DtoConstUint(4); // flags (4 means MIstandalone)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
720 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
721
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
722 // function pointer type for next three fields
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
723 const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false));
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
724
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
725 // ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
726 llvm::Function* fctor = build_module_ctor();
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
727 c = fctor ? fctor : getNullValue(fnptrTy);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
728 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
729
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
730 // dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
731 llvm::Function* fdtor = build_module_dtor();
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
732 c = fdtor ? fdtor : getNullValue(fnptrTy);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
733 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
734
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
735 // unitTest
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
736 llvm::Function* unittest = build_module_unittest();
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
737 c = unittest ? unittest : getNullValue(fnptrTy);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
738 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
739
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
740 // xgetMembers
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
741 c = getNullValue(getVoidPtrType());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
742 initVec.push_back(c);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
743
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
744 // ictor
811
8e6135be6999 Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 810
diff changeset
745 c = getNullValue(fnptrTy);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
746 initVec.push_back(c);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
747
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
748 /*Logger::println("MODULE INFO INITIALIZERS");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
749 for (size_t i=0; i<initVec.size(); ++i)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
750 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
751 Logger::cout() << *initVec[i] << '\n';
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
752 if (initVec[i]->getType() != moduleinfoTy->getElementType(i))
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
753 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
754 }*/
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
755
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
756 // create initializer
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
757 LLConstant* constMI = llvm::ConstantStruct::get(initVec);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
758
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
759 // create name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
760 std::string MIname("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
761 MIname.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
762 MIname.append("8__ModuleZ");
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
763
824
b972fec8a5f5 Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 815
diff changeset
764 // declare global
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
765 // flags will be modified at runtime so can't make it constant
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
766
824
b972fec8a5f5 Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 815
diff changeset
767 // it makes no sense that the our own module info already exists!
b972fec8a5f5 Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 815
diff changeset
768 assert(!gIR->module->getGlobalVariable(MIname));
b972fec8a5f5 Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 815
diff changeset
769 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module);
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
770
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
771 // build the modulereference and ctor for registering it
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
772 LLFunction* mictor = build_module_reference_and_ctor(gvar);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
773
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
774 // register this ctor in the magic llvm.global_ctors appending array
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
775 const LLFunctionType* magicfty = LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
776 std::vector<const LLType*> magictypes;
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
777 magictypes.push_back(LLType::Int32Ty);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
778 magictypes.push_back(getPtrToType(magicfty));
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
779 const LLStructType* magicsty = LLStructType::get(magictypes);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
780
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
781 // make the constant element
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
782 std::vector<LLConstant*> magicconstants;
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
783 magicconstants.push_back(DtoConstUint(65535));
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
784 magicconstants.push_back(mictor);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
785 LLConstant* magicinit = LLConstantStruct::get(magicsty, magicconstants);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
786
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
787 // declare the appending array
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
788 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(magicsty, 1);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
789 std::vector<LLConstant*> appendInits(1, magicinit);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
790 LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits);
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
791 std::string appendName("llvm.global_ctors");
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
792 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
793 }