Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 180 lines (146 sloc) 4.434 kB
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
1 #include "gen/llvm.h"
2
3 #include "aggregate.h"
4 #include "mtype.h"
5
6 #include "gen/arrays.h"
7 #include "gen/irstate.h"
8 #include "gen/linkage.h"
9 #include "gen/llvmhelpers.h"
10 #include "gen/rttibuilder.h"
11 #include "gen/tollvm.h"
12
13 #include "ir/irstruct.h"
14
4d7a6ed @AlexeyProkhin Different fixes for d2
AlexeyProkhin authored
15 RTTIBuilder::RTTIBuilder(AggregateDeclaration* base_class)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
16 {
17 // make sure the base typeinfo class has been processed
18 base_class->codegen(Type::sir);
19
20 base = base_class;
2dbee75 @redstar Prefer C++-style casts.
redstar authored
21 basetype = static_cast<TypeClass*>(base->type);
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
22
23 baseir = base->ir.irStruct;
24 assert(baseir && "no IrStruct for TypeInfo base class");
25
4d7a6ed @AlexeyProkhin Different fixes for d2
AlexeyProkhin authored
26 if (base->isClassDeclaration()) {
27 // just start with adding the vtbl
28 inits.push_back(baseir->getVtblSymbol());
29 // and monitor
30 push_null_vp();
31 }
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
32 }
33
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
34 void RTTIBuilder::push(llvm::Constant* C)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
35 {
36 inits.push_back(C);
37 }
38
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
39 void RTTIBuilder::push_null(Type* T)
40 {
41 inits.push_back(getNullValue(DtoType(T)));
42 }
43
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
44 void RTTIBuilder::push_null_vp()
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
45 {
46 inits.push_back(getNullValue(getVoidPtrType()));
47 }
48
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
49 void RTTIBuilder::push_typeinfo(Type* t)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
50 {
51 inits.push_back(DtoTypeInfoOf(t, true));
52 }
53
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
54 void RTTIBuilder::push_classinfo(ClassDeclaration* cd)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
55 {
56 inits.push_back(cd->ir.irStruct->getClassInfoSymbol());
57 }
58
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
59 void RTTIBuilder::push_string(const char* str)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
60 {
61 inits.push_back(DtoConstString(str));
62 }
63
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
64 void RTTIBuilder::push_null_void_array()
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
65 {
629f139 @AlexeyProkhin WIP: port to llvm 3.0
AlexeyProkhin authored
66 LLType* T = DtoType(Type::tvoid->arrayOf());
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
67 inits.push_back(getNullValue(T));
68 }
69
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
70 void RTTIBuilder::push_void_array(uint64_t dim, llvm::Constant* ptr)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
71 {
72 inits.push_back(DtoConstSlice(
73 DtoConstSize_t(dim),
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
74 DtoBitCast(ptr, getVoidPtrType())
75 ));
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
76 }
77
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
78 void RTTIBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
79 {
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
80 std::string initname(mangle_sym->mangle());
008d81a @wilsonk Fix "garbage at end of line" errors on mingw...shouldn't affect linux…
wilsonk authored
81 initname.append(".rtti.voidarr.data");
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
82
83 LLGlobalVariable* G = new llvm::GlobalVariable(
756a2cb @ckamm Adjust LDC to work with the LLVMContext LLVM changes.
ckamm authored
84 *gIR->module, CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname);
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
85 G->setAlignment(valtype->alignsize());
86
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
87 push_void_array(getTypePaddedSize(CI->getType()), G);
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
88 }
89
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
90 void RTTIBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym)
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
91 {
008d81a @wilsonk Fix "garbage at end of line" errors on mingw...shouldn't affect linux…
wilsonk authored
92 std::string tmpStr(valtype->arrayOf()->toChars());
93 tmpStr.erase( remove( tmpStr.begin(), tmpStr.end(), '[' ), tmpStr.end() );
94 tmpStr.erase( remove( tmpStr.begin(), tmpStr.end(), ']' ), tmpStr.end() );
95 tmpStr.append("arr");
96
97 std::string initname(mangle_sym?mangle_sym->mangle():".ldc");
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
98 initname.append(".rtti.");
008d81a @wilsonk Fix "garbage at end of line" errors on mingw...shouldn't affect linux…
wilsonk authored
99 initname.append(tmpStr);
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
100 initname.append(".data");
101
102 LLGlobalVariable* G = new llvm::GlobalVariable(
756a2cb @ckamm Adjust LDC to work with the LLVMContext LLVM changes.
ckamm authored
103 *gIR->module, CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname);
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
104 G->setAlignment(valtype->alignsize());
105
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
106 push_array(dim, DtoBitCast(G, DtoType(valtype->pointerTo())));
107 }
108
109 void RTTIBuilder::push_array(uint64_t dim, llvm::Constant * ptr)
110 {
111 inits.push_back(DtoConstSlice(DtoConstSize_t(dim), ptr));
5078019 @lindquist Cleaned up TypeInfo_Tuple generation.
lindquist authored
112 }
113
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
114 void RTTIBuilder::push_uint(unsigned u)
d80de9d @lindquist Cleaned up TypeInfo_Struct.
lindquist authored
115 {
116 inits.push_back(DtoConstUint(u));
117 }
118
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
119 void RTTIBuilder::push_size(uint64_t s)
d80de9d @lindquist Cleaned up TypeInfo_Struct.
lindquist authored
120 {
121 inits.push_back(DtoConstSize_t(s));
122 }
123
4ae1444 @klickverbot Emit new TypeInfo layout.
klickverbot authored
124 void RTTIBuilder::push_size_as_vp(uint64_t s)
125 {
126 inits.push_back(llvm::ConstantExpr::getIntToPtr(DtoConstSize_t(s), getVoidPtrType()));
127 }
128
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
129 void RTTIBuilder::push_funcptr(FuncDeclaration* fd, Type* castto)
d80de9d @lindquist Cleaned up TypeInfo_Struct.
lindquist authored
130 {
131 if (fd)
132 {
133 fd->codegen(Type::sir);
134 LLConstant* F = fd->ir.irFunc->func;
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
135 if (castto)
136 F = DtoBitCast(F, DtoType(castto));
d80de9d @lindquist Cleaned up TypeInfo_Struct.
lindquist authored
137 inits.push_back(F);
138 }
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
139 else if (castto)
140 {
141 push_null(castto);
142 }
d80de9d @lindquist Cleaned up TypeInfo_Struct.
lindquist authored
143 else
144 {
145 push_null_vp();
146 }
147 }
148
b6daf3d @lindquist Renamed !TypeInfoBuilder to !RTTIBuilder.
lindquist authored
149 void RTTIBuilder::finalize(IrGlobal* tid)
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
150 {
629f139 @AlexeyProkhin WIP: port to llvm 3.0
AlexeyProkhin authored
151 finalize(tid->type, tid->value);
152 }
153
154 void RTTIBuilder::finalize(LLType* type, LLValue* value)
155 {
156 llvm::ArrayRef<LLConstant*> inits = llvm::makeArrayRef(this->inits);
157 LLStructType *st = isaStruct(type);
158 assert(st);
159
160 // set struct body
8b50928 @AlexeyProkhin Fixed #37 — ICE: llvm::GlobalVariable::setInitializer assert failed
AlexeyProkhin authored
161 if (st->isOpaque()) {
162 std::vector<LLType*> types;
163 for (int i = 0, n = inits.size(); i < n; ++i)
164 types.push_back(inits[i]->getType());
165 st->setBody(types);
166 }
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
167
629f139 @AlexeyProkhin WIP: port to llvm 3.0
AlexeyProkhin authored
168 // create the inititalizer
169 LLConstant* tiInit = LLConstantStruct::get(st, inits);
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
170
171 // set the initializer
629f139 @AlexeyProkhin WIP: port to llvm 3.0
AlexeyProkhin authored
172 isaGlobalVar(value)->setInitializer(tiInit);
f3c7278 @lindquist Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tupl…
lindquist authored
173 }
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
174
629f139 @AlexeyProkhin WIP: port to llvm 3.0
AlexeyProkhin authored
175 LLConstant* RTTIBuilder::get_constant(LLStructType *initType)
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
176 {
177 // just return the inititalizer
629f139 @AlexeyProkhin WIP: port to llvm 3.0
AlexeyProkhin authored
178 return LLConstantStruct::get(initType, inits);
dc4b7e8 @lindquist Update !ClassInfo generation to use !RTTIBuilder, slight update of !R…
lindquist authored
179 }
Something went wrong with that request. Please try again.