Mercurial > projects > ldc
annotate gen/toobj.cpp @ 1578:1dee66f6ec0b
Removed a chunk of code in favour of a shorter and more portable method
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 08 Sep 2009 11:21:30 +0100 |
parents | 299a6b634178 |
children | 40bd4a0d4870 |
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 <fstream> | |
12 | |
40 | 13 #include "gen/llvm.h" |
1 | 14 #include "llvm/Analysis/Verifier.h" |
15 #include "llvm/Bitcode/ReaderWriter.h" | |
673
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
16 #include "llvm/Module.h" |
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
17 #include "llvm/ModuleProvider.h" |
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
18 #include "llvm/PassManager.h" |
689
06c05906b054
Always run SimplifyCFG to workaround LLVM bug 2613.
Christian Kamm <kamm incasoftware de>
parents:
686
diff
changeset
|
19 #include "llvm/LinkAllPasses.h" |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
20 #include "llvm/System/Program.h" |
673
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
21 #include "llvm/Support/raw_ostream.h" |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
22 #include "llvm/Support/CommandLine.h" |
1541
1e7a09548e67
Target.addPassesToEmitFile takes a formatted_raw_ostream now
Benjamin Kramer <benny.kra@gmail.com>
parents:
1535
diff
changeset
|
23 #include "llvm/Support/FormattedStream.h" |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
24 #include "llvm/Target/TargetMachine.h" |
1 | 25 |
26 #include "mars.h" | |
27 #include "module.h" | |
28 #include "mtype.h" | |
29 #include "declaration.h" | |
30 #include "statement.h" | |
31 #include "enum.h" | |
32 #include "aggregate.h" | |
33 #include "init.h" | |
34 #include "attrib.h" | |
35 #include "id.h" | |
36 #include "import.h" | |
37 #include "template.h" | |
18 | 38 #include "scope.h" |
1 | 39 |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
40 #include "gen/abi.h" |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
63
diff
changeset
|
41 #include "gen/arrays.h" |
100 | 42 #include "gen/classes.h" |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
43 #include "gen/cl_options.h" |
100 | 44 #include "gen/functions.h" |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
45 #include "gen/irstate.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
46 #include "gen/llvmhelpers.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
47 #include "gen/logger.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
48 #include "gen/optimizer.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
49 #include "gen/programs.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
50 #include "gen/rttibuilder.h" |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
51 #include "gen/runtime.h" |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
52 #include "gen/structs.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
53 #include "gen/todebug.h" |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
54 #include "gen/tollvm.h" |
1 | 55 |
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
|
56 #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
|
57 #include "ir/irmodule.h" |
1364
46f6365a50d7
Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1341
diff
changeset
|
58 #include "ir/irtype.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
|
59 |
1 | 60 ////////////////////////////////////////////////////////////////////////////////////////// |
61 | |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
62 static llvm::cl::opt<bool> noVerify("noverify", |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
63 llvm::cl::desc("Do not run the validation pass before writing bitcode"), |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
64 llvm::cl::ZeroOrMore); |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
65 |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
66 ////////////////////////////////////////////////////////////////////////////////////////// |
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
67 |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
68 // fwd decl |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
69 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out); |
849
ba390e5e9150
Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents:
824
diff
changeset
|
70 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath); |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
71 |
125 | 72 ////////////////////////////////////////////////////////////////////////////////////////// |
73 | |
1535
61f12f4651b5
Don't use llvm::getGlobalContext() anymore
Benjamin Kramer <benny.kra@gmail.com>
parents:
1534
diff
changeset
|
74 llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir) |
1 | 75 { |
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
|
76 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
|
77 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
|
78 { |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
79 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
|
80 } |
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
|
81 |
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
|
82 Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars())); |
1 | 83 LOG_SCOPE; |
84 | |
1364
46f6365a50d7
Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1341
diff
changeset
|
85 if (global.params.verbose_cg) |
46f6365a50d7
Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1341
diff
changeset
|
86 printf("codegen: %s (%s)\n", toPrettyChars(), 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
|
87 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
88 assert(!global.errors); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
89 |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
90 // name the module |
1572
30bdcfb8299e
Avoid some unecessary heap allocations by using llvm's StringRef class.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1571
diff
changeset
|
91 llvm::StringRef mname(toChars()); |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
92 if (md != 0) |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
93 mname = md->toChars(); |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
94 |
18 | 95 // 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
|
96 // TODO look at making the instance static and moving most functionality into IrModule where it belongs |
1535
61f12f4651b5
Don't use llvm::getGlobalContext() anymore
Benjamin Kramer <benny.kra@gmail.com>
parents:
1534
diff
changeset
|
97 IRState ir(new llvm::Module(mname, context)); |
1 | 98 gIR = &ir; |
99 ir.dmodule = this; | |
100 | |
1247
2a92c115461d
Disabled resetting types between modules MAO (more at once). Fixes guaranteed MOA compilation segfault.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1241
diff
changeset
|
101 // reset all IR data stored in Dsymbols |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
102 IrDsymbol::resetAll(); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
103 |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
104 sir->setState(&ir); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
105 |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
106 // set target triple |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
107 ir.module->setTargetTriple(global.params.targetTriple); |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
733
diff
changeset
|
108 |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
733
diff
changeset
|
109 // set final data layout |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
110 ir.module->setDataLayout(global.params.dataLayout); |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
733
diff
changeset
|
111 if (Logger::enabled()) |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
112 Logger::cout() << "Final data layout: " << global.params.dataLayout << '\n'; |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
113 |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
114 // allocate the target abi |
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
986
diff
changeset
|
115 gABI = TargetABI::getTarget(); |
1 | 116 |
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
|
117 // 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
|
118 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
|
119 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
|
120 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
|
121 } |
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
|
122 |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
123 // handle invalid 'objectø module |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
124 if (!ClassDeclaration::object) { |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
125 error("is missing 'class Object'"); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
126 fatal(); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
127 } |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
128 if (!ClassDeclaration::classinfo) { |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
129 error("is missing 'class ClassInfo'"); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
130 fatal(); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
131 } |
1161
f528e55fb32f
Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
132 |
f528e55fb32f
Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
133 LLVM_D_InitRuntime(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
751
diff
changeset
|
134 |
6 | 135 // process module members |
1 | 136 for (int k=0; k < members->dim; k++) { |
137 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
138 assert(dsym); | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
139 dsym->codegen(sir); |
1 | 140 } |
141 | |
1163
ea52660f828b
Emit function bodies before generating the module info to make sure static
Christian Kamm <kamm incasoftware de>
parents:
1161
diff
changeset
|
142 // emit function bodies |
ea52660f828b
Emit function bodies before generating the module info to make sure static
Christian Kamm <kamm incasoftware de>
parents:
1161
diff
changeset
|
143 sir->emitFunctionBodies(); |
ea52660f828b
Emit function bodies before generating the module info to make sure static
Christian Kamm <kamm incasoftware de>
parents:
1161
diff
changeset
|
144 |
1478
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
145 // for singleobj-compilation, fully emit all seen template instances |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
146 if (opts::singleObj) |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
147 { |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
148 while (!ir.seenTemplateInstances.empty()) |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
149 { |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
150 IRState::TemplateInstanceSet::iterator it, end = ir.seenTemplateInstances.end(); |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
151 for (it = ir.seenTemplateInstances.begin(); it != end; ++it) |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
152 (*it)->codegen(sir); |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
153 ir.seenTemplateInstances.clear(); |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
154 |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
155 // emit any newly added function bodies |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
156 sir->emitFunctionBodies(); |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
157 } |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
158 } |
4dca8ed9d8b7
Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents:
1467
diff
changeset
|
159 |
89 | 160 // generate ModuleInfo |
1241
fc579f389f9a
!ClassInfo instances were not mutable, this is necessary for .classinfo based locking to work. !ModuleInfo generation was commented out as well.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
161 genmoduleinfo(); |
89 | 162 |
250
fc9c1a0eabbd
[svn r267] Fixed debug info for global variables.
lindquist
parents:
248
diff
changeset
|
163 // 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
|
164 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
|
165 { |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
166 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
|
167 LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray); |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
168 LLGlobalVariable* usedArray = new LLGlobalVariable(*ir.module, usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used"); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
169 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
|
170 } |
250
fc9c1a0eabbd
[svn r267] Fixed debug info for global variables.
lindquist
parents:
248
diff
changeset
|
171 |
6 | 172 // verify the llvm |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
951
diff
changeset
|
173 if (!noVerify) { |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
174 std::string verifyErr; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
175 Logger::println("Verifying module..."); |
117 | 176 LOG_SCOPE; |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
177 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
178 { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
179 error("%s", verifyErr.c_str()); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
180 fatal(); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
181 } |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
182 else { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
183 Logger::println("Verification passed!"); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
184 } |
1 | 185 } |
186 | |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
187 gIR = NULL; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
188 |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
189 if (llvmForceLogging && !logenabled) |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
190 { |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
191 Logger::disable(); |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
192 } |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
193 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
194 sir->setState(NULL); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
195 |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
196 return ir.module; |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
197 } |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
198 |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
199 void writeModule(llvm::Module* m, std::string filename) |
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
200 { |
125 | 201 // run optimizer |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
1163
diff
changeset
|
202 bool reverify = ldc_optimize_module(m); |
1 | 203 |
605
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
204 // verify the llvm |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
1163
diff
changeset
|
205 if (!noVerify && reverify) { |
605
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
206 std::string verifyErr; |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
207 Logger::println("Verifying module... again..."); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
208 LOG_SCOPE; |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
209 if (llvm::verifyModule(*m,llvm::ReturnStatusAction,&verifyErr)) |
605
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
210 { |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
211 //error("%s", verifyErr.c_str()); |
605
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
212 fatal(); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
213 } |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
214 else { |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
215 Logger::println("Verification passed!"); |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
216 } |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
217 } |
e235b80c92bc
Removed useless assert in ArrayLiteralExp::toConstElem
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
218 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
219 // 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
|
220 typedef llvm::sys::Path LLPath; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
221 |
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
|
222 // 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
|
223 if (global.params.output_bc) { |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
224 LLPath bcpath = LLPath(filename); |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 std::ofstream bos(bcpath.c_str(), std::ios::binary); |
1380
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
229 if (bos.fail()) |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
230 { |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
231 error("cannot write LLVM bitcode, failed to open file '%s'", bcpath.c_str()); |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
232 fatal(); |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
233 } |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
234 llvm::WriteBitcodeToFile(m, bos); |
52 | 235 } |
1 | 236 |
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
|
237 // 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
|
238 if (global.params.output_ll) { |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
239 LLPath llpath = LLPath(filename); |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
674
diff
changeset
|
240 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
|
241 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
|
242 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
|
243 std::ofstream aos(llpath.c_str()); |
1380
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
244 if (aos.fail()) |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
245 { |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
246 error("cannot write LLVM asm, failed to open file '%s'", llpath.c_str()); |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
247 fatal(); |
98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1379
diff
changeset
|
248 } |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
249 m->print(aos, NULL); |
52 | 250 } |
1 | 251 |
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
|
252 // write native assembly |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
253 if (global.params.output_s || global.params.output_o) { |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
254 LLPath spath = LLPath(filename); |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
255 spath.eraseSuffix(); |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
256 spath.appendSuffix(std::string(global.s_ext)); |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
257 if (!global.params.output_s) { |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
258 spath.createTemporaryFileOnDisk(); |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
259 } |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
260 Logger::println("Writing native asm to: %s\n", spath.c_str()); |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
261 std::string err; |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
262 { |
1542
ba2a5d2fe748
raw_fd_ostream takes a force parameter now
Benjamin Kramer <benny.kra@gmail.com>
parents:
1541
diff
changeset
|
263 llvm::raw_fd_ostream out(spath.c_str(), false, true, err); |
1379
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
264 if (err.empty()) |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
265 { |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
266 write_asm_to_file(*gTargetMachine, *m, out); |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
267 } |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
268 else |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
269 { |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
270 error("cannot write native asm: %s", err.c_str()); |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
271 fatal(); |
d430a41fbb45
Add error message when failed to open output stream for native asm output. Fixes ticket #281 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1364
diff
changeset
|
272 } |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
273 } |
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
|
274 |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
275 // call gcc to convert assembly to object file |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
276 if (global.params.output_o) { |
1052
12ea38902e83
Add '-singleobj' command line switch that will tell LDC to link LLVM modules internally and only emit a single object file.
Christian Kamm <kamm incasoftware de>
parents:
1026
diff
changeset
|
277 LLPath objpath = LLPath(filename); |
849
ba390e5e9150
Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents:
824
diff
changeset
|
278 assemble(spath, objpath); |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
279 } |
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
|
280 |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
281 if (!global.params.output_s) { |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
282 spath.eraseFromDisk(); |
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
689
diff
changeset
|
283 } |
673
37a7688a7494
Add basics for direct assembly output.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
284 } |
1 | 285 } |
286 | |
287 /* ================================================================== */ | |
288 | |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
289 // based on llc code, University of Illinois Open Source License |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
290 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& out) |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
291 { |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
292 using namespace llvm; |
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 // 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
|
295 ExistingModuleProvider Provider(&m); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
296 FunctionPassManager Passes(&Provider); |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
297 |
1566
c03d164e96d9
lookupTarget no longer takes a Module.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
298 if (const TargetData *TD = Target.getTargetData()) |
c03d164e96d9
lookupTarget no longer takes a Module.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
299 Passes.add(new TargetData(*TD)); |
c03d164e96d9
lookupTarget no longer takes a Module.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
300 else |
c03d164e96d9
lookupTarget no longer takes a Module.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
301 Passes.add(new TargetData(&m)); |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
302 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
303 // 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
|
304 MachineCodeEmitter *MCE = 0; |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
305 |
1280
00a307a393f2
Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents:
1276
diff
changeset
|
306 // Last argument is enum CodeGenOpt::Level OptLevel |
00a307a393f2
Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents:
1276
diff
changeset
|
307 // debug info doesn't work properly with OptLevel != None! |
00a307a393f2
Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents:
1276
diff
changeset
|
308 CodeGenOpt::Level LastArg = CodeGenOpt::Default; |
1341
681dd955c53b
Run backend without optimizations when no optimization parameters were used,
Frits van Bommel <fvbommel wxs.nl>
parents:
1299
diff
changeset
|
309 if (global.params.symdebug || !optimize()) |
1280
00a307a393f2
Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents:
1276
diff
changeset
|
310 LastArg = CodeGenOpt::None; |
00a307a393f2
Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents:
1276
diff
changeset
|
311 else if (optLevel() >= 3) |
00a307a393f2
Now the backend wants an enum value as optimization level.
Frits van Bommel <fvbommel wxs.nl>
parents:
1276
diff
changeset
|
312 LastArg = CodeGenOpt::Aggressive; |
1532
c88b16d4a13c
Remove all of the now unecessary #if LLVM_REV
Benjamin Kramer <benny.kra@gmail.com>
parents:
1529
diff
changeset
|
313 |
1541
1e7a09548e67
Target.addPassesToEmitFile takes a formatted_raw_ostream now
Benjamin Kramer <benny.kra@gmail.com>
parents:
1535
diff
changeset
|
314 llvm::formatted_raw_ostream fout(out); |
1e7a09548e67
Target.addPassesToEmitFile takes a formatted_raw_ostream now
Benjamin Kramer <benny.kra@gmail.com>
parents:
1535
diff
changeset
|
315 FileModel::Model mod = Target.addPassesToEmitFile(Passes, fout, TargetMachine::AssemblyFile, LastArg); |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
316 assert(mod == FileModel::AsmFile); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
317 |
1276
fa20726fe074
Update codegen to (hopefully) work correctly with newer LLVM trunk, where
Frits van Bommel <fvbommel wxs.nl>
parents:
1271
diff
changeset
|
318 bool err = Target.addPassesToEmitFileFinish(Passes, MCE, LastArg); |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
319 assert(!err); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
320 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
321 Passes.doInitialization(); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
322 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
323 // 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
|
324 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
|
325 if (!I->isDeclaration()) |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
326 Passes.run(*I); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
327 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
328 Passes.doFinalization(); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
329 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
330 // release module from module provider so we can delete it ourselves |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
331 std::string Err; |
674
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
332 llvm::Module* rmod = Provider.releaseModule(&Err); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
333 assert(rmod); |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
334 } |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
335 |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
336 /* ================================================================== */ |
db6a7e574cbd
Move to separate function and cleanup.
Christian Kamm <kamm incasoftware de>
parents:
673
diff
changeset
|
337 |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
338 // 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
|
339 // based on llvm-ld code, University of Illinois Open Source License |
849
ba390e5e9150
Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents:
824
diff
changeset
|
340 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath) |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
341 { |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
342 using namespace llvm; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
343 |
1299
847b767b2d0b
Factor out the code to find gcc, and add a command-line option to override the
Frits van Bommel <fvbommel wxs.nl>
parents:
1280
diff
changeset
|
344 sys::Path gcc = getGcc(); |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
345 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
346 // 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
|
347 // |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
348 // Note: |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
349 // 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
|
350 // 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
|
351 // GCC mysteriously knows how to do it. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
352 std::vector<std::string> args; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
353 args.push_back(gcc.toString()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
354 args.push_back("-fno-strict-aliasing"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
355 args.push_back("-O3"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
356 args.push_back("-c"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
357 args.push_back("-xassembler"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
358 args.push_back(asmpath.toString()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
359 args.push_back("-o"); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
360 args.push_back(objpath.toString()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
361 |
677
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
362 //FIXME: only use this if needed? |
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
363 args.push_back("-fpic"); |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
364 |
902
893d72ab95d0
Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents:
890
diff
changeset
|
365 //FIXME: enforce 64 bit |
893d72ab95d0
Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents:
890
diff
changeset
|
366 if (global.params.is64bit) |
893d72ab95d0
Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents:
890
diff
changeset
|
367 args.push_back("-m64"); |
1026
f756c47f310a
Pass -m32/-m64 on to gcc when assembling and linking
Frits van Bommel <fvbommel wxs.nl>
parents:
1005
diff
changeset
|
368 else |
f756c47f310a
Pass -m32/-m64 on to gcc when assembling and linking
Frits van Bommel <fvbommel wxs.nl>
parents:
1005
diff
changeset
|
369 // Assume 32-bit? |
f756c47f310a
Pass -m32/-m64 on to gcc when assembling and linking
Frits van Bommel <fvbommel wxs.nl>
parents:
1005
diff
changeset
|
370 args.push_back("-m32"); |
902
893d72ab95d0
Add -m64 switch to gcc calls on 64-bit platforms.
Christian Kamm <kamm incasoftware de>
parents:
890
diff
changeset
|
371 |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
372 // 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
|
373 // 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
|
374 // 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
|
375 std::vector<const char *> Args; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
376 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
|
377 Args.push_back(args[i].c_str()); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
378 Args.push_back(0); |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
379 |
994
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
380 if (Logger::enabled()) { |
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
381 Logger::println("Assembling with: "); |
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
382 std::vector<const char*>::const_iterator I = Args.begin(), E = Args.end(); |
1502
2292878925f4
Add an `llvm::OStream` workalike class for use with `Logger::cout()`, with the
Frits van Bommel <fvbommel wxs.nl>
parents:
1478
diff
changeset
|
383 Stream logstr = Logger::cout(); |
994
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
384 for (; I != E; ++I) |
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
385 if (*I) |
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
386 logstr << "'" << *I << "'" << " "; |
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
387 logstr << "\n" << std::flush; |
18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
Frits van Bommel <fvbommel wxs.nl>
parents:
993
diff
changeset
|
388 } |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
389 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
390 // Run the compiler to assembly the program. |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
391 std::string ErrMsg; |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
392 int R = sys::Program::ExecuteAndWait( |
849
ba390e5e9150
Remove unportable env-sanitizing code. If it is really needed, it needs to be
Christian Kamm <kamm incasoftware de>
parents:
824
diff
changeset
|
393 gcc, &Args[0], 0, 0, 0, 0, &ErrMsg); |
814
05f2651caa6c
Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
811
diff
changeset
|
394 if (R) |
05f2651caa6c
Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
811
diff
changeset
|
395 { |
1062
b9f9bde1707e
Make error message on assembler failure more informative (hopefully)
Frits van Bommel <fvbommel wxs.nl>
parents:
1052
diff
changeset
|
396 error("Failed to invoke gcc. %s", ErrMsg.c_str()); |
814
05f2651caa6c
Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
811
diff
changeset
|
397 fatal(); |
05f2651caa6c
Added error when invoking gcc fails
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
811
diff
changeset
|
398 } |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
399 } |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
400 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
401 |
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
402 /* ================================================================== */ |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
403 |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
404 // 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
|
405 // debug info. these macros are useful for that |
1569
755abafbf25d
Push the context through StructType::get.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1566
diff
changeset
|
406 #define DBG_TYPE ( getPtrToType(llvm::StructType::get(gIR->context(),NULL,NULL)) ) |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
407 #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
|
408 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
409 // build module ctor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
410 |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
411 llvm::Function* build_module_ctor() |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
412 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
413 if (gIR->ctors.empty()) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
414 return NULL; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
415 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
416 size_t n = gIR->ctors.size(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
417 if (n == 1) |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
418 return gIR->ctors[0]->ir.irFunc->func; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
419 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
420 std::string name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
421 name.append(gIR->dmodule->mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
422 name.append("6__ctorZ"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
423 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
424 std::vector<const LLType*> argsTy; |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
425 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::getVoidTy(gIR->context()),argsTy,false); |
184 | 426 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
|
427 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
933
d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
428 fn->setCallingConv(DtoCallingConv(0, LINKd)); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
429 |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
430 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "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
|
431 IRBuilder<> builder(bb); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
432 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
433 // 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
|
434 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
|
435 if(global.params.symdebug) { |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
436 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
437 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
|
438 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
439 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
440 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
|
441 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
|
442 llvm::CallInst* call = builder.CreateCall(f,""); |
933
d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
443 call->setCallingConv(DtoCallingConv(0, LINKd)); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
444 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
445 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
446 // 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
|
447 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
|
448 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
|
449 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
450 builder.CreateRetVoid(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
451 return fn; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
452 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
453 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
454 // build module dtor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
455 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
456 static llvm::Function* build_module_dtor() |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
457 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
458 if (gIR->dtors.empty()) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
459 return NULL; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
460 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
461 size_t n = gIR->dtors.size(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
462 if (n == 1) |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
463 return gIR->dtors[0]->ir.irFunc->func; |
116
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 std::string name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
466 name.append(gIR->dmodule->mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
467 name.append("6__dtorZ"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
468 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
469 std::vector<const LLType*> argsTy; |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
470 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::getVoidTy(gIR->context()),argsTy,false); |
184 | 471 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
|
472 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
933
d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
473 fn->setCallingConv(DtoCallingConv(0, LINKd)); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
474 |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
475 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "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
|
476 IRBuilder<> builder(bb); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
477 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
478 // 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
|
479 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
|
480 if(global.params.symdebug) { |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
481 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
482 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
|
483 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
484 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
485 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
|
486 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
|
487 llvm::CallInst* call = builder.CreateCall(f,""); |
933
d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
488 call->setCallingConv(DtoCallingConv(0, LINKd)); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
489 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
490 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
491 // 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
|
492 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
|
493 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
|
494 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
495 builder.CreateRetVoid(); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
496 return fn; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
497 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
498 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
499 // build module unittest |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
500 |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
501 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
|
502 { |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
503 if (gIR->unitTests.empty()) |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
504 return NULL; |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
505 |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
506 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
|
507 if (n == 1) |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
508 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
|
509 |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
510 std::string name("_D"); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
511 name.append(gIR->dmodule->mangle()); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
512 name.append("10__unittestZ"); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
513 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
514 std::vector<const LLType*> argsTy; |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
515 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::getVoidTy(gIR->context()),argsTy,false); |
184 | 516 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
|
517 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
933
d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
518 fn->setCallingConv(DtoCallingConv(0, LINKd)); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
519 |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
520 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "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
|
521 IRBuilder<> builder(bb); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
522 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
523 // 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
|
524 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
|
525 if(global.params.symdebug) { |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
526 subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
527 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
|
528 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
529 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
530 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
|
531 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
|
532 llvm::CallInst* call = builder.CreateCall(f,""); |
933
d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
920
diff
changeset
|
533 call->setCallingConv(DtoCallingConv(0, LINKd)); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
534 } |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
535 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
536 // 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
|
537 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
|
538 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
|
539 |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
540 builder.CreateRetVoid(); |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
541 return fn; |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
542 } |
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
543 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
544 // 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
|
545 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
|
546 { |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
547 // build ctor type |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
548 const LLFunctionType* fty = LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<const LLType*>(), false); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
549 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
550 // 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
|
551 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
|
552 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
|
553 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
|
554 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
555 // 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
|
556 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
|
557 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
558 // 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
|
559 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
|
560 std::vector<LLConstant*> mrefvalues; |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
561 mrefvalues.push_back(LLConstant::getNullValue(modulerefTy->getContainedType(0))); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
562 mrefvalues.push_back(llvm::ConstantExpr::getBitCast(moduleinfo, modulerefTy->getContainedType(1))); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
563 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
|
564 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
565 // 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
|
566 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
|
567 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
|
568 thismrefname += "11__moduleRefZ"; |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
569 LLGlobalVariable* thismref = new LLGlobalVariable(*gIR->module, modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
570 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
571 // 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
|
572 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
|
573 if (!mref) |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
574 mref = new LLGlobalVariable(*gIR->module, getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref"); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
575 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
576 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
577 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "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
|
578 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
|
579 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
580 // 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
|
581 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
|
582 if(global.params.symdebug) { |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
945
diff
changeset
|
583 subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str()).getGV(); |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
584 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
|
585 } |
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
586 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
587 // 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
|
588 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
|
589 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
590 // 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
|
591 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
|
592 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
|
593 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
594 // 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
|
595 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
|
596 |
686
363bb6c0cc80
Emit stub debug info for generated functions to work around LLVM bug 2172.
Christian Kamm <kamm incasoftware de>
parents:
683
diff
changeset
|
597 // 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
|
598 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
|
599 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
|
600 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
601 // return |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
602 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
|
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 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
|
605 } |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
606 |
1 | 607 // Put out instance of ModuleInfo for this Module |
608 | |
609 void Module::genmoduleinfo() | |
610 { | |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
611 // The layout is: |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
612 // { |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
613 // char[] name; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
614 // ModuleInfo[] importedModules; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
615 // ClassInfo[] localClasses; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
616 // uint flags; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
617 // |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
618 // void function() ctor; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
619 // void function() dtor; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
620 // void function() unitTest; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
621 // |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
622 // void* xgetMembers; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
623 // void function() ictor; |
1464
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
624 // |
1467
630fc54f7c1e
Fix a bug in DtoNestedInit and update an unrelated comment.
Frits van Bommel <fvbommel wxs.nl>
parents:
1464
diff
changeset
|
625 // version(D_Version2) |
630fc54f7c1e
Fix a bug in DtoNestedInit and update an unrelated comment.
Frits van Bommel <fvbommel wxs.nl>
parents:
1464
diff
changeset
|
626 // void*[4] reserved; // useless to us |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
627 // } |
89 | 628 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
629 // resolve ModuleInfo |
919
c76f74d09fb1
Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
902
diff
changeset
|
630 if (!moduleinfo) |
c76f74d09fb1
Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
902
diff
changeset
|
631 { |
c76f74d09fb1
Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
902
diff
changeset
|
632 error("object.d is missing the ModuleInfo class"); |
c76f74d09fb1
Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
902
diff
changeset
|
633 fatal(); |
c76f74d09fb1
Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
902
diff
changeset
|
634 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
635 // check for patch |
1453 | 636 #if DMDV2 |
637 else if (moduleinfo->fields.dim != 10) | |
638 #else | |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
639 else if (moduleinfo->fields.dim != 9) |
1453 | 640 #endif |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
641 { |
919
c76f74d09fb1
Fixed assertion failure when object.d is missing the ModuleInfo class
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
902
diff
changeset
|
642 error("object.d ModuleInfo class is incorrect"); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
643 fatal(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
644 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
645 |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
646 // use the RTTIBuilder |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
647 RTTIBuilder b(moduleinfo); |
89 | 648 |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
649 // some types |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
650 const LLType* moduleinfoTy = moduleinfo->type->irtype->getPA(); |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
651 const LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getPA(); |
89 | 652 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
653 // name |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
654 b.push_string(toPrettyChars()); |
89 | 655 |
656 // importedModules[] | |
657 int aimports_dim = aimports.dim; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
658 std::vector<LLConstant*> importInits; |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
659 LLConstant* c = 0; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
660 for (size_t i = 0; i < aimports.dim; i++) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
661 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
662 Module *m = (Module *)aimports.data[i]; |
824
b972fec8a5f5
Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
815
diff
changeset
|
663 if (!m->needModuleInfo() || m == this) |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
664 continue; |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
665 |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
666 // declare the imported module info |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
667 std::string m_name("_D"); |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
668 m_name.append(m->mangle()); |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
669 m_name.append("8__ModuleZ"); |
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
670 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
671 if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name); |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
672 importInits.push_back(m_gvar); |
89 | 673 } |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
674 // has import array? |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
675 if (!importInits.empty()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
676 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
677 const llvm::ArrayType* importArrTy = llvm::ArrayType::get(getPtrToType(moduleinfoTy), importInits.size()); |
1554
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1547
diff
changeset
|
678 c = LLConstantArray::get(importArrTy, importInits); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
679 std::string m_name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
680 m_name.append(mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
681 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
|
682 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
683 if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
684 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType())); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
685 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
686 } |
89 | 687 else |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
688 { |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
689 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy)) ); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
690 } |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
691 b.push(c); |
89 | 692 |
693 // localClasses[] | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
694 ClassDeclarations aclasses; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
695 //printf("members->dim = %d\n", members->dim); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
696 for (size_t i = 0; i < members->dim; i++) |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
697 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
698 Dsymbol *member; |
89 | 699 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
700 member = (Dsymbol *)members->data[i]; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
701 //printf("\tmember '%s'\n", member->toChars()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
702 member->addLocalClass(&aclasses); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
703 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
704 // fill inits |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
705 std::vector<LLConstant*> classInits; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
706 for (size_t i = 0; i < aclasses.dim; i++) |
89 | 707 { |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
708 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
709 cd->codegen(Type::sir); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
710 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
711 if (cd->isInterfaceDeclaration()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
712 { |
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
|
713 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
|
714 continue; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
715 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
716 else if (cd->sizeok != 1) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
717 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
718 Logger::println("skipping opaque class declaration '%s' in moduleinfo", cd->toPrettyChars()); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
719 continue; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
720 } |
132 | 721 Logger::println("class: %s", cd->toPrettyChars()); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1184
diff
changeset
|
722 c = DtoBitCast(cd->ir.irStruct->getClassInfoSymbol(), getPtrToType(classinfoTy)); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
766
diff
changeset
|
723 classInits.push_back(c); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
724 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
725 // has class array? |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
726 if (!classInits.empty()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
727 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
728 const llvm::ArrayType* classArrTy = llvm::ArrayType::get(getPtrToType(classinfoTy), classInits.size()); |
1554
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1547
diff
changeset
|
729 c = LLConstantArray::get(classArrTy, classInits); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
730 std::string m_name("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
731 m_name.append(mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
732 m_name.append("9__classesZ"); |
184 | 733 assert(gIR->module->getGlobalVariable(m_name) == NULL); |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
734 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(*gIR->module, classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name); |
1450
83bdf7bed9c5
Fix a type mismatch in ModuleInfo generation.
Frits van Bommel <fvbommel wxs.nl>
parents:
1386
diff
changeset
|
735 c = DtoGEPi(m_gvar, 0, 0); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
736 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
737 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
738 else |
1450
83bdf7bed9c5
Fix a type mismatch in ModuleInfo generation.
Frits van Bommel <fvbommel wxs.nl>
parents:
1386
diff
changeset
|
739 c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(getPtrToType(classinfoTy))) ); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
740 b.push(c); |
89 | 741 |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
742 // flags (4 means MIstandalone) |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
743 unsigned mi_flags = needmoduleinfo ? 0 : 4; |
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
744 b.push_uint(mi_flags); |
89 | 745 |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
746 // function pointer type for next three fields |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
747 const LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<const LLType*>(), false)); |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
748 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
749 // ctor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
750 llvm::Function* fctor = build_module_ctor(); |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
751 c = fctor ? fctor : getNullValue(fnptrTy); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
752 b.push(c); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
753 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
754 // dtor |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
755 llvm::Function* fdtor = build_module_dtor(); |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
756 c = fdtor ? fdtor : getNullValue(fnptrTy); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
757 b.push(c); |
89 | 758 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
759 // unitTest |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
117
diff
changeset
|
760 llvm::Function* unittest = build_module_unittest(); |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
761 c = unittest ? unittest : getNullValue(fnptrTy); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
762 b.push(c); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
763 |
132 | 764 // xgetMembers |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
765 c = getNullValue(getVoidPtrType()); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
766 b.push(c); |
132 | 767 |
768 // ictor | |
811
8e6135be6999
Fixed ModuleInfo generation to no longer use the ModuleInfo class' default initializer for types/defaults, it's unsafe as initializers don't necesarily match the "formal" type. There might be explicit padding.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
810
diff
changeset
|
769 c = getNullValue(fnptrTy); |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
770 b.push(c); |
132 | 771 |
1464
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
772 #if DMDV2 |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
773 |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
774 // void*[4] reserved :/ |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
775 const LLType* AT = llvm::ArrayType::get(getVoidPtrType(), 4); |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
776 c = getNullValue(AT); |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
777 b.push(c); |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
778 |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
779 #endif |
93644700a0b3
Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1456
diff
changeset
|
780 |
132 | 781 /*Logger::println("MODULE INFO INITIALIZERS"); |
782 for (size_t i=0; i<initVec.size(); ++i) | |
783 { | |
784 Logger::cout() << *initVec[i] << '\n'; | |
785 if (initVec[i]->getType() != moduleinfoTy->getElementType(i)) | |
786 assert(0); | |
787 }*/ | |
788 | |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
789 // create initializer |
1386
402bffb1b356
Use RTTIBuilder to build !ModuleInfo, still needs some work.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1380
diff
changeset
|
790 LLConstant* constMI = b.get_constant(); |
89 | 791 |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
792 // create name |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
793 std::string MIname("_D"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
794 MIname.append(mangle()); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
795 MIname.append("8__ModuleZ"); |
89 | 796 |
824
b972fec8a5f5
Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
815
diff
changeset
|
797 // declare global |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
115
diff
changeset
|
798 // flags will be modified at runtime so can't make it constant |
184 | 799 |
824
b972fec8a5f5
Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
815
diff
changeset
|
800 // it makes no sense that the our own module info already exists! |
b972fec8a5f5
Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
815
diff
changeset
|
801 assert(!gIR->module->getGlobalVariable(MIname)); |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
802 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module, constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname); |
117 | 803 |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
804 // 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
|
805 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
|
806 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
807 // register this ctor in the magic llvm.global_ctors appending array |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
808 const LLFunctionType* magicfty = LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<const LLType*>(), false); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
809 std::vector<const LLType*> magictypes; |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
810 magictypes.push_back(LLType::getInt32Ty(gIR->context())); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
811 magictypes.push_back(getPtrToType(magicfty)); |
1569
755abafbf25d
Push the context through StructType::get.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1566
diff
changeset
|
812 const LLStructType* magicsty = LLStructType::get(gIR->context(), magictypes); |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
813 |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
316
diff
changeset
|
814 // 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
|
815 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
|
816 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
|
817 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
|
818 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
|
819 |
117 | 820 // 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
|
821 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
|
822 std::vector<LLConstant*> appendInits(1, magicinit); |
1554
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1547
diff
changeset
|
823 LLConstant* appendInit = LLConstantArray::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
|
824 std::string appendName("llvm.global_ctors"); |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1521
diff
changeset
|
825 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(*gIR->module, appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName); |
1 | 826 } |