Mercurial > projects > ldc
annotate gen/runtime.cpp @ 137:ce7b81fb957f trunk
[svn r141] fixed more problems with classinfo
moved more IR state out of the AST classes
author | lindquist |
---|---|
date | Fri, 18 Jan 2008 16:42:16 +0100 |
parents | 44a95ac7368a |
children | 5c17f81fc1c1 |
rev | line source |
---|---|
1 | 1 #include <cassert> |
2 | |
52 | 3 #include "gen/llvm.h" |
1 | 4 #include "llvm/Module.h" |
5 #include "llvm/Bitcode/ReaderWriter.h" | |
6 #include "llvm/Support/MemoryBuffer.h" | |
7 | |
8 #include "root.h" | |
9 #include "mars.h" | |
132 | 10 #include "lexer.h" |
11 #include "dsymbol.h" | |
12 #include "mtype.h" | |
13 #include "aggregate.h" | |
1 | 14 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
15 #include "gen/runtime.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
16 #include "gen/logger.h" |
132 | 17 #include "gen/tollvm.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
18 |
1 | 19 static llvm::Module* M = NULL; |
20 static bool runtime_failed = false; | |
21 | |
132 | 22 static void LLVM_D_BuildRuntimeModule(); |
23 | |
52 | 24 ////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | |
1 | 26 bool LLVM_D_InitRuntime() |
27 { | |
132 | 28 Logger::println("*** Initializing D runtime declarations ***"); |
1 | 29 LOG_SCOPE; |
30 | |
132 | 31 LLVM_D_BuildRuntimeModule(); |
32 return true; | |
33 | |
34 /* | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
4
diff
changeset
|
35 if (!global.params.runtimeImppath) { |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
4
diff
changeset
|
36 error("You must set the runtime import path with -E"); |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
4
diff
changeset
|
37 fatal(); |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
4
diff
changeset
|
38 } |
1 | 39 std::string filename(global.params.runtimeImppath); |
40 filename.append("/llvmdcore.bc"); | |
41 llvm::MemoryBuffer* buffer = llvm::MemoryBuffer::getFile(filename.c_str(), filename.length()); | |
42 if (!buffer) { | |
43 Logger::println("Failed to load runtime library from disk"); | |
44 runtime_failed = true; | |
45 return false; | |
46 } | |
47 | |
48 std::string errstr; | |
49 bool retval = false; | |
50 M = llvm::ParseBitcodeFile(buffer, &errstr); | |
51 if (M) { | |
52 retval = true; | |
53 } | |
54 else { | |
55 Logger::println("Failed to load runtime: %s", errstr.c_str()); | |
56 runtime_failed = true; | |
57 } | |
52 | 58 |
1 | 59 delete buffer; |
60 return retval; | |
132 | 61 */ |
1 | 62 } |
63 | |
64 void LLVM_D_FreeRuntime() | |
65 { | |
66 if (M) { | |
132 | 67 Logger::println("*** Freeing D runtime declarations ***"); |
1 | 68 delete M; |
132 | 69 M = NULL; |
1 | 70 } |
71 } | |
72 | |
52 | 73 ////////////////////////////////////////////////////////////////////////////////////////////////// |
74 | |
1 | 75 llvm::Function* LLVM_D_GetRuntimeFunction(llvm::Module* target, const char* name) |
76 { | |
77 if (global.params.noruntime) { | |
78 error("No implicit runtime calls allowed with -noruntime option enabled"); | |
79 fatal(); | |
80 } | |
52 | 81 |
1 | 82 if (!M) { |
83 assert(!runtime_failed); | |
84 LLVM_D_InitRuntime(); | |
85 } | |
52 | 86 |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
87 llvm::Function* fn = target->getFunction(name); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
88 if (fn) |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
89 return fn; |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
90 |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
91 fn = M->getFunction(name); |
40 | 92 if (!fn) { |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
93 printf("Runtime function '%s' was not found\n", name); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
86
diff
changeset
|
94 assert(0); |
40 | 95 //return NULL; |
96 } | |
52 | 97 |
1 | 98 const llvm::FunctionType* fnty = fn->getFunctionType(); |
99 return llvm::cast<llvm::Function>(target->getOrInsertFunction(name, fnty)); | |
100 } | |
40 | 101 |
52 | 102 ////////////////////////////////////////////////////////////////////////////////////////////////// |
103 | |
104 llvm::GlobalVariable* LLVM_D_GetRuntimeGlobal(llvm::Module* target, const char* name) | |
105 { | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
52
diff
changeset
|
106 llvm::GlobalVariable* gv = target->getNamedGlobal(name); |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
52
diff
changeset
|
107 if (gv) { |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
52
diff
changeset
|
108 return gv; |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
52
diff
changeset
|
109 } |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
52
diff
changeset
|
110 |
52 | 111 if (global.params.noruntime) { |
112 error("No implicit runtime calls allowed with -noruntime option enabled"); | |
113 fatal(); | |
114 } | |
115 | |
116 if (!M) { | |
117 assert(!runtime_failed); | |
118 LLVM_D_InitRuntime(); | |
119 } | |
120 | |
121 llvm::GlobalVariable* g = M->getNamedGlobal(name); | |
122 if (!g) { | |
123 error("Runtime global '%s' was not found", name); | |
124 fatal(); | |
125 //return NULL; | |
126 } | |
127 | |
128 const llvm::PointerType* t = g->getType(); | |
129 return new llvm::GlobalVariable(t->getElementType(),g->isConstant(),g->getLinkage(),NULL,g->getName(),target); | |
130 } | |
132 | 131 |
132 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
133 | |
134 static const llvm::Type* rt_ptr(const llvm::Type* t) | |
135 { | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
136 return getPtrToType(t); |
132 | 137 } |
138 | |
139 static const llvm::Type* rt_array(const llvm::Type* elemty) | |
140 { | |
141 std::vector<const llvm::Type*> t; | |
142 t.push_back(DtoSize_t()); | |
143 t.push_back(rt_ptr(elemty)); | |
144 return rt_ptr(llvm::StructType::get(t)); | |
145 } | |
146 | |
147 static const llvm::Type* rt_dg1() | |
148 { | |
149 std::vector<const llvm::Type*> types; | |
150 types.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
151 types.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
152 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::Int32Ty, types, false); | |
153 | |
154 std::vector<const llvm::Type*> t; | |
155 t.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
156 t.push_back(rt_ptr(fty)); | |
157 return rt_ptr(llvm::StructType::get(t)); | |
158 } | |
159 | |
160 static const llvm::Type* rt_dg2() | |
161 { | |
162 std::vector<const llvm::Type*> types; | |
163 types.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
164 types.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
165 types.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
166 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::Int32Ty, types, false); | |
167 | |
168 std::vector<const llvm::Type*> t; | |
169 t.push_back(rt_ptr(llvm::Type::Int8Ty)); | |
170 t.push_back(rt_ptr(fty)); | |
171 return rt_ptr(llvm::StructType::get(t)); | |
172 } | |
173 | |
174 static void LLVM_D_BuildRuntimeModule() | |
175 { | |
176 M = new llvm::Module("llvmdc internal runtime"); | |
177 | |
178 const llvm::Type* voidTy = llvm::Type::VoidTy; | |
179 const llvm::Type* boolTy = llvm::Type::Int1Ty; | |
180 const llvm::Type* byteTy = llvm::Type::Int8Ty; | |
181 const llvm::Type* shortTy = llvm::Type::Int16Ty; | |
182 const llvm::Type* intTy = llvm::Type::Int32Ty; | |
183 const llvm::Type* longTy = llvm::Type::Int64Ty; | |
184 const llvm::Type* floatTy = llvm::Type::FloatTy; | |
185 const llvm::Type* doubleTy = llvm::Type::DoubleTy; | |
186 const llvm::Type* sizeTy = DtoSize_t(); | |
187 const llvm::Type* voidPtrTy = rt_ptr(byteTy); | |
188 const llvm::Type* stringTy = rt_array(byteTy); | |
189 const llvm::Type* wstringTy = rt_array(shortTy); | |
190 const llvm::Type* dstringTy = rt_array(intTy); | |
191 const llvm::Type* objectTy = rt_ptr(ClassDeclaration::object->type->llvmType->get()); | |
192 const llvm::Type* classInfoTy = rt_ptr(ClassDeclaration::classinfo->type->llvmType->get()); | |
193 const llvm::Type* typeInfoTy = rt_ptr(Type::typeinfo->type->llvmType->get()); | |
194 const llvm::Type* aaTy = rt_ptr(llvm::OpaqueType::get()); | |
195 | |
196 ///////////////////////////////////////////////////////////////////////////////////// | |
197 ///////////////////////////////////////////////////////////////////////////////////// | |
198 ///////////////////////////////////////////////////////////////////////////////////// | |
199 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
200 // void _d_assert( char[] file, uint line ) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
201 // void _d_array_bounds( char[] file, uint line ) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
202 // void _d_switch_error( char[] file, uint line ) |
132 | 203 { |
204 std::string fname("_d_assert"); | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
205 std::string fname2("_d_array_bounds"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
206 std::string fname3("_d_switch_error"); |
132 | 207 std::vector<const llvm::Type*> types; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
208 types.push_back(stringTy); |
132 | 209 types.push_back(intTy); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
210 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
211 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
212 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
213 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname3, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
214 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
215 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
216 // void _d_assert_msg( char[] msg, char[] file, uint line ) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
217 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
218 std::string fname("_d_assert_msg"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
219 std::vector<const llvm::Type*> types; |
132 | 220 types.push_back(stringTy); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
221 types.push_back(stringTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
222 types.push_back(intTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
223 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); |
132 | 224 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
225 } | |
226 | |
227 ///////////////////////////////////////////////////////////////////////////////////// | |
228 ///////////////////////////////////////////////////////////////////////////////////// | |
229 ///////////////////////////////////////////////////////////////////////////////////// | |
230 | |
231 // realloc | |
232 // void* _d_realloc(void* ptr, size_t n) | |
233 { | |
234 std::string fname("_d_realloc"); | |
235 std::vector<const llvm::Type*> types; | |
236 types.push_back(voidPtrTy); | |
237 types.push_back(sizeTy); | |
238 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
239 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
240 } | |
241 | |
242 // free | |
243 // void _d_free(void* ptr) | |
244 { | |
245 std::string fname("_d_free"); | |
246 std::vector<const llvm::Type*> types; | |
247 types.push_back(voidPtrTy); | |
248 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
249 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
250 } | |
251 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
252 // Object _d_newclass(ClassInfo ci) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
253 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
254 std::string fname("_d_newclass"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
255 std::vector<const llvm::Type*> types; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
256 types.push_back(classInfoTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
257 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
258 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
259 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
260 |
132 | 261 ///////////////////////////////////////////////////////////////////////////////////// |
262 ///////////////////////////////////////////////////////////////////////////////////// | |
263 ///////////////////////////////////////////////////////////////////////////////////// | |
264 | |
265 #define ARRAY_INIT(TY,suffix) \ | |
266 { \ | |
267 std::string fname("_d_array_init_"); \ | |
268 fname.append(suffix); \ | |
269 std::vector<const llvm::Type*> types; \ | |
270 types.push_back(rt_ptr(TY)); \ | |
271 types.push_back(sizeTy); \ | |
272 types.push_back(TY); \ | |
273 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); \ | |
274 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
275 } | |
276 | |
277 ARRAY_INIT(boolTy,"i1") | |
278 ARRAY_INIT(byteTy,"i8") | |
279 ARRAY_INIT(shortTy,"i16") | |
280 ARRAY_INIT(intTy,"i32") | |
281 ARRAY_INIT(longTy,"i64") | |
282 ARRAY_INIT(floatTy,"float") | |
283 ARRAY_INIT(doubleTy,"double") | |
284 ARRAY_INIT(voidPtrTy,"pointer") | |
285 | |
286 #undef ARRAY_INIT | |
287 | |
288 // array init mem | |
289 // void _d_array_init_mem(void* a, size_t na, void* v, size_t nv) | |
290 { | |
291 std::string fname("_d_array_init_mem"); | |
292 std::vector<const llvm::Type*> types; | |
293 types.push_back(voidPtrTy); | |
294 types.push_back(sizeTy); | |
295 types.push_back(voidPtrTy); | |
296 types.push_back(sizeTy); | |
297 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
298 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
299 } | |
300 | |
301 ///////////////////////////////////////////////////////////////////////////////////// | |
302 ///////////////////////////////////////////////////////////////////////////////////// | |
303 ///////////////////////////////////////////////////////////////////////////////////// | |
304 | |
305 #define STR_APPLY1(TY,a,b) \ | |
306 { \ | |
307 std::string fname(a); \ | |
308 std::string fname2(b); \ | |
309 std::vector<const llvm::Type*> types; \ | |
310 types.push_back(TY); \ | |
311 types.push_back(rt_dg1()); \ | |
312 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
313 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
314 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
315 } | |
316 STR_APPLY1(stringTy, "_aApplycw1", "_aApplycd1") | |
317 STR_APPLY1(wstringTy, "_aApplywc1", "_aApplywd1") | |
318 STR_APPLY1(dstringTy, "_aApplydc1", "_aApplydw1") | |
319 #undef STR_APPLY | |
320 | |
321 #define STR_APPLY2(TY,a,b) \ | |
322 { \ | |
323 std::string fname(a); \ | |
324 std::string fname2(b); \ | |
325 std::vector<const llvm::Type*> types; \ | |
326 types.push_back(TY); \ | |
327 types.push_back(rt_dg2()); \ | |
328 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
329 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
330 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
331 } | |
332 STR_APPLY2(stringTy, "_aApplycw2", "_aApplycd2") | |
333 STR_APPLY2(wstringTy, "_aApplywc2", "_aApplywd2") | |
334 STR_APPLY2(dstringTy, "_aApplydc2", "_aApplydw2") | |
335 #undef STR_APPLY2 | |
336 | |
337 #define STR_APPLY_R1(TY,a,b) \ | |
338 { \ | |
339 std::string fname(a); \ | |
340 std::string fname2(b); \ | |
341 std::vector<const llvm::Type*> types; \ | |
342 types.push_back(TY); \ | |
343 types.push_back(rt_dg1()); \ | |
344 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
345 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
346 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
347 } | |
348 STR_APPLY_R1(stringTy, "_aApplyRcw1", "_aApplyRcd1") | |
349 STR_APPLY_R1(wstringTy, "_aApplyRwc1", "_aApplyRwd1") | |
350 STR_APPLY_R1(dstringTy, "_aApplyRdc1", "_aApplyRdw1") | |
351 #undef STR_APPLY | |
352 | |
353 #define STR_APPLY_R2(TY,a,b) \ | |
354 { \ | |
355 std::string fname(a); \ | |
356 std::string fname2(b); \ | |
357 std::vector<const llvm::Type*> types; \ | |
358 types.push_back(TY); \ | |
359 types.push_back(rt_dg2()); \ | |
360 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
361 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
362 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
363 } | |
364 STR_APPLY_R2(stringTy, "_aApplyRcw2", "_aApplyRcd2") | |
365 STR_APPLY_R2(wstringTy, "_aApplyRwc2", "_aApplyRwd2") | |
366 STR_APPLY_R2(dstringTy, "_aApplyRdc2", "_aApplyRdw2") | |
367 #undef STR_APPLY2 | |
368 | |
369 ///////////////////////////////////////////////////////////////////////////////////// | |
370 ///////////////////////////////////////////////////////////////////////////////////// | |
371 ///////////////////////////////////////////////////////////////////////////////////// | |
372 | |
373 // fixes the length for dynamic array casts | |
374 // size_t _d_array_cast_len(size_t len, size_t elemsz, size_t newelemsz) | |
375 { | |
376 std::string fname("_d_array_cast_len"); | |
377 std::vector<const llvm::Type*> types; | |
378 types.push_back(sizeTy); | |
379 types.push_back(sizeTy); | |
380 types.push_back(sizeTy); | |
381 const llvm::FunctionType* fty = llvm::FunctionType::get(sizeTy, types, false); | |
382 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
383 } | |
384 | |
385 ///////////////////////////////////////////////////////////////////////////////////// | |
386 ///////////////////////////////////////////////////////////////////////////////////// | |
387 ///////////////////////////////////////////////////////////////////////////////////// | |
388 | |
389 // builds the d string[] for the D main args from the C main args | |
390 // void _d_main_args(uint n, char** args, ref char[][] res) | |
391 { | |
392 std::string fname("_d_main_args"); | |
393 std::vector<const llvm::Type*> types; | |
394 types.push_back(intTy); | |
395 types.push_back(rt_ptr(rt_ptr(byteTy))); | |
396 types.push_back(rt_array(stringTy->getContainedType(0))); | |
397 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
398 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
399 } | |
400 | |
401 ///////////////////////////////////////////////////////////////////////////////////// | |
402 ///////////////////////////////////////////////////////////////////////////////////// | |
403 ///////////////////////////////////////////////////////////////////////////////////// | |
404 | |
405 // cast to object | |
406 // Object _d_toObject(void* p) | |
407 { | |
408 std::string fname("_d_toObject"); | |
409 std::vector<const llvm::Type*> types; | |
410 types.push_back(voidPtrTy); | |
411 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); | |
412 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
413 } | |
414 | |
415 // cast interface | |
416 // Object _d_interface_cast(void* p, ClassInfo c) | |
417 { | |
418 std::string fname("_d_interface_cast"); | |
419 std::vector<const llvm::Type*> types; | |
420 types.push_back(voidPtrTy); | |
421 types.push_back(classInfoTy); | |
422 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); | |
423 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
424 } | |
425 | |
426 // dynamic cast | |
427 // Object _d_dynamic_cast(Object o, ClassInfo c) | |
428 { | |
429 std::string fname("_d_dynamic_cast"); | |
430 std::vector<const llvm::Type*> types; | |
431 types.push_back(objectTy); | |
432 types.push_back(classInfoTy); | |
433 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); | |
434 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
435 } | |
436 | |
437 ///////////////////////////////////////////////////////////////////////////////////// | |
438 ///////////////////////////////////////////////////////////////////////////////////// | |
439 ///////////////////////////////////////////////////////////////////////////////////// | |
440 | |
441 // char[] _adReverseChar(char[] a) | |
442 // char[] _adSortChar(char[] a) | |
443 { | |
444 std::string fname("_adReverseChar"); | |
445 std::string fname2("_adSortChar"); | |
446 std::vector<const llvm::Type*> types; | |
447 types.push_back(stringTy); | |
448 types.push_back(stringTy); | |
449 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
450 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
451 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
452 } | |
453 | |
454 // wchar[] _adReverseWchar(wchar[] a) | |
455 // wchar[] _adSortWchar(wchar[] a) | |
456 { | |
457 std::string fname("_adReverseWchar"); | |
458 std::string fname2("_adSortWchar"); | |
459 std::vector<const llvm::Type*> types; | |
460 types.push_back(wstringTy); | |
461 types.push_back(wstringTy); | |
462 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
463 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
464 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
465 } | |
466 | |
467 // Array _adReverse(Array a, size_t szelem) | |
468 { | |
469 std::string fname("_adReverse"); | |
470 std::vector<const llvm::Type*> types; | |
471 types.push_back(rt_array(byteTy)); | |
472 types.push_back(rt_array(byteTy)); | |
473 types.push_back(sizeTy); | |
474 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
475 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
476 } | |
477 | |
478 // Array _adDupT(TypeInfo ti, Array a) | |
479 { | |
480 std::string fname("_adDupT"); | |
481 std::vector<const llvm::Type*> types; | |
482 types.push_back(rt_array(byteTy)); | |
483 types.push_back(typeInfoTy); | |
484 types.push_back(rt_array(byteTy)); | |
485 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
486 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
487 } | |
488 | |
489 // int _adEq(Array a1, Array a2, TypeInfo ti) | |
490 // int _adCmp(Array a1, Array a2, TypeInfo ti) | |
491 { | |
492 std::string fname("_adEq"); | |
493 std::string fname2("_adCmp"); | |
494 std::vector<const llvm::Type*> types; | |
495 types.push_back(rt_array(byteTy)); | |
496 types.push_back(rt_array(byteTy)); | |
497 types.push_back(typeInfoTy); | |
498 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
499 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
500 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
501 } | |
502 | |
503 // int _adCmpChar(Array a1, Array a2) | |
504 { | |
505 std::string fname("_adCmpChar"); | |
506 std::vector<const llvm::Type*> types; | |
507 types.push_back(rt_array(byteTy)); | |
508 types.push_back(rt_array(byteTy)); | |
509 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
510 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
511 } | |
512 | |
513 // Array _adSort(Array a, TypeInfo ti) | |
514 { | |
515 std::string fname("_adSort"); | |
516 std::vector<const llvm::Type*> types; | |
517 types.push_back(rt_array(byteTy)); | |
518 types.push_back(rt_array(byteTy)); | |
519 types.push_back(typeInfoTy); | |
520 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
521 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
522 } | |
523 | |
524 ///////////////////////////////////////////////////////////////////////////////////// | |
525 ///////////////////////////////////////////////////////////////////////////////////// | |
526 ///////////////////////////////////////////////////////////////////////////////////// | |
527 | |
528 // size_t _aaLen(AA aa) | |
529 { | |
530 std::string fname("_aaLen"); | |
531 std::vector<const llvm::Type*> types; | |
532 types.push_back(aaTy); | |
533 const llvm::FunctionType* fty = llvm::FunctionType::get(sizeTy, types, false); | |
534 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
535 } | |
536 | |
537 // void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize) | |
538 { | |
539 std::string fname("_aaGet"); | |
540 std::vector<const llvm::Type*> types; | |
541 types.push_back(aaTy); | |
542 types.push_back(typeInfoTy); | |
543 types.push_back(voidPtrTy); | |
544 types.push_back(sizeTy); | |
545 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
546 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
547 } | |
548 | |
549 // void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey) | |
550 { | |
551 std::string fname("_aaGetRvalue"); | |
552 std::vector<const llvm::Type*> types; | |
553 types.push_back(aaTy); | |
554 types.push_back(typeInfoTy); | |
555 types.push_back(sizeTy); | |
556 types.push_back(voidPtrTy); | |
557 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
558 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
559 } | |
560 | |
561 // void* _aaIn(AA aa, TypeInfo keyti, void* pkey) | |
562 { | |
563 std::string fname("_aaIn"); | |
564 std::vector<const llvm::Type*> types; | |
565 types.push_back(aaTy); | |
566 types.push_back(typeInfoTy); | |
567 types.push_back(voidPtrTy); | |
568 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
569 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
570 } | |
571 | |
572 // void _aaDel(AA aa, TypeInfo keyti, void* pkey) | |
573 { | |
574 std::string fname("_aaDel"); | |
575 std::vector<const llvm::Type*> types; | |
576 types.push_back(aaTy); | |
577 types.push_back(typeInfoTy); | |
578 types.push_back(voidPtrTy); | |
579 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
580 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
581 } | |
582 | |
583 // ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize) | |
584 { | |
585 std::string fname("_aaValues"); | |
586 std::vector<const llvm::Type*> types; | |
587 types.push_back(rt_array(byteTy)); | |
588 types.push_back(aaTy); | |
589 types.push_back(sizeTy); | |
590 types.push_back(sizeTy); | |
591 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
592 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
593 } | |
594 | |
595 // void* _aaRehash(AA* paa, TypeInfo keyti) | |
596 { | |
597 std::string fname("_aaRehash"); | |
598 std::vector<const llvm::Type*> types; | |
599 types.push_back(aaTy); | |
600 types.push_back(typeInfoTy); | |
601 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
602 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
603 } | |
604 | |
605 // ArrayRet_t _aaKeys(AA aa, size_t keysize) | |
606 { | |
607 std::string fname("_aaKeys"); | |
608 std::vector<const llvm::Type*> types; | |
609 types.push_back(rt_array(byteTy)); | |
610 types.push_back(aaTy); | |
611 types.push_back(sizeTy); | |
612 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
613 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
614 } | |
615 | |
616 // int _aaApply(AA aa, size_t keysize, dg_t dg) | |
617 { | |
618 std::string fname("_aaApply"); | |
619 std::vector<const llvm::Type*> types; | |
620 types.push_back(aaTy); | |
621 types.push_back(sizeTy); | |
622 types.push_back(rt_dg1()); | |
623 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
624 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
625 } | |
626 | |
627 // int _aaApply2(AA aa, size_t keysize, dg2_t dg) | |
628 { | |
629 std::string fname("_aaApply2"); | |
630 std::vector<const llvm::Type*> types; | |
631 types.push_back(aaTy); | |
632 types.push_back(sizeTy); | |
633 types.push_back(rt_dg1()); | |
634 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
635 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
636 } | |
637 | |
638 ///////////////////////////////////////////////////////////////////////////////////// | |
639 ///////////////////////////////////////////////////////////////////////////////////// | |
640 ///////////////////////////////////////////////////////////////////////////////////// | |
641 | |
642 // void _moduleCtor() | |
643 // void _moduleDtor() | |
644 { | |
645 std::string fname("_moduleCtor"); | |
646 std::string fname2("_moduleDtor"); | |
647 std::vector<const llvm::Type*> types; | |
648 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
649 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
650 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
651 } | |
652 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
653 ///////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
654 ///////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
655 ///////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
656 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
657 // Object _d_toObject(void* p) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
658 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
659 std::string fname("_d_toObject"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
660 std::vector<const llvm::Type*> types; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
661 types.push_back(voidPtrTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
662 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
663 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
664 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
665 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
666 // Object _d_dynamic_cast(Object o, ClassInfo c) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
667 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
668 std::string fname("_d_dynamic_cast"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
669 std::vector<const llvm::Type*> types; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
670 types.push_back(objectTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
671 types.push_back(classInfoTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
672 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
673 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
674 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
675 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
676 // Object _d_interface_cast(void* p, ClassInfo c) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
677 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
678 std::string fname("_d_interface_cast"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
679 std::vector<const llvm::Type*> types; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
680 types.push_back(voidPtrTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
681 types.push_back(classInfoTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
682 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
683 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
684 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
685 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
686 ///////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
687 ///////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
688 ///////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
689 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
690 // void _d_throw_exception(Object e) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
691 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
692 std::string fname("_d_throw_exception"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
693 std::vector<const llvm::Type*> types; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
694 types.push_back(objectTy); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
695 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
696 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
697 } |
132 | 698 } |
699 | |
700 | |
701 | |
702 | |
703 | |
704 |