annotate gen/toobj.cpp @ 602:48f079b4fe0f

Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 15 Sep 2008 15:48:59 +0200
parents 12bda38ea366
children e235b80c92bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2 // Copyright (c) 1999-2004 by Digital Mars
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3 // All Rights Reserved
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 // written by Walter Bright
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 // www.digitalmars.com
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 // License for redistribution is by either the Artistic License
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8 // See the included readme.txt for details.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10 #include <cstddef>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11 #include <iostream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
12 #include <fstream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
13
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
14 #include "gen/llvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
15 #include "llvm/Analysis/Verifier.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16 #include "llvm/Bitcode/ReaderWriter.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 #include "llvm/Target/TargetMachine.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 #include "llvm/Target/TargetMachineRegistry.h"
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
19 #include "llvm/System/Path.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 #include "mars.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 #include "module.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
23 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
24 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
25 #include "statement.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
26 #include "enum.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
27 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 #include "attrib.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 #include "id.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 #include "import.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32 #include "template.h"
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
33 #include "scope.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
34
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
35 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
36 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
37 #include "gen/tollvm.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
38 #include "gen/llvmhelpers.h"
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 63
diff changeset
39 #include "gen/arrays.h"
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
40 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
41 #include "gen/classes.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
42 #include "gen/functions.h"
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
43 #include "gen/todebug.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
44 #include "gen/runtime.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
45
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
46 #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
47 #include "ir/irmodule.h"
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
48
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
49 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
51 // in gen/optimize.cpp
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
52 void llvmdc_optimize_module(llvm::Module* m, char lvl, bool doinline);
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
53
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
54 //////////////////////////////////////////////////////////////////////////////////////////
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
55
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
56 void Module::genobjfile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57 {
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
58 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
59 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
60 {
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
61 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
62 }
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
63
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64 Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
66
499
9aac7cff8342 Revert accidental change to toobj.cpp.
Christian Kamm <kamm incasoftware de>
parents: 498
diff changeset
67 //printf("codegen: %s\n", srcfile->toChars());
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 393
diff changeset
68
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
69 // start by deleting the old object file
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
70 deleteObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
71
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
72 // 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
73 // TODO look at making the instance static and moving most functionality into IrModule where it belongs
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
74 IRState ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
75 gIR = &ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
76 ir.dmodule = this;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
77
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
78 // reset all IR data stored in Dsymbols and Types
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
79 IrDsymbol::resetAll();
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
80 IrType::resetAll();
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
81
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
82 // module ir state
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 137
diff changeset
83 // might already exist via import, just overwrite...
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
84 this->ir.irModule = new IrModule(this);
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
85
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
86 // name the module
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87 std::string mname(toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
88 if (md != 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
89 mname = md->toChars();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
90 ir.module = new llvm::Module(mname);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
91
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
92 // set target stuff
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
93 std::string target_triple(global.params.tt_arch);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94 target_triple.append(global.params.tt_os);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 ir.module->setTargetTriple(target_triple);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 ir.module->setDataLayout(global.params.data_layout);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97
583
12bda38ea366 Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 580
diff changeset
98 gTargetData = new llvm::TargetData(global.params.data_layout);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99
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
100 // 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
101 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
102 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
103 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
104 }
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
105
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
106 // start out by providing opaque for the built-in class types
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
107 if (!ClassDeclaration::object->type->ir.type)
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
108 ClassDeclaration::object->type->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get());
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
109
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
110 if (!Type::typeinfo->type->ir.type)
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
111 Type::typeinfo->type->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get());
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
112
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
113 if (!ClassDeclaration::classinfo->type->ir.type)
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
114 ClassDeclaration::classinfo->type->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get());
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
115
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
116 // process module members
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
117 for (int k=0; k < members->dim; k++) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
118 Dsymbol* dsym = (Dsymbol*)(members->data[k]);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
119 assert(dsym);
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
120 dsym->toObjFile(multiobj);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
121 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
122
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
123 // main driver loop
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
124 DtoEmptyAllLists();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
125 // generate ModuleInfo
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
126 genmoduleinfo();
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
127 // do this again as moduleinfo might have pulled something in!
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
128 DtoEmptyAllLists();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
129
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 248
diff changeset
130 // 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
131 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
132 {
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
133 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
134 LLConstant* usedInit = LLConstantArray::get(usedTy, ir.usedArray);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
135 LLGlobalVariable* usedArray = new LLGlobalVariable(usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used", ir.module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
136 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
137 }
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 248
diff changeset
138
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
139 // verify the llvm
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
140 if (!global.params.novalidate) {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
141 std::string verifyErr;
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
142 Logger::println("Verifying module...");
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
143 LOG_SCOPE;
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
144 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
145 {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
146 error("%s", verifyErr.c_str());
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
147 fatal();
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
148 }
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
149 else {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
150 Logger::println("Verification passed!");
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
151 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
153
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
154 // run optimizer
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
155 llvmdc_optimize_module(ir.module, global.params.optimizeLevel, global.params.llvmInline);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
157 // 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
158 typedef llvm::sys::Path LLPath;
580
7824c21a58e3 Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents: 565
diff changeset
159 LLPath bcpath = LLPath(objfile->name->toChars());
7824c21a58e3 Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents: 565
diff changeset
160 LLPath llpath = bcpath;
7824c21a58e3 Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents: 565
diff changeset
161 llpath.eraseSuffix();
7824c21a58e3 Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents: 565
diff changeset
162 llpath.appendSuffix(std::string(global.ll_ext));
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
163
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
164 // write bytecode
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
165 {
393
a3f3c2770a0d Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 363
diff changeset
166 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
167 std::ofstream bos(bcpath.c_str(), std::ios::binary);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
168 llvm::WriteBitcodeToFile(ir.module, bos);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
169 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
170
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
171 // disassemble ?
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
172 if (global.params.disassemble) {
580
7824c21a58e3 Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents: 565
diff changeset
173 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
174 std::ofstream aos(llpath.c_str());
565
3c07287765bc Fixed toobj.cpp to compile with latest LLVM, seems a method overload was removed recently.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 511
diff changeset
175 ir.module->print(aos, NULL);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
176 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
177
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
178 delete ir.module;
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 121
diff changeset
179 gTargetData = 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
180 gIR = NULL;
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 393
diff changeset
181
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
182 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
183 {
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
184 Logger::disable();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 393
diff changeset
185 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
186 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
187
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
188 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
189
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
190 // build module ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
191
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
192 static llvm::Function* build_module_ctor()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
193 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
194 if (gIR->ctors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
195 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
196
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
197 size_t n = gIR->ctors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
198 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
199 return gIR->ctors[0]->ir.irFunc->func;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
200
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
201 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
202 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
203 name.append("6__ctorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
204
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
205 std::vector<const LLType*> argsTy;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
206 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
207 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
208 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
209 fn->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
210
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
211 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
212 IRBuilder<> builder(bb);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
213
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
214 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
215 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
216 llvm::CallInst* call = builder.CreateCall(f,"");
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
217 call->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
218 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
219
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
220 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
221 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
222 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
223
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
224 // build module dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
225
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
226 static llvm::Function* build_module_dtor()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
227 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
228 if (gIR->dtors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
229 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
230
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
231 size_t n = gIR->dtors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
232 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
233 return gIR->dtors[0]->ir.irFunc->func;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
234
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
235 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
236 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
237 name.append("6__dtorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
238
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
239 std::vector<const LLType*> argsTy;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
240 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
241 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
242 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
243 fn->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
244
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
245 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
246 IRBuilder<> builder(bb);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
247
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
248 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
249 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
250 llvm::CallInst* call = builder.CreateCall(f,"");
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
251 call->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
252 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
253
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
254 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
255 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
256 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
257
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
258 // build module unittest
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
259
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
260 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
261 {
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
262 if (gIR->unitTests.empty())
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
263 return NULL;
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
264
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
265 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
266 if (n == 1)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
267 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
268
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
269 std::string name("_D");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
270 name.append(gIR->dmodule->mangle());
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
271 name.append("10__unittestZ");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
272
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
273 std::vector<const LLType*> argsTy;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
274 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
275 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
276 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
277 fn->setCallingConv(llvm::CallingConv::Fast);
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
278
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
279 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
280 IRBuilder<> builder(bb);
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
281
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
282 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
283 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
284 llvm::CallInst* call = builder.CreateCall(f,"");
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
285 call->setCallingConv(llvm::CallingConv::Fast);
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
286 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
287
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
288 builder.CreateRetVoid();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
289 return fn;
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
290 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
291
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
292 // 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
293 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
294 {
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
295 // build ctor type
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
296 const LLFunctionType* fty = LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
297
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
298 // 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
299 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
300 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
301 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
302
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
303 // 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
304 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
305
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
306 // 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
307 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
308 std::vector<LLConstant*> mrefvalues;
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
309 mrefvalues.push_back(LLConstant::getNullValue(modulerefTy->getContainedType(0)));
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
310 mrefvalues.push_back(moduleinfo);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
311 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
312
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
313 // 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
314 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
315 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
316 thismrefname += "11__moduleRefZ";
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
317 LLGlobalVariable* thismref = new LLGlobalVariable(modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit, thismrefname, gIR->module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
318
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
319 // 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
320 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
321 if (!mref)
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
322 mref = new LLGlobalVariable(getPtrToType(modulerefTy), false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref", gIR->module);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
324 // make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
325 llvm::BasicBlock* bb = llvm::BasicBlock::Create("moduleinfoCtorEntry", ctor);
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
326 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
327
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
328 // 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
329 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
330
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
331 // 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
332 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
333 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
334
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
335 // 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
336 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
337
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
338 // return
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
339 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
340
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
341 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
342 }
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
343
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
344 // Put out instance of ModuleInfo for this Module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
345
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
346 void Module::genmoduleinfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
347 {
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
348 // The layout is:
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
349 // {
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
350 // void **vptr;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
351 // monitor_t monitor;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
352 // char[] name; // class name
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
353 // ModuleInfo importedModules[];
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
354 // ClassInfo localClasses[];
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
355 // uint flags; // initialization state
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
356 // void *ctor;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
357 // void *dtor;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
358 // void *unitTest;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
359 // }
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
360
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
361 // resolve ModuleInfo
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
362 assert(moduleinfo);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
363 DtoForceConstInitDsymbol(moduleinfo);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
364
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
365 // moduleinfo llvm struct type
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
366 const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
367
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
368 // classinfo llvm struct type
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
369 const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
370
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
371 // initializer vector
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
372 std::vector<LLConstant*> initVec;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
373 LLConstant* c = 0;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
374
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
375 // vtable
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
376 c = moduleinfo->ir.irStruct->vtbl;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
377 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
378
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
379 // monitor
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
380 c = getNullPtr(getPtrToType(LLType::Int8Ty));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
381 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
382
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
383 // name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
384 char *name = toPrettyChars();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
385 c = DtoConstString(name);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
386 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
387
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
388 // importedModules[]
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
389 int aimports_dim = aimports.dim;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
390 std::vector<LLConstant*> importInits;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
391 for (size_t i = 0; i < aimports.dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
392 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
393 Module *m = (Module *)aimports.data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
394 if (!m->needModuleInfo())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
395 aimports_dim--;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
396 else { // declare
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
397 // create name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
398 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
399 m_name.append(m->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
400 m_name.append("8__ModuleZ");
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
401 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
402 if (!m_gvar) m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
403 importInits.push_back(m_gvar);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
404 }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
405 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
406 // has import array?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
407 if (!importInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
408 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
409 const llvm::ArrayType* importArrTy = llvm::ArrayType::get(getPtrToType(moduleinfoTy), importInits.size());
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
410 c = llvm::ConstantArray::get(importArrTy, importInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
411 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
412 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
413 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
414 llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name);
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
415 if (!m_gvar) m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
416 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType()));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
417 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
418 }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
419 else
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
420 c = moduleinfo->ir.irStruct->constInit->getOperand(3);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
421 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
422
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
423 // localClasses[]
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
424 ClassDeclarations aclasses;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
425 //printf("members->dim = %d\n", members->dim);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
426 for (size_t i = 0; i < members->dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
427 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
428 Dsymbol *member;
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
429
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
430 member = (Dsymbol *)members->data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
431 //printf("\tmember '%s'\n", member->toChars());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
432 member->addLocalClass(&aclasses);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
433 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
434 // fill inits
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
435 std::vector<LLConstant*> classInits;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
436 for (size_t i = 0; i < aclasses.dim; i++)
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
437 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
438 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i];
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
439 if (cd->isInterfaceDeclaration())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
440 {
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
441 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
442 continue;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
443 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
444 Logger::println("class: %s", cd->toPrettyChars());
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
445 assert(cd->ir.irStruct->classInfo);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
446 classInits.push_back(cd->ir.irStruct->classInfo);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
447 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
448 // has class array?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
449 if (!classInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
450 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
451 const llvm::ArrayType* classArrTy = llvm::ArrayType::get(getPtrToType(classinfoTy), classInits.size());
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
452 c = llvm::ConstantArray::get(classArrTy, classInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
453 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
454 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
455 m_name.append("9__classesZ");
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
456 assert(gIR->module->getGlobalVariable(m_name) == NULL);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
457 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
458 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(classArrTy->getElementType()));
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
459 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
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 else
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
462 c = moduleinfo->ir.irStruct->constInit->getOperand(4);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
463 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
464
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
465 // flags
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
466 c = DtoConstUint(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
467 if (!needmoduleinfo)
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
468 c = DtoConstUint(4); // flags (4 means MIstandalone)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
469 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
470
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
471 // ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
472 llvm::Function* fctor = build_module_ctor();
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
473 c = fctor ? fctor : moduleinfo->ir.irStruct->constInit->getOperand(6);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
474 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
475
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
476 // dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
477 llvm::Function* fdtor = build_module_dtor();
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
478 c = fdtor ? fdtor : moduleinfo->ir.irStruct->constInit->getOperand(7);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
479 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
480
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
481 // unitTest
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 117
diff changeset
482 llvm::Function* unittest = build_module_unittest();
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
483 c = unittest ? unittest : moduleinfo->ir.irStruct->constInit->getOperand(8);
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
484 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
485
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
486 // xgetMembers
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
487 c = moduleinfo->ir.irStruct->constInit->getOperand(9);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
488 initVec.push_back(c);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
489
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
490 // ictor
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
491 c = moduleinfo->ir.irStruct->constInit->getOperand(10);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
492 initVec.push_back(c);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
493
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
494 /*Logger::println("MODULE INFO INITIALIZERS");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
495 for (size_t i=0; i<initVec.size(); ++i)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
496 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
497 Logger::cout() << *initVec[i] << '\n';
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
498 if (initVec[i]->getType() != moduleinfoTy->getElementType(i))
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
499 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
500 }*/
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
501
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
502 // create initializer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
503 LLConstant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
504
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
505 // create name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
506 std::string MIname("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
507 MIname.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
508 MIname.append("8__ModuleZ");
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
509
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
510 // declare
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
511 // flags will be modified at runtime so can't make it constant
184
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
512
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
513 llvm::GlobalVariable* gvar = gIR->module->getGlobalVariable(MIname);
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
514 if (!gvar) gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, MIname, gIR->module);
f5ca6bbbf1d7 [svn r200] Fixed: removed use of std.intrinsic.
lindquist
parents: 173
diff changeset
515 gvar->setInitializer(constMI);
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
516
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
517 // 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
518 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
519
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
520 // register this ctor in the magic llvm.global_ctors appending array
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
521 const LLFunctionType* magicfty = LLFunctionType::get(LLType::VoidTy, std::vector<const LLType*>(), false);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
522 std::vector<const LLType*> magictypes;
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
523 magictypes.push_back(LLType::Int32Ty);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
524 magictypes.push_back(getPtrToType(magicfty));
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
525 const LLStructType* magicsty = LLStructType::get(magictypes);
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
526
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
527 // 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
528 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
529 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
530 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
531 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
532
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
533 // 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
534 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
535 std::vector<LLConstant*> appendInits(1, magicinit);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
536 LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits);
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 316
diff changeset
537 std::string appendName("llvm.global_ctors");
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
538 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
539 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
540
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
541 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
542
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
543 void Dsymbol::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
544 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
545 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
546 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
547
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
548 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
549
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
550 void Declaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
551 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
552 Logger::println("Ignoring Declaration::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
553 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
554
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
555 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
556
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
557 void InterfaceDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
558 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
559 //Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
560 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
561 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
562
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
563 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
564
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
565 void StructDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
566 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
567 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
568 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
569
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
570 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
571
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
572 void ClassDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
573 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
574 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
575 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
576
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
577 /******************************************
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
578 * Get offset of base class's vtbl[] initializer from start of csym.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
579 * Returns ~0 if not this csym.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
580 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
581
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
582 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
583 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
584 return ~0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
585 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
586
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
587 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
588
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
589 void VarDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
590 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
591 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
592 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
593
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
594 if (aliassym)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
595 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
596 Logger::println("alias sym");
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
597 toAlias()->toObjFile(multiobj);
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
598 return;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
599 }
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
600
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
601 // global variable or magic
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
602 if (isDataseg())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
603 {
511
a0b0676e787d Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 499
diff changeset
604 Logger::println("data segment");
a0b0676e787d Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 499
diff changeset
605
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
606 // we don't want to touch private static members at all !!!
511
a0b0676e787d Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 499
diff changeset
607 // template instances should always be emitted
a0b0676e787d Fixed problem when instantiating a template with private global variables.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 499
diff changeset
608 if (!DtoIsTemplateInstance(this) && prot() == PROTprivate && getModule() != gIR->dmodule)
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
609 return;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
610
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
611 // don't duplicate work
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
612 if (this->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
613 this->ir.resolved = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
614 this->ir.declared = true;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
615
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
616 this->ir.irGlobal = new IrGlobal(this);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
617
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
618 Logger::println("parent: %s (%s)", parent->toChars(), parent->kind());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
619
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
620 // handle static local variables
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
621 bool static_local = false;
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
622 bool _isconst = isConst();
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
623 if (parent && parent->isFuncDeclaration())
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
624 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
625 static_local = true;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
626 if (init && init->isExpInitializer()) {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
627 _isconst = false;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
628 }
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
629 }
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
630
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
631 Logger::println("Creating global variable");
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
632
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
633 const LLType* _type = this->ir.irGlobal->type.get();
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 139
diff changeset
634 llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
635 std::string _name(mangle());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
636
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
637 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
638 this->ir.irGlobal->value = gvar;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
639
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
640 Logger::cout() << *gvar << '\n';
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 157
diff changeset
641
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
642 if (static_local)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
643 DtoConstInitGlobal(this);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
644 else
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
645 gIR->constInitList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
646 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
647
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
648 // inside aggregate declaration. declare a field.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
649 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
650 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
651 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
652
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
653 const LLType* _type = DtoType(type);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
654 this->ir.irField = new IrField(this);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
655
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
656 // add the field in the IRStruct
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
657 gIR->topstruct()->offsets.insert(std::make_pair(offset, IrStruct::Offset(this, _type)));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
658 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
659
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
660 Logger::println("VarDeclaration::toObjFile is done");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
661 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
662
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
663 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
664
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
665 void TypedefDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
666 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
667 static int tdi = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
668 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
669 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
670
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
671 // generate typeinfo
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 251
diff changeset
672 DtoTypeInfoOf(type, false);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
673 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
674
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
675 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
676
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
677 void EnumDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
678 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
679 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
680 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
681
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
682 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
683
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 324
diff changeset
684 void FuncDeclaration::toObjFile(int multiobj)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
685 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
686 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
687 }