Mercurial > projects > ldc
annotate gen/toobj.cpp @ 686:363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 12 Oct 2008 14:38:55 +0200 |
parents | b411c41a9716 |
children | 06c05906b054 |
rev | line source |
---|---|
1 | 1 |
2 // Copyright (c) 1999-2004 by Digital Mars | |
3 // All Rights Reserved | |
4 // written by Walter Bright | |
5 // www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <cstddef> | |
11 #include <iostream> | |
12 #include <fstream> | |
13 | |
40 | 14 #include "gen/llvm.h" |
1 | 15 #include "llvm/Analysis/Verifier.h" |
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 | 18 #include "llvm/Target/TargetMachine.h" |
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" |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
23 #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
|
24 #include "llvm/System/Path.h" |
673
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
25 #include "llvm/Support/raw_ostream.h" |
1 | 26 |
27 #include "mars.h" | |
28 #include "module.h" | |
29 #include "mtype.h" | |
30 #include "declaration.h" | |
31 #include "statement.h" | |
32 #include "enum.h" | |
33 #include "aggregate.h" | |
34 #include "init.h" | |
35 #include "attrib.h" | |
36 #include "id.h" | |
37 #include "import.h" | |
38 #include "template.h" | |
18 | 39 #include "scope.h" |
1 | 40 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
41 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
42 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
43 #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
|
44 #include "gen/llvmhelpers.h" |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
63
diff
changeset
|
45 #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
|
46 #include "gen/structs.h" |
100 | 47 #include "gen/classes.h" |
48 #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
|
49 #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
|
50 #include "gen/runtime.h" |
1 | 51 |
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
|
52 #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
|
53 #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
|
54 |
1 | 55 ////////////////////////////////////////////////////////////////////////////////////////// |
56 | |
125 | 57 // in gen/optimize.cpp |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
650
diff
changeset
|
58 void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline); |
125 | 59 |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
60 // fwd decl |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
61 void write_asm_to_file(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
|
62 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
|
63 |
125 | 64 ////////////////////////////////////////////////////////////////////////////////////////// |
65 | |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
66 void Module::genobjfile(int multiobj, char** envp) |
1 | 67 { |
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
|
68 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
|
69 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
|
70 { |
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 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
|
72 } |
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 |
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
|
74 Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars())); |
1 | 75 LOG_SCOPE; |
76 | |
626
e83ba4ae4878
Fix import visibility bugs 313 and 314.
Christian Kamm <kamm incasoftware de>
parents:
622
diff
changeset
|
77 // 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
|
78 |
6 | 79 // start by deleting the old object file |
1 | 80 deleteObjFile(); |
81 | |
18 | 82 // 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
|
83 // TODO look at making the instance static and moving most functionality into IrModule where it belongs |
1 | 84 IRState ir; |
85 gIR = &ir; | |
86 ir.dmodule = this; | |
87 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
88 // 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
|
89 IrDsymbol::resetAll(); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
90 IrType::resetAll(); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
91 |
6 | 92 // name the module |
1 | 93 std::string mname(toChars()); |
94 if (md != 0) | |
95 mname = md->toChars(); | |
96 ir.module = new llvm::Module(mname); | |
97 | |
683
b411c41a9716
Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
98 // module ir state |
b411c41a9716
Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
99 // 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
|
100 //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
|
101 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
|
102 |
6 | 103 // set target stuff |
1 | 104 std::string target_triple(global.params.tt_arch); |
105 target_triple.append(global.params.tt_os); | |
106 ir.module->setTargetTriple(target_triple); | |
107 ir.module->setDataLayout(global.params.data_layout); | |
108 | |
583
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
109 gTargetData = new llvm::TargetData(global.params.data_layout); |
1 | 110 |
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
|
111 // 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
|
112 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
|
113 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
|
114 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
|
115 } |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
116 |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
117 // start out by providing opaque for the built-in class types |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
118 if (!ClassDeclaration::object->type->ir.type) |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
119 ClassDeclaration::object->type->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get()); |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
120 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
121 if (!Type::typeinfo->type->ir.type) |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
122 Type::typeinfo->type->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get()); |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
123 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
124 if (!ClassDeclaration::classinfo->type->ir.type) |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
125 ClassDeclaration::classinfo->type->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get()); |
103
855adfdb8d38
[svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents:
102
diff
changeset
|
126 |
6 | 127 // process module members |
1 | 128 for (int k=0; k < members->dim; k++) { |
129 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
130 assert(dsym); | |
336 | 131 dsym->toObjFile(multiobj); |
1 | 132 } |
133 | |
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
|
134 // main driver loop |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
135 DtoEmptyAllLists(); |
89 | 136 // generate ModuleInfo |
137 genmoduleinfo(); | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
138 // do this again as moduleinfo might have pulled something in! |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
139 DtoEmptyAllLists(); |
89 | 140 |
250
fc9c1a0eabbd
[svn r267] Fixed debug info for global variables.
lindquist
parents:
248
diff
changeset
|
141 // 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
|
142 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
|
143 { |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 } |
250
fc9c1a0eabbd
[svn r267] Fixed debug info for global variables.
lindquist
parents:
248
diff
changeset
|
149 |
6 | 150 // verify the llvm |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
151 if (!global.params.novalidate) { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
152 std::string verifyErr; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
153 Logger::println("Verifying module..."); |
117 | 154 LOG_SCOPE; |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
155 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
156 { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
157 error("%s", verifyErr.c_str()); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
158 fatal(); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
159 } |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
160 else { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
161 Logger::println("Verification passed!"); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
162 } |
1 | 163 } |
164 | |
125 | 165 // run optimizer |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
650
diff
changeset
|
166 ldc_optimize_module(ir.module, global.params.optimizeLevel, global.params.llvmInline); |
1 | 167 |
605
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
168 // verify the llvm |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
169 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
|
170 std::string verifyErr; |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
171 Logger::println("Verifying module... again..."); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
172 LOG_SCOPE; |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
173 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
|
174 { |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
175 error("%s", verifyErr.c_str()); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
176 fatal(); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
177 } |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
178 else { |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
179 Logger::println("Verification passed!"); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
180 } |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
181 } |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
182 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
183 // 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
|
184 typedef llvm::sys::Path LLPath; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
185 |
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
|
186 // 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 std::ofstream bos(bcpath.c_str(), std::ios::binary); |
52 | 193 llvm::WriteBitcodeToFile(ir.module, bos); |
194 } | |
1 | 195 |
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
|
196 // 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 ir.module->print(aos, NULL); |
52 | 204 } |
1 | 205 |
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
|
206 // write native assembly |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
207 LLPath spath = 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
|
208 spath.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
|
209 spath.appendSuffix(std::string(global.s_ext)); |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
210 if (!global.params.output_s) { |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
211 spath.createTemporaryFileOnDisk(); |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
212 } |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
213 Logger::println("Writing native asm to: %s\n", spath.c_str()); |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
214 std::string err; |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
215 { |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
216 llvm::raw_fd_ostream out(spath.c_str(), err); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
217 write_asm_to_file(*ir.module, out); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
218 } |
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
|
219 |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
220 // call gcc to convert assembly to object file |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
221 LLPath objpath = LLPath(objfile->name->toChars()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
222 assemble(spath, objpath, envp); |
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
|
223 |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
224 if (!global.params.output_s) { |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
225 spath.eraseFromDisk(); |
673
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
226 } |
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
227 |
1 | 228 delete ir.module; |
125 | 229 gTargetData = 0; |
1 | 230 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
|
231 |
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
|
232 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
|
233 { |
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
|
234 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
|
235 } |
1 | 236 } |
237 | |
238 /* ================================================================== */ | |
239 | |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
240 // based on llc code, University of Illinois Open Source License |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
241 void write_asm_to_file(llvm::Module& m, llvm::raw_fd_ostream& out) |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
242 { |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
243 using namespace llvm; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
244 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
245 std::string Err; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
246 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
247 const TargetMachineRegistry::entry* MArch; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
248 MArch = TargetMachineRegistry::getClosestStaticTargetForModule(m, Err); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
249 if (MArch == 0) { |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
250 error("error auto-selecting target for module '%s'", Err.c_str()); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
251 fatal(); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
252 } |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
253 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
254 SubtargetFeatures Features; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
255 //TODO: Features? |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
256 // Features.setCPU(MCPU); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
257 // for (unsigned i = 0; i != MAttrs.size(); ++i) |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
258 // Features.AddFeature(MAttrs[i]); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
259 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
260 //FIXME: Only set this if required? |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
261 TargetMachine::setRelocationModel(Reloc::PIC_); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
262 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
263 std::auto_ptr<TargetMachine> target(MArch->CtorFn(m, Features.getString())); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
264 assert(target.get() && "Could not allocate target machine!"); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
265 TargetMachine &Target = *target.get(); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
266 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
267 // 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
|
268 ExistingModuleProvider Provider(&m); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
269 FunctionPassManager Passes(&Provider); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
270 //FIXME: Will gTargetData always be Target.getTargetData anyway? |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
271 assert(gTargetData->getStringRepresentation() == Target.getTargetData()->getStringRepresentation()); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
272 Passes.add(new TargetData(*Target.getTargetData())); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
273 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
274 // 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
|
275 MachineCodeEmitter *MCE = 0; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
276 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
277 //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
|
278 bool Fast = false; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
279 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
|
280 assert(mod == FileModel::AsmFile); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
281 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
282 bool err = Target.addPassesToEmitFileFinish(Passes, MCE, Fast); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
283 assert(!err); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
284 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
285 Passes.doInitialization(); |
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 // 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
|
288 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
|
289 if (!I->isDeclaration()) |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
290 Passes.run(*I); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
291 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
292 Passes.doFinalization(); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
293 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
294 // release module from module provider so we can delete it ourselves |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
295 llvm::Module* rmod = Provider.releaseModule(&Err); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
296 assert(rmod); |
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 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
299 /* ================================================================== */ |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
300 |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
301 // helper functions for gcc call to assemble |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
302 // 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
|
303 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
304 /// 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
|
305 /// 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
|
306 /// without affecting the process's real environment. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
307 /// |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
308 /// Inputs: |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
309 /// 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
|
310 /// |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
311 /// Return value: |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
312 /// NULL - An error occurred. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
313 /// |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
314 /// 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
|
315 /// 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
|
316 /// 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
|
317 /// |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
318 static char ** CopyEnv(char ** const envp) { |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
319 // 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
|
320 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
|
321 for (entries = 0; envp[entries] != NULL; entries++) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
322 /*empty*/; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
323 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
324 // 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
|
325 ++entries; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
326 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
327 // 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
|
328 if (entries == 0) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
329 return NULL; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
330 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
331 // Allocate a new environment list. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
332 char **newenv = new char* [entries]; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
333 if ((newenv = new char* [entries]) == NULL) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
334 return NULL; |
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 // 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
|
337 entries = 0; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
338 while (envp[entries] != NULL) { |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
339 newenv[entries] = new char[strlen (envp[entries]) + 1]; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
340 strcpy (newenv[entries], envp[entries]); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
341 ++entries; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
342 } |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
343 newenv[entries] = NULL; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
344 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
345 return newenv; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
346 } |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
347 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
348 // 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
|
349 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
350 /// 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
|
351 /// array. |
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 /// Inputs: |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
354 /// 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
|
355 /// 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
|
356 /// |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
357 /// Notes: |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
358 /// 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
|
359 /// 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
|
360 /// 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
|
361 /// undocumented if they do exist). |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
362 /// |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
363 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
|
364 for (unsigned index=0; envp[index] != NULL; index++) { |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
365 // 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
|
366 char *p = strchr (envp[index], '='); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
367 if (p == NULL) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
368 continue; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
369 else |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
370 *p = '\0'; |
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 // 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
|
373 // Otherwise, restore it. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
374 if (!strcmp(name, envp[index])) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
375 *envp[index] = '\0'; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
376 else |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
377 *p = '='; |
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 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
380 return; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
381 } |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
382 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
383 // 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
|
384 // 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
|
385 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
|
386 { |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
387 using namespace llvm; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
388 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
389 sys::Path gcc = llvm::sys::Program::FindProgramByName("gcc"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
390 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
391 // 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
|
392 // 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
|
393 // 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
|
394 // themselves identically. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
395 // |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
396 // 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
|
397 // configuration. Hence, we must sanitize its environment. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
398 char ** clean_env = CopyEnv(envp); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
399 if (clean_env == NULL) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
400 return; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
401 RemoveEnv("LIBRARY_PATH", clean_env); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
402 RemoveEnv("COLLECT_GCC_OPTIONS", clean_env); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
403 RemoveEnv("GCC_EXEC_PREFIX", clean_env); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
404 RemoveEnv("COMPILER_PATH", clean_env); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
405 RemoveEnv("COLLECT_GCC", clean_env); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
406 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
407 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
408 // 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
|
409 // |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
410 // Note: |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
411 // 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
|
412 // 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
|
413 // GCC mysteriously knows how to do it. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
414 std::vector<std::string> args; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
415 args.push_back(gcc.toString()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
416 args.push_back("-fno-strict-aliasing"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
417 args.push_back("-O3"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
418 args.push_back("-c"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
419 args.push_back("-xassembler"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
420 args.push_back(asmpath.toString()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
421 args.push_back("-o"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
422 args.push_back(objpath.toString()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
423 |
677
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
424 //FIXME: only use this if needed? |
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
425 args.push_back("-fpic"); |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
426 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
427 // 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
|
428 // 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
|
429 // 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
|
430 std::vector<const char *> Args; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
431 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
|
432 Args.push_back(args[i].c_str()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
433 Args.push_back(0); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
434 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
435 Logger::println("Assembling with: "); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
436 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
|
437 std::ostream& logstr = Logger::cout(); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
438 for (; I != E; ++I) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
439 if (*I) |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
440 logstr << "'" << *I << "'" << " "; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
441 logstr << "\n" << std::flush; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
442 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
443 // Run the compiler to assembly the program. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
444 std::string ErrMsg; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
445 int R = sys::Program::ExecuteAndWait( |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
446 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
|
447 delete [] clean_env; |
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 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
450 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
451 /* ================================================================== */ |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
452 |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
453 // 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
|
454 // 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
|
455 #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
|
456 #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
|
457 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
458 // build module ctor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
459 |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
460 llvm::Function* build_module_ctor() |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
461 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
462 if (gIR->ctors.empty()) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
463 return NULL; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
464 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
465 size_t n = gIR->ctors.size(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
466 if (n == 1) |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
467 return gIR->ctors[0]->ir.irFunc->func; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
468 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
469 std::string name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
470 name.append(gIR->dmodule->mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
471 name.append("6__ctorZ"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
472 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
473 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
|
474 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); |
184 | 475 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
|
476 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
477 fn->setCallingConv(llvm::CallingConv::Fast); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
478 |
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
|
479 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
|
480 IRBuilder<> builder(bb); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
481 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
482 // 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
488 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
489 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
|
490 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
|
491 llvm::CallInst* call = builder.CreateCall(f,""); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
492 call->setCallingConv(llvm::CallingConv::Fast); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
493 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
494 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
495 // 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
|
496 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
|
497 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
|
498 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
499 builder.CreateRetVoid(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
500 return fn; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
501 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
502 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
503 // build module dtor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
504 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
505 static llvm::Function* build_module_dtor() |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
506 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
507 if (gIR->dtors.empty()) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
508 return NULL; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
509 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
510 size_t n = gIR->dtors.size(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
511 if (n == 1) |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
512 return gIR->dtors[0]->ir.irFunc->func; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
513 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
514 std::string name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
515 name.append(gIR->dmodule->mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
516 name.append("6__dtorZ"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
517 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
518 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
|
519 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); |
184 | 520 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
|
521 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
522 fn->setCallingConv(llvm::CallingConv::Fast); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
523 |
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
|
524 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
|
525 IRBuilder<> builder(bb); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
526 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
527 // 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
533 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
534 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
|
535 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
|
536 llvm::CallInst* call = builder.CreateCall(f,""); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
537 call->setCallingConv(llvm::CallingConv::Fast); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
538 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
539 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
540 // 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
|
541 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
|
542 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
|
543 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
544 builder.CreateRetVoid(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
545 return fn; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
546 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
547 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
548 // build module unittest |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
549 |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
550 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
|
551 { |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
552 if (gIR->unitTests.empty()) |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
553 return NULL; |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
554 |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
555 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
|
556 if (n == 1) |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
557 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
|
558 |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
559 std::string name("_D"); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
560 name.append(gIR->dmodule->mangle()); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
561 name.append("10__unittestZ"); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
562 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
563 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
|
564 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); |
184 | 565 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
|
566 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
567 fn->setCallingConv(llvm::CallingConv::Fast); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
568 |
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
|
569 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
|
570 IRBuilder<> builder(bb); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
571 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
572 // 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
578 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
579 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
|
580 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
|
581 llvm::CallInst* call = builder.CreateCall(f,""); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
582 call->setCallingConv(llvm::CallingConv::Fast); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
583 } |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
584 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
585 // 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
|
586 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
|
587 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
|
588 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
589 builder.CreateRetVoid(); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
590 return fn; |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
591 } |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
592 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
593 // 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
|
594 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
|
595 { |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
596 // 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
|
597 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
|
598 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
599 // 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
|
600 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
|
601 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
|
602 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
|
603 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
604 // 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
|
605 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
|
606 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
607 // 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
|
608 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
|
609 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
|
610 mrefvalues.push_back(LLConstant::getNullValue(modulerefTy->getContainedType(0))); |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
611 mrefvalues.push_back(moduleinfo); |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
612 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
|
613 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
614 // 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
620 // 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
|
621 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
|
622 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
|
623 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
|
624 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
625 // 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
|
626 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
|
627 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
|
628 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
629 // 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
635 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
636 // 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
|
637 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
|
638 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
639 // 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
|
640 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
|
641 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
|
642 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
643 // 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
|
644 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
|
645 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
646 // 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
|
647 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
|
648 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
|
649 |
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 // return |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
651 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
|
652 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
653 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
|
654 } |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
655 |
1 | 656 // Put out instance of ModuleInfo for this Module |
657 | |
658 void Module::genmoduleinfo() | |
659 { | |
89 | 660 // The layout is: |
661 // { | |
662 // void **vptr; | |
663 // monitor_t monitor; | |
664 // char[] name; // class name | |
665 // ModuleInfo importedModules[]; | |
666 // ClassInfo localClasses[]; | |
667 // uint flags; // initialization state | |
668 // void *ctor; | |
669 // void *dtor; | |
670 // void *unitTest; | |
671 // } | |
672 | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
673 // resolve ModuleInfo |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
674 assert(moduleinfo); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
675 DtoForceConstInitDsymbol(moduleinfo); |
89 | 676 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
677 // moduleinfo llvm struct type |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
678 const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get()); |
89 | 679 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
680 // classinfo llvm struct type |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
681 const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get()); |
89 | 682 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
683 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
684 std::vector<LLConstant*> initVec; |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
685 LLConstant* c = 0; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
686 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
687 // vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
688 c = moduleinfo->ir.irStruct->vtbl; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
689 initVec.push_back(c); |
89 | 690 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
691 // 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
|
692 c = getNullPtr(getPtrToType(LLType::Int8Ty)); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
693 initVec.push_back(c); |
89 | 694 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
695 // name |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
696 char *name = toPrettyChars(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
697 c = DtoConstString(name); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
698 initVec.push_back(c); |
89 | 699 |
700 // importedModules[] | |
701 int aimports_dim = aimports.dim; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
702 std::vector<LLConstant*> importInits; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
703 for (size_t i = 0; i < aimports.dim; i++) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
704 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
705 Module *m = (Module *)aimports.data[i]; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
706 if (!m->needModuleInfo()) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
707 aimports_dim--; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
708 else { // declare |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
709 // create name |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
710 std::string m_name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
711 m_name.append(m->mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
712 m_name.append("8__ModuleZ"); |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
157
diff
changeset
|
713 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
|
714 if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
715 importInits.push_back(m_gvar); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
716 } |
89 | 717 } |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
718 // has import array? |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
719 if (!importInits.empty()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
720 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
721 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
|
722 c = llvm::ConstantArray::get(importArrTy, importInits); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
723 std::string m_name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
724 m_name.append(mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType())); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
729 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
730 } |
89 | 731 else |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
732 c = moduleinfo->ir.irStruct->constInit->getOperand(3); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
733 initVec.push_back(c); |
89 | 734 |
735 // localClasses[] | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
736 ClassDeclarations aclasses; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
737 //printf("members->dim = %d\n", members->dim); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
738 for (size_t i = 0; i < members->dim; i++) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
739 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
740 Dsymbol *member; |
89 | 741 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
742 member = (Dsymbol *)members->data[i]; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
743 //printf("\tmember '%s'\n", member->toChars()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
744 member->addLocalClass(&aclasses); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
745 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
746 // fill inits |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
747 std::vector<LLConstant*> classInits; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
748 for (size_t i = 0; i < aclasses.dim; i++) |
89 | 749 { |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
750 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
|
751 if (cd->isInterfaceDeclaration()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
752 { |
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
|
753 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
|
754 continue; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
755 } |
132 | 756 Logger::println("class: %s", cd->toPrettyChars()); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
757 assert(cd->ir.irStruct->classInfo); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
758 classInits.push_back(cd->ir.irStruct->classInfo); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
759 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
760 // has class array? |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
761 if (!classInits.empty()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
762 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
763 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
|
764 c = llvm::ConstantArray::get(classArrTy, classInits); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
765 std::string m_name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
766 m_name.append(mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
767 m_name.append("9__classesZ"); |
184 | 768 assert(gIR->module->getGlobalVariable(m_name) == NULL); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
769 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, 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
|
770 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(classArrTy->getElementType())); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
771 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
772 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
773 else |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
774 c = moduleinfo->ir.irStruct->constInit->getOperand(4); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
775 initVec.push_back(c); |
89 | 776 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
777 // flags |
132 | 778 c = DtoConstUint(0); |
779 if (!needmoduleinfo) | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
780 c = DtoConstUint(4); // flags (4 means MIstandalone) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
781 initVec.push_back(c); |
89 | 782 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
783 // ctor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
784 llvm::Function* fctor = build_module_ctor(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
785 c = fctor ? fctor : moduleinfo->ir.irStruct->constInit->getOperand(6); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
786 initVec.push_back(c); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
787 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
788 // dtor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
789 llvm::Function* fdtor = build_module_dtor(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
790 c = fdtor ? fdtor : moduleinfo->ir.irStruct->constInit->getOperand(7); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
791 initVec.push_back(c); |
89 | 792 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
793 // unitTest |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
794 llvm::Function* unittest = build_module_unittest(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
795 c = unittest ? unittest : moduleinfo->ir.irStruct->constInit->getOperand(8); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
796 initVec.push_back(c); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
797 |
132 | 798 // xgetMembers |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
799 c = moduleinfo->ir.irStruct->constInit->getOperand(9); |
132 | 800 initVec.push_back(c); |
801 | |
802 // ictor | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
803 c = moduleinfo->ir.irStruct->constInit->getOperand(10); |
132 | 804 initVec.push_back(c); |
805 | |
806 /*Logger::println("MODULE INFO INITIALIZERS"); | |
807 for (size_t i=0; i<initVec.size(); ++i) | |
808 { | |
809 Logger::cout() << *initVec[i] << '\n'; | |
810 if (initVec[i]->getType() != moduleinfoTy->getElementType(i)) | |
811 assert(0); | |
812 }*/ | |
813 | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
814 // create initializer |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
815 LLConstant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec); |
89 | 816 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
817 // create name |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
818 std::string MIname("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
819 MIname.append(mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
820 MIname.append("8__ModuleZ"); |
89 | 821 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
822 // declare |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
823 // flags will be modified at runtime so can't make it constant |
184 | 824 |
825 llvm::GlobalVariable* gvar = gIR->module->getGlobalVariable(MIname); | |
826 if (!gvar) gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, MIname, gIR->module); | |
827 gvar->setInitializer(constMI); | |
117 | 828 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
829 // 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
|
830 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
|
831 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
832 // 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
839 // 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
|
840 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
|
841 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
|
842 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
|
843 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
|
844 |
117 | 845 // 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
|
846 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
|
847 std::vector<LLConstant*> appendInits(1, magicinit); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
848 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
|
849 std::string appendName("llvm.global_ctors"); |
117 | 850 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); |
1 | 851 } |
852 | |
853 /* ================================================================== */ | |
854 | |
336 | 855 void Dsymbol::toObjFile(int multiobj) |
1 | 856 { |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
857 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars()); |
1 | 858 } |
859 | |
860 /* ================================================================== */ | |
861 | |
862 void Declaration::toObjFile() | |
863 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
864 Logger::println("Ignoring Declaration::toObjFile for %s", toChars()); |
1 | 865 } |
866 | |
867 /* ================================================================== */ | |
868 | |
336 | 869 void InterfaceDeclaration::toObjFile(int multiobj) |
1 | 870 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
871 //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
|
872 gIR->resolveList.push_back(this); |
1 | 873 } |
874 | |
875 /* ================================================================== */ | |
876 | |
336 | 877 void StructDeclaration::toObjFile(int multiobj) |
1 | 878 { |
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
|
879 gIR->resolveList.push_back(this); |
1 | 880 } |
881 | |
882 /* ================================================================== */ | |
883 | |
336 | 884 void ClassDeclaration::toObjFile(int multiobj) |
1 | 885 { |
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
|
886 gIR->resolveList.push_back(this); |
1 | 887 } |
888 | |
889 /****************************************** | |
890 * Get offset of base class's vtbl[] initializer from start of csym. | |
891 * Returns ~0 if not this csym. | |
892 */ | |
893 | |
894 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc) | |
895 { | |
896 return ~0; | |
897 } | |
898 | |
899 /* ================================================================== */ | |
900 | |
336 | 901 void VarDeclaration::toObjFile(int multiobj) |
1 | 902 { |
40 | 903 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars()); |
1 | 904 LOG_SCOPE; |
905 | |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
906 if (aliassym) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
907 { |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
908 Logger::println("alias sym"); |
336 | 909 toAlias()->toObjFile(multiobj); |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
910 return; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
911 } |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
912 |
1 | 913 // global variable or magic |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
914 if (isDataseg()) |
1 | 915 { |
511
a0b0676e787d
Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
499
diff
changeset
|
916 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
|
917 |
132 | 918 // don't duplicate work |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
919 if (this->ir.resolved) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
920 this->ir.resolved = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
921 this->ir.declared = true; |
40 | 922 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
923 this->ir.irGlobal = new IrGlobal(this); |
100 | 924 |
925 Logger::println("parent: %s (%s)", parent->toChars(), parent->kind()); | |
926 | |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
927 // handle static local variables |
100 | 928 bool static_local = false; |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
929 bool _isconst = isConst(); |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
930 if (parent && parent->isFuncDeclaration()) |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
931 { |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
932 static_local = true; |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
933 if (init && init->isExpInitializer()) { |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
934 _isconst = false; |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
935 } |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
936 } |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
937 |
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
139
diff
changeset
|
938 Logger::println("Creating global variable"); |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
939 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
940 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
|
941 llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
942 std::string _name(mangle()); |
52 | 943 |
100 | 944 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
|
945 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
|
946 |
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
|
947 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
|
948 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
|
949 |
100 | 950 if (static_local) |
951 DtoConstInitGlobal(this); | |
952 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
|
953 gIR->constInitList.push_back(this); |
1 | 954 } |
955 | |
956 // inside aggregate declaration. declare a field. | |
957 else | |
958 { | |
959 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | |
960 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
961 const LLType* _type = DtoType(type); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
962 this->ir.irField = new IrField(this); |
73 | 963 |
964 // add the field in the IRStruct | |
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
|
965 gIR->topstruct()->offsets.insert(std::make_pair(offset, IrStruct::Offset(this, _type))); |
1 | 966 } |
967 | |
968 Logger::println("VarDeclaration::toObjFile is done"); | |
969 } | |
970 | |
971 /* ================================================================== */ | |
972 | |
336 | 973 void TypedefDeclaration::toObjFile(int multiobj) |
1 | 974 { |
975 static int tdi = 0; | |
976 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars()); | |
977 LOG_SCOPE; | |
978 | |
52 | 979 // generate typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
251
diff
changeset
|
980 DtoTypeInfoOf(type, false); |
1 | 981 } |
982 | |
983 /* ================================================================== */ | |
984 | |
336 | 985 void EnumDeclaration::toObjFile(int multiobj) |
1 | 986 { |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
987 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); |
1 | 988 } |
989 | |
990 /* ================================================================== */ | |
991 | |
336 | 992 void FuncDeclaration::toObjFile(int multiobj) |
1 | 993 { |
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
|
994 gIR->resolveList.push_back(this); |
1 | 995 } |