annotate gen/toobj.cpp @ 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. Changed -g switch to emit DW_LANG_D debug info, make demangling work with a patched GDB, still more work to do for full support of D's Dwarf extensions. Added getNullValue helper method.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 01 Dec 2008 02:10:16 +0100
parents 67fcd9df8b79
children 05f2651caa6c
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 <iostream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
12 #include <fstream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
13
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
14 #include "gen/llvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
15 #include "llvm/Analysis/Verifier.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16 #include "llvm/Bitcode/ReaderWriter.h"
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
17 #include "llvm/Target/SubtargetFeature.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 #include "llvm/Target/TargetMachine.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
19 #include "llvm/Target/TargetMachineRegistry.h"
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
20 #include "llvm/Module.h"
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
21 #include "llvm/ModuleProvider.h"
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
22 #include "llvm/PassManager.h"
689
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
23 #include "llvm/LinkAllPasses.h"
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
24 #include "llvm/System/Program.h"
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
25 #include "llvm/System/Path.h"
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
26 #include "llvm/Support/raw_ostream.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
27
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 #include "mars.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 #include "module.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32 #include "statement.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33 #include "enum.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
34 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
35 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36 #include "attrib.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
37 #include "id.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
38 #include "import.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
39 #include "template.h"
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
40 #include "scope.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
41
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
42 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
43 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
44 #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
45 #include "gen/llvmhelpers.h"
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 63
diff changeset
46 #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
47 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
48 #include "gen/classes.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
49 #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
50 #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
51 #include "gen/runtime.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
52
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
53 #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
54 #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
55
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
58 // in gen/optimize.cpp
663
6aaa3d3c1183 First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents: 650
diff changeset
59 void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline);
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
60
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
61 // 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
62 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out);
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
63 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath, char** envp);
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
64
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
65 //////////////////////////////////////////////////////////////////////////////////////////
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
66
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
67 void Module::genobjfile(int multiobj, char** envp)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68 {
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
69 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
70 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
71 {
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
72 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
73 }
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
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
75 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
76 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
77
722
bd56056a581f Commented that codegen: <modulename> printf ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
78 //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
79
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
80 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
81
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
82 // start by deleting the old object file
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
83 deleteObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
84
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
85 // 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
86 // TODO look at making the instance static and moving most functionality into IrModule where it belongs
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87 IRState ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
88 gIR = &ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
89 ir.dmodule = this;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
90
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
91 // reset all IR data stored in Dsymbols and Types
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
92 IrDsymbol::resetAll();
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
93 IrType::resetAll();
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
94
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
95 // name the module
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 std::string mname(toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97 if (md != 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98 mname = md->toChars();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99 ir.module = new llvm::Module(mname);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 677
diff changeset
101 // module ir state
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 677
diff changeset
102 // might already exist via import, just overwrite...
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 677
diff changeset
103 //FIXME: is there a good reason for overwriting?
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 677
diff changeset
104 this->ir.irModule = new IrModule(this, srcfile->toChars());
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 677
diff changeset
105
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
106 // set target stuff
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
107
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
108 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
109 ir.module->setDataLayout(global.params.dataLayout);
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
110
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
111 // get the target machine
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
112 const llvm::TargetMachineRegistry::entry* MArch;
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
113
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
114 std::string Err;
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
115 MArch = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, Err);
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
116 if (MArch == 0) {
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
117 error("error auto-selecting target for module '%s'", Err.c_str());
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
118 fatal();
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
119 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
120
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
121 llvm::SubtargetFeatures Features;
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
122 //TODO: Features?
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
123 // Features.setCPU(MCPU);
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
124 // for (unsigned i = 0; i != MAttrs.size(); ++i)
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
125 // Features.AddFeature(MAttrs[i]);
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
126
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
127 // only generate PIC code when -fPIC switch is used
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
128 if (global.params.pic)
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
129 llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_);
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
130
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
131 // allocate the target machine
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
132 std::auto_ptr<llvm::TargetMachine> target(MArch->CtorFn(*ir.module, Features.getString()));
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
133 assert(target.get() && "Could not allocate target machine!");
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
134 llvm::TargetMachine &Target = *target.get();
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
135
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
136 gTargetData = Target.getTargetData();
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
137
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
138 // set final data layout
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
139 std::string datalayout = gTargetData->getStringRepresentation();
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
140 ir.module->setDataLayout(datalayout);
eee9efe5b51f Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 733
diff changeset
141 if (Logger::enabled())
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
142 Logger::cout() << "Final data layout: " << datalayout << '\n';
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
143 assert(memcmp(global.params.dataLayout, datalayout.c_str(), 9) == 0); // "E-p:xx:xx"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
144
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
145 // 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
146 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
147 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
148 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
149 }
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
150
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
151 // 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
152 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
153 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
154 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
155 }
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
156 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
157 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
158 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
159 }
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
160
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
161 // process module members
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
162 for (int k=0; k < members->dim; k++) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
163 Dsymbol* dsym = (Dsymbol*)(members->data[k]);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
164 assert(dsym);
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
165 dsym->toObjFile(multiobj);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
166 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
168 // main driver loop
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
169 DtoEmptyAllLists();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
170 // generate ModuleInfo
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
171 genmoduleinfo();
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
172 // do this again as moduleinfo might have pulled something in!
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
173 DtoEmptyAllLists();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
174
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 248
diff changeset
175 // 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
176 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
177 {
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
178 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
179 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
180 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
181 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
182 }
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 248
diff changeset
183
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
184 // verify the llvm
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
185 if (!global.params.novalidate) {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
186 std::string verifyErr;
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
187 Logger::println("Verifying module...");
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
188 LOG_SCOPE;
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
189 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
190 {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
191 error("%s", verifyErr.c_str());
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
192 fatal();
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
193 }
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
194 else {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
195 Logger::println("Verification passed!");
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
196 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
197 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
198
689
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
199 // always run this pass to eliminate dead code that breaks debug info
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
200 llvm::PassManager pm;
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
201 pm.add(new llvm::TargetData(ir.module));
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
202 pm.add(llvm::createCFGSimplificationPass());
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
203 pm.run(*ir.module);
06c05906b054 Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents: 686
diff changeset
204
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
205 // run optimizer
663
6aaa3d3c1183 First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents: 650
diff changeset
206 ldc_optimize_module(ir.module, global.params.optimizeLevel, global.params.llvmInline);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
207
605
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
208 // verify the llvm
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
209 if (!global.params.novalidate && (global.params.optimizeLevel >= 0 || global.params.llvmInline)) {
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
210 std::string verifyErr;
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
211 Logger::println("Verifying module... again...");
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
212 LOG_SCOPE;
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
213 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
214 {
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
215 error("%s", verifyErr.c_str());
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
216 fatal();
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
217 }
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
218 else {
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
219 Logger::println("Verification passed!");
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
220 }
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
221 }
e235b80c92bc Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 583
diff changeset
222
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
223 // 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
224 typedef llvm::sys::Path LLPath;
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
225
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
226 // 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
227 if (global.params.output_bc) {
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
228 LLPath bcpath = LLPath(objfile->name->toChars());
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
229 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
230 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
231 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
232 std::ofstream bos(bcpath.c_str(), std::ios::binary);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
233 llvm::WriteBitcodeToFile(ir.module, bos);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
234 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
235
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
236 // 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
237 if (global.params.output_ll) {
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 LLPath llpath = LLPath(objfile->name->toChars());
bfe5229f9d8e Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents: 674
diff changeset
239 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
240 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
241 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
242 std::ofstream aos(llpath.c_str());
565
3c07287765bc Fixed toobj.cpp to compile with latest LLVM, seems a method overload was removed recently.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 511
diff changeset
243 ir.module->print(aos, NULL);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
244 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
245
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
246 // 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
247 if (global.params.output_s || global.params.output_o) {
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
248 LLPath spath = LLPath(objfile->name->toChars());
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
249 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
250 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
251 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
252 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
253 }
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
254 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
255 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
256 {
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
257 llvm::raw_fd_ostream out(spath.c_str(), err);
699
ed9a9e6dd1cc Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 694
diff changeset
258 write_asm_to_file(Target, *ir.module, 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
259 }
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
260
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
261 // 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
262 if (global.params.output_o) {
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
263 LLPath objpath = LLPath(objfile->name->toChars());
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
264 assemble(spath, objpath, envp);
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
265 }
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
266
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
267 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
268 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
269 }
673
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
270 }
37a7688a7494 Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents: 663
diff changeset
271
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
272 delete ir.module;
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
273 gTargetData = 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
274 gIR = NULL;
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
275
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
276 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
277 {
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
278 Logger::disable();
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
279 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
280 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
281
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
282 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
283
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
284 // 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
285 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
286 {
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
287 using namespace llvm;
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
288
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
289 // 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
290 ExistingModuleProvider Provider(&m);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
291 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
292
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
293 Passes.add(new TargetData(*Target.getTargetData()));
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
294
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
295 // 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
296 MachineCodeEmitter *MCE = 0;
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
297
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
298 //TODO: May want to switch it on for -O0?
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
299 bool Fast = false;
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
300 FileModel::Model mod = Target.addPassesToEmitFile(Passes, out, TargetMachine::AssemblyFile, Fast);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
301 assert(mod == FileModel::AsmFile);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
302
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
303 bool err = Target.addPassesToEmitFileFinish(Passes, MCE, Fast);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
304 assert(!err);
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 Passes.doInitialization();
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
307
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
308 // 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
309 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
310 if (!I->isDeclaration())
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
311 Passes.run(*I);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
312
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
313 Passes.doFinalization();
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
314
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
315 // 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
316 std::string Err;
674
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
317 llvm::Module* rmod = Provider.releaseModule(&Err);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
318 assert(rmod);
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
319 }
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
320
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
321 /* ================================================================== */
db6a7e574cbd Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents: 673
diff changeset
322
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
323 // helper functions for gcc call to assemble
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
324 // based on llvm-ld code, University of Illinois Open Source License
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
325
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
326 /// CopyEnv - This function takes an array of environment variables and makes a
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
327 /// copy of it. This copy can then be manipulated any way the caller likes
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
328 /// without affecting the process's real environment.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
329 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
330 /// Inputs:
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
331 /// envp - An array of C strings containing an environment.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
332 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
333 /// Return value:
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
334 /// NULL - An error occurred.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
335 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
336 /// Otherwise, a pointer to a new array of C strings is returned. Every string
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
337 /// in the array is a duplicate of the one in the original array (i.e. we do
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
338 /// not copy the char *'s from one array to another).
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
339 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
340 static char ** CopyEnv(char ** const envp) {
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
341 // Count the number of entries in the old list;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
342 unsigned entries; // The number of entries in the old environment list
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
343 for (entries = 0; envp[entries] != NULL; entries++)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
344 /*empty*/;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
345
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
346 // Add one more entry for the NULL pointer that ends the list.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
347 ++entries;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
348
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
349 // If there are no entries at all, just return NULL.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
350 if (entries == 0)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
351 return NULL;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
352
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
353 // Allocate a new environment list.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
354 char **newenv = new char* [entries];
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
355 if ((newenv = new char* [entries]) == NULL)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
356 return NULL;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
357
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
358 // Make a copy of the list. Don't forget the NULL that ends the list.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
359 entries = 0;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
360 while (envp[entries] != NULL) {
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
361 newenv[entries] = new char[strlen (envp[entries]) + 1];
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
362 strcpy (newenv[entries], envp[entries]);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
363 ++entries;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
364 }
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
365 newenv[entries] = NULL;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
366
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
367 return newenv;
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 // based on llvm-ld code, University of Illinois Open Source License
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
371
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
372 /// RemoveEnv - Remove the specified environment variable from the environment
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
373 /// array.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
374 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
375 /// Inputs:
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
376 /// name - The name of the variable to remove. It cannot be NULL.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
377 /// envp - The array of environment variables. It cannot be NULL.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
378 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
379 /// Notes:
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
380 /// This is mainly done because functions to remove items from the environment
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
381 /// are not available across all platforms. In particular, Solaris does not
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
382 /// seem to have an unsetenv() function or a setenv() function (or they are
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
383 /// undocumented if they do exist).
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
384 ///
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
385 static void RemoveEnv(const char * name, char ** const envp) {
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
386 for (unsigned index=0; envp[index] != NULL; index++) {
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
387 // Find the first equals sign in the array and make it an EOS character.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
388 char *p = strchr (envp[index], '=');
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
389 if (p == NULL)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
390 continue;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
391 else
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
392 *p = '\0';
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
393
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
394 // Compare the two strings. If they are equal, zap this string.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
395 // Otherwise, restore it.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
396 if (!strcmp(name, envp[index]))
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
397 *envp[index] = '\0';
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
398 else
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
399 *p = '=';
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
400 }
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
401
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
402 return;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
403 }
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
404
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
405 // 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
406 // based on llvm-ld code, University of Illinois Open Source License
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
407 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath, char** envp)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
408 {
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
409 using namespace llvm;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
410
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
411 sys::Path gcc = llvm::sys::Program::FindProgramByName("gcc");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
412
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
413 // Remove these environment variables from the environment of the
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
414 // programs that we will execute. It appears that GCC sets these
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
415 // environment variables so that the programs it uses can configure
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
416 // themselves identically.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
417 //
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
418 // However, when we invoke GCC below, we want it to use its normal
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
419 // configuration. Hence, we must sanitize its environment.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
420 char ** clean_env = CopyEnv(envp);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
421 if (clean_env == NULL)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
422 return;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
423 RemoveEnv("LIBRARY_PATH", clean_env);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
424 RemoveEnv("COLLECT_GCC_OPTIONS", clean_env);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
425 RemoveEnv("GCC_EXEC_PREFIX", clean_env);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
426 RemoveEnv("COMPILER_PATH", clean_env);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
427 RemoveEnv("COLLECT_GCC", clean_env);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
428
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
429
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
430 // 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
431 //
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
432 // Note:
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
433 // 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
434 // 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
435 // GCC mysteriously knows how to do it.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
436 std::vector<std::string> args;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
437 args.push_back(gcc.toString());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
438 args.push_back("-fno-strict-aliasing");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
439 args.push_back("-O3");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
440 args.push_back("-c");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
441 args.push_back("-xassembler");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
442 args.push_back(asmpath.toString());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
443 args.push_back("-o");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
444 args.push_back(objpath.toString());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
445
677
075c1272a01d Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents: 676
diff changeset
446 //FIXME: only use this if needed?
075c1272a01d Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents: 676
diff changeset
447 args.push_back("-fpic");
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
448
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
449 // 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
450 // 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
451 // 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
452 std::vector<const char *> Args;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
453 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
454 Args.push_back(args[i].c_str());
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
455 Args.push_back(0);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
456
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
457 Logger::println("Assembling with: ");
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
458 std::vector<const char*>::const_iterator I = Args.begin(), E = Args.end();
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
459 std::ostream& logstr = Logger::cout();
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
460 for (; I != E; ++I)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
461 if (*I)
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
462 logstr << "'" << *I << "'" << " ";
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
463 logstr << "\n" << std::flush;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
464
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
465 // Run the compiler to assembly the program.
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
466 std::string ErrMsg;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
467 int R = sys::Program::ExecuteAndWait(
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
468 gcc, &Args[0], (const char**)clean_env, 0, 0, 0, &ErrMsg);
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
469 delete [] clean_env;
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
470 }
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
471
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
472
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
473 /* ================================================================== */
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
474
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
475 // 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
476 // 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
477 #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
478 #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
479
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
480 // build module ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
481
676
1f0a78174598 Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents: 675
diff changeset
482 llvm::Function* build_module_ctor()
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
483 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
484 if (gIR->ctors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
485 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
486
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
487 size_t n = gIR->ctors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
488 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
489 return gIR->ctors[0]->ir.irFunc->func;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
490
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
491 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
492 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
493 name.append("6__ctorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
494
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
495 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
496 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
497 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
498 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
707
1556a9328ba1 Fixed bug with generated functions having wrong calling conventions. Thanks downs.
Christian Kamm <kamm incasoftware de>
parents: 699
diff changeset
499 fn->setCallingConv(DtoCallingConv(LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
500
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
501 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
502 IRBuilder<> builder(bb);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
503
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
504 // 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
505 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
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 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str());
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
508 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
509 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
510
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
511 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
512 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
513 llvm::CallInst* call = builder.CreateCall(f,"");
707
1556a9328ba1 Fixed bug with generated functions having wrong calling conventions. Thanks downs.
Christian Kamm <kamm incasoftware de>
parents: 699
diff changeset
514 call->setCallingConv(DtoCallingConv(LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
515 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
516
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
517 // 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
518 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
519 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
520
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
521 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
522 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
523 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
524
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
525 // build module dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
526
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
527 static llvm::Function* build_module_dtor()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
528 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
529 if (gIR->dtors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
530 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
531
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
532 size_t n = gIR->dtors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
533 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
534 return gIR->dtors[0]->ir.irFunc->func;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
535
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
536 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
537 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
538 name.append("6__dtorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
539
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
540 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
541 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
542 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
543 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
707
1556a9328ba1 Fixed bug with generated functions having wrong calling conventions. Thanks downs.
Christian Kamm <kamm incasoftware de>
parents: 699
diff changeset
544 fn->setCallingConv(DtoCallingConv(LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
545
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
546 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
547 IRBuilder<> builder(bb);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
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) {
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
552 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str());
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
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
556 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
557 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
558 llvm::CallInst* call = builder.CreateCall(f,"");
707
1556a9328ba1 Fixed bug with generated functions having wrong calling conventions. Thanks downs.
Christian Kamm <kamm incasoftware de>
parents: 699
diff changeset
559 call->setCallingConv(DtoCallingConv(LINKd));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
560 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
561
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
562 // 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
563 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
564 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
565
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
566 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
567 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
568 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
569
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
570 // build module unittest
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
571
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
572 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
573 {
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
574 if (gIR->unitTests.empty())
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
575 return NULL;
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
576
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
577 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
578 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
579 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
580
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
581 std::string name("_D");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
582 name.append(gIR->dmodule->mangle());
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
583 name.append("10__unittestZ");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
584
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
585 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
586 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
587 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
588 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
707
1556a9328ba1 Fixed bug with generated functions having wrong calling conventions. Thanks downs.
Christian Kamm <kamm incasoftware de>
parents: 699
diff changeset
589 fn->setCallingConv(DtoCallingConv(LINKd));
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
590
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
591 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
592 IRBuilder<> builder(bb);
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
593
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
594 // 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
595 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
596 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
597 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str());
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
598 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
599 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
600
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
601 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
602 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
603 llvm::CallInst* call = builder.CreateCall(f,"");
707
1556a9328ba1 Fixed bug with generated functions having wrong calling conventions. Thanks downs.
Christian Kamm <kamm incasoftware de>
parents: 699
diff changeset
604 call->setCallingConv(DtoCallingConv(LINKd));
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
605 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
606
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
607 // 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
608 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
609 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
610
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
611 builder.CreateRetVoid();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
612 return fn;
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
613 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
614
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
615 // 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
616 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
617 {
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
618 // 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
619 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
620
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
621 // 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
622 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
623 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
624 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
625
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
626 // 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
627 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
628
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
629 // 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
630 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
631 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
632 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
633 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
634 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
635
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
636 // 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
637 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
638 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
639 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
640 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
641
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
642 // 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
643 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
644 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
645 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
646
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
647 // 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
648 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
649 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
650
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
651 // 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
652 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
653 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
654 subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str());
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
655 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
656 }
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
657
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
658 // 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
659 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
660
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
661 // 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
662 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
663 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
664
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
665 // 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
666 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
667
686
363bb6c0cc80 Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents: 683
diff changeset
668 // 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
669 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
670 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
671
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
672 // return
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
673 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
674
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
675 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
676 }
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
677
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
678 // Put out instance of ModuleInfo for this Module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
679
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
680 void Module::genmoduleinfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
681 {
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
682 // 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
683 // {
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
684 // 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
685 // 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
686 // 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
687 // 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
688 //
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
689 // 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
690 // 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
691 // 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
692 //
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
693 // 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
694 // 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
695 // }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
696
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
697 // resolve ModuleInfo
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
698 assert(moduleinfo);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
699 DtoForceConstInitDsymbol(moduleinfo);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
700
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
701 // check for patch
810
67fcd9df8b79 Fixed ModuleInfo patch check, failed on 64bit
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
702 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
703 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
704 error("unpatched object.d detected, ModuleInfo incorrect");
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
705 fatal();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
706 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
707
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
708 // moduleinfo llvm struct type
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
709 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
710 // classinfo llvm struct type
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
711 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
712
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
713 // initializer vector
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
714 std::vector<LLConstant*> initVec;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
715 LLConstant* c = 0;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
716
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
717 // vtable
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
718 c = moduleinfo->ir.irStruct->vtbl;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
719 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
720
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
721 // 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
722 c = getNullPtr(getPtrToType(LLType::Int8Ty));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
723 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
724
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
725 // name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
726 char *name = toPrettyChars();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
727 c = DtoConstString(name);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
728 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
729
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
730 // importedModules[]
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
731 int aimports_dim = aimports.dim;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
732 std::vector<LLConstant*> importInits;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
733 for (size_t i = 0; i < aimports.dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
734 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
735 Module *m = (Module *)aimports.data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
736 if (!m->needModuleInfo())
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 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
738
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
739 // 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
740 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
741 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
742 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
743 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
744 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
745 importInits.push_back(m_gvar);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
746 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
747 // has import array?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
748 if (!importInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
749 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
750 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
751 c = llvm::ConstantArray::get(importArrTy, importInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
752 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
753 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
754 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
755 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
756 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
757 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType()));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
758 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
759 }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
760 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
761 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) );
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
762 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
763
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
764 // localClasses[]
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
765 ClassDeclarations aclasses;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
766 //printf("members->dim = %d\n", members->dim);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
767 for (size_t i = 0; i < members->dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
768 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
769 Dsymbol *member;
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
770
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
771 member = (Dsymbol *)members->data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
772 //printf("\tmember '%s'\n", member->toChars());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
773 member->addLocalClass(&aclasses);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
774 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
775 // fill inits
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
776 std::vector<LLConstant*> classInits;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
777 for (size_t i = 0; i < aclasses.dim; i++)
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
778 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
779 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i];
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
780 if (cd->isInterfaceDeclaration())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
781 {
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
782 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
783 continue;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
784 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
785 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
786 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
787 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
788 continue;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
789 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
790 Logger::println("class: %s", cd->toPrettyChars());
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
791 assert(cd->ir.irStruct->classInfo);
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
792 c = DtoBitCast(cd->ir.irStruct->classInfo, 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
793 classInits.push_back(c);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
794 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
795 // has class array?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
796 if (!classInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
797 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
798 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
799 c = llvm::ConstantArray::get(classArrTy, classInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
800 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
801 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
802 m_name.append("9__classesZ");
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
803 assert(gIR->module->getGlobalVariable(m_name) == NULL);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
804 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
805 c = DtoBitCast(m_gvar, getPtrToType(classinfoTy));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
806 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
807 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
808 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
809 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(classinfoTy)) );
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
810 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
811
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
812 // flags
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
813 c = DtoConstUint(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
814 if (!needmoduleinfo)
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
815 c = DtoConstUint(4); // flags (4 means MIstandalone)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
816 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
817
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
818 // 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
819 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
820
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
821 // ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
822 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
823 c = fctor ? fctor : getNullValue(fnptrTy);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
824 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
825
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
826 // dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
827 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
828 c = fdtor ? fdtor : getNullValue(fnptrTy);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
829 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
830
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
831 // unitTest
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
832 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
833 c = unittest ? unittest : getNullValue(fnptrTy);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
834 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
835
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
836 // 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
837 c = getNullValue(getVoidPtrType());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
838 initVec.push_back(c);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
839
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
840 // 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
841 c = getNullValue(fnptrTy);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
842 initVec.push_back(c);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
843
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
844 /*Logger::println("MODULE INFO INITIALIZERS");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
845 for (size_t i=0; i<initVec.size(); ++i)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
846 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
847 Logger::cout() << *initVec[i] << '\n';
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
848 if (initVec[i]->getType() != moduleinfoTy->getElementType(i))
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
849 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
850 }*/
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
851
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
852 // 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
853 LLConstant* constMI = llvm::ConstantStruct::get(initVec);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
854
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
855 // create name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
856 std::string MIname("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
857 MIname.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
858 MIname.append("8__ModuleZ");
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
859
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
860 // declare
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
861 // 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
862
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
863 llvm::GlobalVariable* gvar = gIR->module->getGlobalVariable(MIname);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
864 if (!gvar) gvar = new llvm::GlobalVariable(constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, NULL, MIname, gIR->module);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
865 else assert(gvar->getType()->getContainedType(0) == constMI->getType());
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
866 gvar->setInitializer(constMI);
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
867
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
868 // 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
869 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
870
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
871 // 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
872 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
873 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
874 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
875 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
876 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
877
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
878 // 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
879 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
880 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
881 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
882 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
883
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
884 // 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
885 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
886 std::vector<LLConstant*> appendInits(1, magicinit);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
887 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
888 std::string appendName("llvm.global_ctors");
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
889 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
890 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
891
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
892 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
893
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
894 void Dsymbol::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
895 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
896 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
897 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
898
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
899 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
900
751
dc8b8b7ea0c1 Fix compile-time warnings. Adjust include in d-asm-i386.
Christian Kamm <kamm incasoftware de>
parents: 737
diff changeset
901 void Declaration::toObjFile(int unused)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
902 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
903 Logger::println("Ignoring Declaration::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
904 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
905
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
906 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
907
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
908 void InterfaceDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
909 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
910 //Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
911 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
912 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
913
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
914 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
915
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
916 void StructDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
917 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
918 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
919 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
920
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
921 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
922
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
923 void ClassDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
924 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
925 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
926 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
927
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
928 /******************************************
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
929 * Get offset of base class's vtbl[] initializer from start of csym.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
930 * Returns ~0 if not this csym.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
931 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
932
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
933 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
934 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
935 return ~0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
936 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
937
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
938 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
939
732
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
940 void TupleDeclaration::toObjFile(int multiobj)
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
941 {
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
942 Logger::println("TupleDeclaration::toObjFile(): %s", toChars());
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
943
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
944 assert(isexp);
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
945 assert(objects);
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
946
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
947 int n = objects->dim;
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
948
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
949 for (int i=0; i < n; ++i)
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
950 {
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
951 DsymbolExp* exp = (DsymbolExp*)objects->data[i];
733
cc8ba72c0350 Nested access to with statement should work now. fixes #105
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 732
diff changeset
952 assert(exp->op == TOKdsymbol);
732
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
953 exp->s->toObjFile(multiobj);
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
954 }
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
955 }
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
956
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
957 /* ================================================================== */
6aeaef263289 Fixed tuple fields, thanx downs
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 722
diff changeset
958
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
959 void VarDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
960 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
961 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
962 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
963
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
964 if (aliassym)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
965 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
966 Logger::println("alias sym");
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
967 toAlias()->toObjFile(multiobj);
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
968 return;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
969 }
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
970
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
971 // global variable or magic
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
972 if (isDataseg())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
973 {
511
a0b0676e787d Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 499
diff changeset
974 Logger::println("data segment");
a0b0676e787d Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 499
diff changeset
975
766
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
976 #if DMDV2
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
977 if (storage_class & STCmanifest)
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
978 {
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
979 assert(0 && "manifest constant being codegened!!!");
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
980 }
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
981 #endif
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
982
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
983 // don't duplicate work
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
984 if (this->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
985 this->ir.resolved = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
986 this->ir.declared = true;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
987
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
988 this->ir.irGlobal = new IrGlobal(this);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
989
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
990 Logger::println("parent: %s (%s)", parent->toChars(), parent->kind());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
991
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
992 // handle static local variables
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
993 bool static_local = false;
766
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
994 #if DMDV2
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
995 // not sure why this is only needed for d2
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
996 bool _isconst = isConst() && init;
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
997 #else
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
998 bool _isconst = isConst();
766
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
999 #endif
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1000 Dsymbol* par = toParent2();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1001 if (par && par->isFuncDeclaration())
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1002 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1003 static_local = true;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1004 if (init && init->isExpInitializer()) {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1005 _isconst = false;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1006 }
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
1007 }
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1008
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1009 Logger::println("Creating global variable");
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
1010
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
1011 const LLType* _type = this->ir.irGlobal->type.get();
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
1012 llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
1013 std::string _name(mangle());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
1014
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
1015 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1016 this->ir.irGlobal->value = gvar;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1017
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
1018 if (Logger::enabled())
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
1019 Logger::cout() << *gvar << '\n';
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
1020
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
1021 if (static_local)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
1022 DtoConstInitGlobal(this);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
1023 else
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1024 gIR->constInitList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1025 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1026 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1027 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1028 // might already have its irField, as classes derive each other without getting copies of the VarDeclaration
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
1029 if (!ir.irField)
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
1030 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1031 assert(!ir.isSet());
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1032 ir.irField = new IrField(this);
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
1033 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1034 IrStruct* irstruct = gIR->topstruct();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1035 irstruct->addVar(this);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1036
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1037 Logger::println("added offset %u", offset);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1038 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1039 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1040
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1041 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1042
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
1043 void TypedefDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1044 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1045 static int tdi = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1046 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1047 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1048
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
1049 // generate typeinfo
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 251
diff changeset
1050 DtoTypeInfoOf(type, false);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1051 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1052
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1053 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1054
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
1055 void EnumDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1056 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
1057 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1058 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1059
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1060 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1061
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
1062 void FuncDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1063 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1064 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1065 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1066
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1067 /* ================================================================== */
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1068
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1069 void AnonDeclaration::toObjFile(int multiobj)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1070 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1071 Array *d = include(NULL, NULL);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1072
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1073 if (d)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1074 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1075 // get real aggregate parent
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1076 IrStruct* irstruct = gIR->topstruct();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1077
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1078 // push a block on the stack
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1079 irstruct->pushAnon(isunion);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1080
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1081 // go over children
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1082 for (unsigned i = 0; i < d->dim; i++)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1083 { Dsymbol *s = (Dsymbol *)d->data[i];
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1084 s->toObjFile(multiobj);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1085 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1086
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1087 // finish
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1088 irstruct->popAnon();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1089 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 766
diff changeset
1090 }