Mercurial > projects > ldc
annotate gen/runtime.cpp @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | 6789050b5ad1 |
children | 44a95ac7368a |
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 { | |
136 return llvm::PointerType::get(t); | |
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 | |
200 // assert | |
201 // void _d_assert(bool cond, uint line, char[] msg) | |
202 { | |
203 std::string fname("_d_assert"); | |
204 std::vector<const llvm::Type*> types; | |
205 types.push_back(boolTy); | |
206 types.push_back(intTy); | |
207 types.push_back(stringTy); | |
208 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
209 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
210 } | |
211 | |
212 ///////////////////////////////////////////////////////////////////////////////////// | |
213 ///////////////////////////////////////////////////////////////////////////////////// | |
214 ///////////////////////////////////////////////////////////////////////////////////// | |
215 | |
216 // realloc | |
217 // void* _d_realloc(void* ptr, size_t n) | |
218 { | |
219 std::string fname("_d_realloc"); | |
220 std::vector<const llvm::Type*> types; | |
221 types.push_back(voidPtrTy); | |
222 types.push_back(sizeTy); | |
223 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
224 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
225 } | |
226 | |
227 // free | |
228 // void _d_free(void* ptr) | |
229 { | |
230 std::string fname("_d_free"); | |
231 std::vector<const llvm::Type*> types; | |
232 types.push_back(voidPtrTy); | |
233 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
234 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
235 } | |
236 | |
237 ///////////////////////////////////////////////////////////////////////////////////// | |
238 ///////////////////////////////////////////////////////////////////////////////////// | |
239 ///////////////////////////////////////////////////////////////////////////////////// | |
240 | |
241 #define ARRAY_INIT(TY,suffix) \ | |
242 { \ | |
243 std::string fname("_d_array_init_"); \ | |
244 fname.append(suffix); \ | |
245 std::vector<const llvm::Type*> types; \ | |
246 types.push_back(rt_ptr(TY)); \ | |
247 types.push_back(sizeTy); \ | |
248 types.push_back(TY); \ | |
249 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); \ | |
250 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
251 } | |
252 | |
253 ARRAY_INIT(boolTy,"i1") | |
254 ARRAY_INIT(byteTy,"i8") | |
255 ARRAY_INIT(shortTy,"i16") | |
256 ARRAY_INIT(intTy,"i32") | |
257 ARRAY_INIT(longTy,"i64") | |
258 ARRAY_INIT(floatTy,"float") | |
259 ARRAY_INIT(doubleTy,"double") | |
260 ARRAY_INIT(voidPtrTy,"pointer") | |
261 | |
262 #undef ARRAY_INIT | |
263 | |
264 // array init mem | |
265 // void _d_array_init_mem(void* a, size_t na, void* v, size_t nv) | |
266 { | |
267 std::string fname("_d_array_init_mem"); | |
268 std::vector<const llvm::Type*> types; | |
269 types.push_back(voidPtrTy); | |
270 types.push_back(sizeTy); | |
271 types.push_back(voidPtrTy); | |
272 types.push_back(sizeTy); | |
273 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
274 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
275 } | |
276 | |
277 ///////////////////////////////////////////////////////////////////////////////////// | |
278 ///////////////////////////////////////////////////////////////////////////////////// | |
279 ///////////////////////////////////////////////////////////////////////////////////// | |
280 | |
281 #define STR_APPLY1(TY,a,b) \ | |
282 { \ | |
283 std::string fname(a); \ | |
284 std::string fname2(b); \ | |
285 std::vector<const llvm::Type*> types; \ | |
286 types.push_back(TY); \ | |
287 types.push_back(rt_dg1()); \ | |
288 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
289 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
290 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
291 } | |
292 STR_APPLY1(stringTy, "_aApplycw1", "_aApplycd1") | |
293 STR_APPLY1(wstringTy, "_aApplywc1", "_aApplywd1") | |
294 STR_APPLY1(dstringTy, "_aApplydc1", "_aApplydw1") | |
295 #undef STR_APPLY | |
296 | |
297 #define STR_APPLY2(TY,a,b) \ | |
298 { \ | |
299 std::string fname(a); \ | |
300 std::string fname2(b); \ | |
301 std::vector<const llvm::Type*> types; \ | |
302 types.push_back(TY); \ | |
303 types.push_back(rt_dg2()); \ | |
304 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
305 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
306 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
307 } | |
308 STR_APPLY2(stringTy, "_aApplycw2", "_aApplycd2") | |
309 STR_APPLY2(wstringTy, "_aApplywc2", "_aApplywd2") | |
310 STR_APPLY2(dstringTy, "_aApplydc2", "_aApplydw2") | |
311 #undef STR_APPLY2 | |
312 | |
313 #define STR_APPLY_R1(TY,a,b) \ | |
314 { \ | |
315 std::string fname(a); \ | |
316 std::string fname2(b); \ | |
317 std::vector<const llvm::Type*> types; \ | |
318 types.push_back(TY); \ | |
319 types.push_back(rt_dg1()); \ | |
320 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
321 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
322 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
323 } | |
324 STR_APPLY_R1(stringTy, "_aApplyRcw1", "_aApplyRcd1") | |
325 STR_APPLY_R1(wstringTy, "_aApplyRwc1", "_aApplyRwd1") | |
326 STR_APPLY_R1(dstringTy, "_aApplyRdc1", "_aApplyRdw1") | |
327 #undef STR_APPLY | |
328 | |
329 #define STR_APPLY_R2(TY,a,b) \ | |
330 { \ | |
331 std::string fname(a); \ | |
332 std::string fname2(b); \ | |
333 std::vector<const llvm::Type*> types; \ | |
334 types.push_back(TY); \ | |
335 types.push_back(rt_dg2()); \ | |
336 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ | |
337 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \ | |
338 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \ | |
339 } | |
340 STR_APPLY_R2(stringTy, "_aApplyRcw2", "_aApplyRcd2") | |
341 STR_APPLY_R2(wstringTy, "_aApplyRwc2", "_aApplyRwd2") | |
342 STR_APPLY_R2(dstringTy, "_aApplyRdc2", "_aApplyRdw2") | |
343 #undef STR_APPLY2 | |
344 | |
345 ///////////////////////////////////////////////////////////////////////////////////// | |
346 ///////////////////////////////////////////////////////////////////////////////////// | |
347 ///////////////////////////////////////////////////////////////////////////////////// | |
348 | |
349 // fixes the length for dynamic array casts | |
350 // size_t _d_array_cast_len(size_t len, size_t elemsz, size_t newelemsz) | |
351 { | |
352 std::string fname("_d_array_cast_len"); | |
353 std::vector<const llvm::Type*> types; | |
354 types.push_back(sizeTy); | |
355 types.push_back(sizeTy); | |
356 types.push_back(sizeTy); | |
357 const llvm::FunctionType* fty = llvm::FunctionType::get(sizeTy, types, false); | |
358 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
359 } | |
360 | |
361 ///////////////////////////////////////////////////////////////////////////////////// | |
362 ///////////////////////////////////////////////////////////////////////////////////// | |
363 ///////////////////////////////////////////////////////////////////////////////////// | |
364 | |
365 // builds the d string[] for the D main args from the C main args | |
366 // void _d_main_args(uint n, char** args, ref char[][] res) | |
367 { | |
368 std::string fname("_d_main_args"); | |
369 std::vector<const llvm::Type*> types; | |
370 types.push_back(intTy); | |
371 types.push_back(rt_ptr(rt_ptr(byteTy))); | |
372 types.push_back(rt_array(stringTy->getContainedType(0))); | |
373 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
374 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
375 } | |
376 | |
377 ///////////////////////////////////////////////////////////////////////////////////// | |
378 ///////////////////////////////////////////////////////////////////////////////////// | |
379 ///////////////////////////////////////////////////////////////////////////////////// | |
380 | |
381 // cast to object | |
382 // Object _d_toObject(void* p) | |
383 { | |
384 std::string fname("_d_toObject"); | |
385 std::vector<const llvm::Type*> types; | |
386 types.push_back(voidPtrTy); | |
387 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); | |
388 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
389 } | |
390 | |
391 // cast interface | |
392 // Object _d_interface_cast(void* p, ClassInfo c) | |
393 { | |
394 std::string fname("_d_interface_cast"); | |
395 std::vector<const llvm::Type*> types; | |
396 types.push_back(voidPtrTy); | |
397 types.push_back(classInfoTy); | |
398 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); | |
399 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
400 } | |
401 | |
402 // dynamic cast | |
403 // Object _d_dynamic_cast(Object o, ClassInfo c) | |
404 { | |
405 std::string fname("_d_dynamic_cast"); | |
406 std::vector<const llvm::Type*> types; | |
407 types.push_back(objectTy); | |
408 types.push_back(classInfoTy); | |
409 const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); | |
410 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
411 } | |
412 | |
413 ///////////////////////////////////////////////////////////////////////////////////// | |
414 ///////////////////////////////////////////////////////////////////////////////////// | |
415 ///////////////////////////////////////////////////////////////////////////////////// | |
416 | |
417 // char[] _adReverseChar(char[] a) | |
418 // char[] _adSortChar(char[] a) | |
419 { | |
420 std::string fname("_adReverseChar"); | |
421 std::string fname2("_adSortChar"); | |
422 std::vector<const llvm::Type*> types; | |
423 types.push_back(stringTy); | |
424 types.push_back(stringTy); | |
425 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
426 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
427 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
428 } | |
429 | |
430 // wchar[] _adReverseWchar(wchar[] a) | |
431 // wchar[] _adSortWchar(wchar[] a) | |
432 { | |
433 std::string fname("_adReverseWchar"); | |
434 std::string fname2("_adSortWchar"); | |
435 std::vector<const llvm::Type*> types; | |
436 types.push_back(wstringTy); | |
437 types.push_back(wstringTy); | |
438 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
439 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
440 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
441 } | |
442 | |
443 // Array _adReverse(Array a, size_t szelem) | |
444 { | |
445 std::string fname("_adReverse"); | |
446 std::vector<const llvm::Type*> types; | |
447 types.push_back(rt_array(byteTy)); | |
448 types.push_back(rt_array(byteTy)); | |
449 types.push_back(sizeTy); | |
450 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
451 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
452 } | |
453 | |
454 // Array _adDupT(TypeInfo ti, Array a) | |
455 { | |
456 std::string fname("_adDupT"); | |
457 std::vector<const llvm::Type*> types; | |
458 types.push_back(rt_array(byteTy)); | |
459 types.push_back(typeInfoTy); | |
460 types.push_back(rt_array(byteTy)); | |
461 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
462 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
463 } | |
464 | |
465 // int _adEq(Array a1, Array a2, TypeInfo ti) | |
466 // int _adCmp(Array a1, Array a2, TypeInfo ti) | |
467 { | |
468 std::string fname("_adEq"); | |
469 std::string fname2("_adCmp"); | |
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(typeInfoTy); | |
474 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
475 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
476 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
477 } | |
478 | |
479 // int _adCmpChar(Array a1, Array a2) | |
480 { | |
481 std::string fname("_adCmpChar"); | |
482 std::vector<const llvm::Type*> types; | |
483 types.push_back(rt_array(byteTy)); | |
484 types.push_back(rt_array(byteTy)); | |
485 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
486 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
487 } | |
488 | |
489 // Array _adSort(Array a, TypeInfo ti) | |
490 { | |
491 std::string fname("_adSort"); | |
492 std::vector<const llvm::Type*> types; | |
493 types.push_back(rt_array(byteTy)); | |
494 types.push_back(rt_array(byteTy)); | |
495 types.push_back(typeInfoTy); | |
496 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
497 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
498 } | |
499 | |
500 ///////////////////////////////////////////////////////////////////////////////////// | |
501 ///////////////////////////////////////////////////////////////////////////////////// | |
502 ///////////////////////////////////////////////////////////////////////////////////// | |
503 | |
504 // size_t _aaLen(AA aa) | |
505 { | |
506 std::string fname("_aaLen"); | |
507 std::vector<const llvm::Type*> types; | |
508 types.push_back(aaTy); | |
509 const llvm::FunctionType* fty = llvm::FunctionType::get(sizeTy, types, false); | |
510 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
511 } | |
512 | |
513 // void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize) | |
514 { | |
515 std::string fname("_aaGet"); | |
516 std::vector<const llvm::Type*> types; | |
517 types.push_back(aaTy); | |
518 types.push_back(typeInfoTy); | |
519 types.push_back(voidPtrTy); | |
520 types.push_back(sizeTy); | |
521 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
522 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
523 } | |
524 | |
525 // void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey) | |
526 { | |
527 std::string fname("_aaGetRvalue"); | |
528 std::vector<const llvm::Type*> types; | |
529 types.push_back(aaTy); | |
530 types.push_back(typeInfoTy); | |
531 types.push_back(sizeTy); | |
532 types.push_back(voidPtrTy); | |
533 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
534 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
535 } | |
536 | |
537 // void* _aaIn(AA aa, TypeInfo keyti, void* pkey) | |
538 { | |
539 std::string fname("_aaIn"); | |
540 std::vector<const llvm::Type*> types; | |
541 types.push_back(aaTy); | |
542 types.push_back(typeInfoTy); | |
543 types.push_back(voidPtrTy); | |
544 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
545 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
546 } | |
547 | |
548 // void _aaDel(AA aa, TypeInfo keyti, void* pkey) | |
549 { | |
550 std::string fname("_aaDel"); | |
551 std::vector<const llvm::Type*> types; | |
552 types.push_back(aaTy); | |
553 types.push_back(typeInfoTy); | |
554 types.push_back(voidPtrTy); | |
555 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
556 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
557 } | |
558 | |
559 // ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize) | |
560 { | |
561 std::string fname("_aaValues"); | |
562 std::vector<const llvm::Type*> types; | |
563 types.push_back(rt_array(byteTy)); | |
564 types.push_back(aaTy); | |
565 types.push_back(sizeTy); | |
566 types.push_back(sizeTy); | |
567 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
568 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
569 } | |
570 | |
571 // void* _aaRehash(AA* paa, TypeInfo keyti) | |
572 { | |
573 std::string fname("_aaRehash"); | |
574 std::vector<const llvm::Type*> types; | |
575 types.push_back(aaTy); | |
576 types.push_back(typeInfoTy); | |
577 const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); | |
578 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
579 } | |
580 | |
581 // ArrayRet_t _aaKeys(AA aa, size_t keysize) | |
582 { | |
583 std::string fname("_aaKeys"); | |
584 std::vector<const llvm::Type*> types; | |
585 types.push_back(rt_array(byteTy)); | |
586 types.push_back(aaTy); | |
587 types.push_back(sizeTy); | |
588 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
589 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
590 } | |
591 | |
592 // int _aaApply(AA aa, size_t keysize, dg_t dg) | |
593 { | |
594 std::string fname("_aaApply"); | |
595 std::vector<const llvm::Type*> types; | |
596 types.push_back(aaTy); | |
597 types.push_back(sizeTy); | |
598 types.push_back(rt_dg1()); | |
599 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
600 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
601 } | |
602 | |
603 // int _aaApply2(AA aa, size_t keysize, dg2_t dg) | |
604 { | |
605 std::string fname("_aaApply2"); | |
606 std::vector<const llvm::Type*> types; | |
607 types.push_back(aaTy); | |
608 types.push_back(sizeTy); | |
609 types.push_back(rt_dg1()); | |
610 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); | |
611 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
612 } | |
613 | |
614 ///////////////////////////////////////////////////////////////////////////////////// | |
615 ///////////////////////////////////////////////////////////////////////////////////// | |
616 ///////////////////////////////////////////////////////////////////////////////////// | |
617 | |
618 // void _moduleCtor() | |
619 // void _moduleDtor() | |
620 { | |
621 std::string fname("_moduleCtor"); | |
622 std::string fname2("_moduleDtor"); | |
623 std::vector<const llvm::Type*> types; | |
624 const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); | |
625 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname, M); | |
626 new llvm::Function(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); | |
627 } | |
628 | |
629 } | |
630 | |
631 | |
632 | |
633 | |
634 | |
635 |