annotate gen/toobj.cpp @ 116:fd7ad91fd713 trunk

[svn r120] ModuleInfo implementation is now almost complete. Fixed some nasty static array-initializer bugs. Fixed bug in DtoArrayLen and DtoArrayPtr for full slices of static arrays.
author lindquist
date Sun, 25 Nov 2007 18:55:52 +0100
parents 5ba6d286c941
children 56a21f3e5d3e
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"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
19
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 #include "mars.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 #include "module.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
23 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
24 #include "statement.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
25 #include "enum.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
26 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
27 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 #include "attrib.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 #include "id.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 #include "import.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 #include "template.h"
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
32 #include "scope.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
34 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
35 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
36 #include "gen/tollvm.h"
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 63
diff changeset
37 #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
38 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
39 #include "gen/classes.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
40 #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
41 #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
42 #include "gen/runtime.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
44 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
45
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
46 void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
47 Module::genobjfile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
48 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
49 Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
52 // start by deleting the old object file
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
53 deleteObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 17
diff changeset
55 // create a new ir state
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 IRState ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57 gIR = &ir;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
58 ir.dmodule = this;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
60 // name the module
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
61 std::string mname(toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
62 if (md != 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
63 mname = md->toChars();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64 ir.module = new llvm::Module(mname);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
66 // set target stuff
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67 std::string target_triple(global.params.tt_arch);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68 target_triple.append(global.params.tt_os);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
69 ir.module->setTargetTriple(target_triple);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
70 ir.module->setDataLayout(global.params.data_layout);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
71
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
72 // heavily inspired by tools/llc/llc.cpp:200-230
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
73 const llvm::TargetMachineRegistry::Entry* targetEntry;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
74 std::string targetError;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
75 targetEntry = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, targetError);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
76 assert(targetEntry && "Failed to find a static target for module");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
77 std::auto_ptr<llvm::TargetMachine> targetPtr(targetEntry->CtorFn(*ir.module, "")); // TODO: replace "" with features
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
78 assert(targetPtr.get() && "Could not allocate target machine!");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
79 llvm::TargetMachine &targetMachine = *targetPtr.get();
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
80 gTargetData = targetMachine.getTargetData();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
81
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
82 // 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
83 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
84 RegisterDwarfSymbols(ir.module);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 89
diff changeset
85 ir.dmodule->llvmCompileUnit = DtoDwarfCompileUnit(this,true);
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
86 }
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
87
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
88 // start out by providing opaque for the built-in class types
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
89 if (!ClassDeclaration::object->type->llvmType)
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
90 ClassDeclaration::object->type->llvmType = new llvm::PATypeHolder(llvm::OpaqueType::get());
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
91
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
92 if (!Type::typeinfo->type->llvmType)
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
93 Type::typeinfo->type->llvmType = new llvm::PATypeHolder(llvm::OpaqueType::get());
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
94
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
95 if (!ClassDeclaration::classinfo->type->llvmType)
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
96 ClassDeclaration::classinfo->type->llvmType = new llvm::PATypeHolder(llvm::OpaqueType::get());
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
97
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 103
diff changeset
98 /*if (!Type::typeinfoclass->type->llvmType)
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 103
diff changeset
99 Type::typeinfoclass->type->llvmType = new llvm::PATypeHolder(llvm::OpaqueType::get());*/
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 103
diff changeset
100
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
101 // process module members
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102 for (int k=0; k < members->dim; k++) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
103 Dsymbol* dsym = (Dsymbol*)(members->data[k]);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 assert(dsym);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
105 dsym->toObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107
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
108 // main driver loop
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
109 DtoEmptyAllLists();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
110 // generate ModuleInfo
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
111 genmoduleinfo();
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
112 // do this again as moduleinfo might have pulled something in!
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
113 DtoEmptyAllLists();
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
114
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115 gTargetData = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
116
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 10
diff changeset
117 // emit the llvm main function if necessary
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 10
diff changeset
118 if (ir.emitMain) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 77
diff changeset
119 DtoMain();
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 10
diff changeset
120 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 10
diff changeset
121
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
122 // verify the llvm
31
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
123 if (!global.params.novalidate) {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
124 std::string verifyErr;
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
125 Logger::println("Verifying module...");
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
126 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
127 {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
128 error("%s", verifyErr.c_str());
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
129 fatal();
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
130 }
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
131 else {
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
132 Logger::println("Verification passed!");
2841234d2aea [svn r35] * Attributes on struct fields/methods now work
lindquist
parents: 28
diff changeset
133 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
134 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
135
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
136 // run passes
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
137 // TODO
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
138
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
139 // write bytecode
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
140 {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
141 Logger::println("Writing LLVM bitcode\n");
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
142 std::ofstream bos(bcfile->name->toChars(), std::ios::binary);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
143 llvm::WriteBitcodeToFile(ir.module, bos);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
144 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
145
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
146 // disassemble ?
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
147 if (global.params.disassemble) {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
148 Logger::println("Writing LLVM asm to: %s\n", llfile->name->toChars());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
149 std::ofstream aos(llfile->name->toChars());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
150 ir.module->print(aos);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
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 delete ir.module;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 gIR = NULL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
155 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
157 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
159 // build module ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
160
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
161 static llvm::Function* build_module_ctor()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
162 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
163 if (gIR->ctors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
164 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
165
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
166 size_t n = gIR->ctors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
167 if (n == 1)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
168 return llvm::cast<llvm::Function>(gIR->ctors[0]->llvmValue);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
169
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
170 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
171 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
172 name.append("6__ctorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
173
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
174 std::vector<const llvm::Type*> argsTy;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
175 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
176 llvm::Function* fn = new llvm::Function(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
177 fn->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
178
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
179 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
180 LLVMBuilder builder(bb);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
181
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
182 for (size_t i=0; i<n; i++) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
183 llvm::Function* f = llvm::cast<llvm::Function>(gIR->ctors[i]->llvmValue);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
184 llvm::CallInst* call = builder.CreateCall(f,"");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
185 call->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
186 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
187
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
188 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
189 return fn;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
190 }
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 // build module dtor
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 static llvm::Function* build_module_dtor()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
195 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
196 if (gIR->dtors.empty())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
197 return NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
198
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
199 size_t n = gIR->dtors.size();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
200 if (n == 1)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
201 return llvm::cast<llvm::Function>(gIR->dtors[0]->llvmValue);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
202
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
203 std::string name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
204 name.append(gIR->dmodule->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
205 name.append("6__dtorZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
206
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
207 std::vector<const llvm::Type*> argsTy;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
208 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
209 llvm::Function* fn = new llvm::Function(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
210 fn->setCallingConv(llvm::CallingConv::Fast);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
211
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
212 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
213 LLVMBuilder builder(bb);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
214
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
215 for (size_t i=0; i<n; i++) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
216 llvm::Function* f = llvm::cast<llvm::Function>(gIR->dtors[i]->llvmValue);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
217 llvm::CallInst* call = builder.CreateCall(f,"");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
218 call->setCallingConv(llvm::CallingConv::Fast);
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
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
221 builder.CreateRetVoid();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
222 return fn;
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
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
225 // Put out instance of ModuleInfo for this Module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
226
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
227 void Module::genmoduleinfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
228 {
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
229 // The layout is:
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
230 // {
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
231 // void **vptr;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
232 // monitor_t monitor;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
233 // char[] name; // class name
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
234 // ModuleInfo importedModules[];
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
235 // ClassInfo localClasses[];
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
236 // uint flags; // initialization state
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
237 // void *ctor;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
238 // void *dtor;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
239 // void *unitTest;
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
240 // }
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
241
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
242 // resolve ModuleInfo
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
243 assert(moduleinfo);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
244 DtoForceConstInitDsymbol(moduleinfo);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
245
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
246 // moduleinfo llvm struct type
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
247 const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->llvmType->get());
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
248
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
249 // classinfo llvm struct type
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
250 const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->llvmType->get());
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
251
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
252 // initializer vector
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
253 std::vector<llvm::Constant*> initVec;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
254 llvm::Constant* c = 0;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
255
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
256 // vtable
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
257 c = moduleinfo->llvmVtbl;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
258 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
259
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
260 // monitor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
261 c = llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty));
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
262 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
263
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
264 // name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
265 char *name = toPrettyChars();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
266 c = DtoConstString(name);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
267 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
268
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
269 // importedModules[]
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
270 int aimports_dim = aimports.dim;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
271 std::vector<llvm::Constant*> importInits;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
272 for (size_t i = 0; i < aimports.dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
273 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
274 Module *m = (Module *)aimports.data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
275 if (!m->needModuleInfo())
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
276 aimports_dim--;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
277 else { // declare
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
278 // create name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
279 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
280 m_name.append(m->mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
281 m_name.append("8__ModuleZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
282 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
283 importInits.push_back(m_gvar);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
284 }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
285 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
286 // has import array?
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
287 if (!importInits.empty()) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
288 const llvm::ArrayType* importArrTy = llvm::ArrayType::get(llvm::PointerType::get(moduleinfoTy), importInits.size());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
289 c = llvm::ConstantArray::get(importArrTy, importInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
290 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
291 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
292 m_name.append("9__importsZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
293 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
294 c = llvm::ConstantExpr::getBitCast(m_gvar, llvm::PointerType::get(importArrTy->getElementType()));
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
295 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
296 }
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
297 else
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
298 c = moduleinfo->llvmInitZ->getOperand(3);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
299 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
300
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
301 // localClasses[]
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
302 ClassDeclarations aclasses;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
303 //printf("members->dim = %d\n", members->dim);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
304 for (size_t i = 0; i < members->dim; i++)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
305 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
306 Dsymbol *member;
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
307
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
308 member = (Dsymbol *)members->data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
309 //printf("\tmember '%s'\n", member->toChars());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
310 member->addLocalClass(&aclasses);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
311 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
312 // fill inits
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
313 std::vector<llvm::Constant*> classInits;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
314 for (size_t i = 0; i < aclasses.dim; i++)
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
315 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
316 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
317 assert(cd->llvmClass);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
318 classInits.push_back(cd->llvmClass);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
319 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
320 // has class array?
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
321 if (!classInits.empty()) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
322 const llvm::ArrayType* classArrTy = llvm::ArrayType::get(llvm::PointerType::get(classinfoTy), classInits.size());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
323 c = llvm::ConstantArray::get(classArrTy, classInits);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
324 std::string m_name("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
325 m_name.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
326 m_name.append("9__classesZ");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
327 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
328 c = llvm::ConstantExpr::getBitCast(m_gvar, llvm::PointerType::get(classArrTy->getElementType()));
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
329 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
330 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
331 else
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
332 c = moduleinfo->llvmInitZ->getOperand(4);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
333 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
334
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
335 // flags
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
336 if (needmoduleinfo)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
337 c = DtoConstUint(0); // flags (4 means MIstandalone)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
338 else
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
339 c = DtoConstUint(4); // flags (4 means MIstandalone)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
340 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
341
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
342 // ctor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
343 llvm::Function* fctor = build_module_ctor();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
344 c = fctor ? fctor : moduleinfo->llvmInitZ->getOperand(6);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
345 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
346
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
347 // dtor
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
348 llvm::Function* fdtor = build_module_dtor();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
349 c = fdtor ? fdtor : moduleinfo->llvmInitZ->getOperand(7);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
350 initVec.push_back(c);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
351
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
352 // unitTest
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
353 c = moduleinfo->llvmInitZ->getOperand(8);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
354 initVec.push_back(c);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
355
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
356 // create initializer
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
357 llvm::Constant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec);
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
358
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
359 // create name
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
360 std::string MIname("_D");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
361 MIname.append(mangle());
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
362 MIname.append("8__ModuleZ");
89
ccca1c13e13a [svn r93] a few fixes, some phobos additions.
lindquist
parents: 88
diff changeset
363
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
364 // declare
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
365 // flags will be modified at runtime so can't make it constant
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 115
diff changeset
366 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
367 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
368
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
369 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
370
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
371 void Dsymbol::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
372 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
373 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
374 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
375
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
376 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
377
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
378 void Declaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
379 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
380 Logger::println("Ignoring Declaration::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
381 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
382
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
383 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
384
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
385 void InterfaceDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
386 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
387 Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
388 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
389
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
390 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
391
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
392 void StructDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
393 {
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
394 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
395 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
396
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
397 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
398
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
399 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx)
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
400 {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
401 // start at the bottom of the inheritance chain
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
402 if (cd->baseClass != 0) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
403 unsigned o = LLVM_ClassOffsetToIndex(cd->baseClass, os, idx);
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
404 if (o != (unsigned)-1)
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
405 return o;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
406 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
407
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
408 // check this class
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
409 unsigned i;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
410 for (i=0; i<cd->fields.dim; ++i) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
411 VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i];
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
412 if (os == vd->offset)
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
413 return i+idx;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
414 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
415 idx += i;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
416
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
417 return (unsigned)-1;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
418 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
419
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
420 void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result)
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
421 {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
422 unsigned idx = 0;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
423 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx);
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
424 assert(r != (unsigned)-1 && "Offset not found in any aggregate field");
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
425 // vtable is 0, monitor is 1
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
426 r += 2;
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
427 // interface offset further
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 106
diff changeset
428 r += vtblInterfaces->dim;
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
429 // the final index was not pushed
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 106
diff changeset
430 result.push_back(r);
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
431 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
432
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
433 /* ================================================================== */
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 74
diff changeset
434
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
435 void ClassDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
436 {
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
437 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
438 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
439
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
440 /******************************************
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
441 * 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
442 * Returns ~0 if not this csym.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
443 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
444
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
445 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
446 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
447 return ~0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
448 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
449
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
450 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
451
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
452 void VarDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
453 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
454 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
455 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
456
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
457 if (aliassym)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
458 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
459 Logger::println("alias sym");
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
460 toAlias()->toObjFile();
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
461 return;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
462 }
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
463
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
464 // global variable or magic
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
465 if (isDataseg())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
466 {
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
467 if (llvmResolved) return;
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
468 llvmResolved = true;
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
469 llvmDeclared = true;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 38
diff changeset
470
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
471 llvmIRGlobal = new IRGlobal(this);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
472
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
473 Logger::println("parent: %s (%s)", parent->toChars(), parent->kind());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
474
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
475 bool _isconst = isConst();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
476 if (parent && parent->isFuncDeclaration() && init && init->isExpInitializer())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
477 _isconst = false;
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
478
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
479 llvm::GlobalValue::LinkageTypes _linkage;
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
480 bool istempl = false;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
481 bool static_local = false;
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
482 if ((storage_class & STCcomdat) || (parent && DtoIsTemplateInstance(parent))) {
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
483 _linkage = llvm::GlobalValue::WeakLinkage;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
484 istempl = true;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 84
diff changeset
485 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
486 else if (parent && parent->isFuncDeclaration()) {
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
487 _linkage = llvm::GlobalValue::InternalLinkage;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
488 static_local = true;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
489 }
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
490 else
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 77
diff changeset
491 _linkage = DtoLinkage(protection, storage_class);
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 24
diff changeset
492
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
493 const llvm::Type* _type = llvmIRGlobal->type.get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
494
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
495 Logger::println("Creating global variable");
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
496 std::string _name(mangle());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
497
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
498 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
499 llvmValue = gvar;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
500
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
501 if (static_local)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
502 DtoConstInitGlobal(this);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
503 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
504 gIR->constInitList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
505
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
506 //if (storage_class & STCprivate)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
507 // gvar->setVisibility(llvm::GlobalValue::ProtectedVisibility);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
508 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
509
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
510 // inside aggregate declaration. declare a field.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
511 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
512 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
513 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
514
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
515 const llvm::Type* _type = DtoType(type);
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
516
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
517 // add the field in the IRStruct
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
518 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
519 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
520
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
521 Logger::println("VarDeclaration::toObjFile is done");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
522 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
523
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
524 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
525
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
526 void TypedefDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
527 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
528 static int tdi = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
529 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
530 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
531
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 50
diff changeset
532 // generate typeinfo
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
533 type->getTypeInfo(NULL);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
534 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
535
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
536 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
537
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
538 void EnumDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
539 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 31
diff changeset
540 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars());
1
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
543 /* ================================================================== */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
544
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
545 void FuncDeclaration::toObjFile()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
546 {
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
547 gIR->resolveList.push_back(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
548 }