comparison 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
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
5 #include "llvm/Bitcode/ReaderWriter.h" 5 #include "llvm/Bitcode/ReaderWriter.h"
6 #include "llvm/Support/MemoryBuffer.h" 6 #include "llvm/Support/MemoryBuffer.h"
7 7
8 #include "root.h" 8 #include "root.h"
9 #include "mars.h" 9 #include "mars.h"
10 #include "lexer.h"
11 #include "dsymbol.h"
12 #include "mtype.h"
13 #include "aggregate.h"
10 14
11 #include "gen/runtime.h" 15 #include "gen/runtime.h"
12 #include "gen/logger.h" 16 #include "gen/logger.h"
17 #include "gen/tollvm.h"
13 18
14 static llvm::Module* M = NULL; 19 static llvm::Module* M = NULL;
15 static bool runtime_failed = false; 20 static bool runtime_failed = false;
16 21
22 static void LLVM_D_BuildRuntimeModule();
23
17 ////////////////////////////////////////////////////////////////////////////////////////////////// 24 //////////////////////////////////////////////////////////////////////////////////////////////////
18 25
19 bool LLVM_D_InitRuntime() 26 bool LLVM_D_InitRuntime()
20 { 27 {
21 Logger::println("*** Loading D runtime ***"); 28 Logger::println("*** Initializing D runtime declarations ***");
22 LOG_SCOPE; 29 LOG_SCOPE;
23 30
31 LLVM_D_BuildRuntimeModule();
32 return true;
33
34 /*
24 if (!global.params.runtimeImppath) { 35 if (!global.params.runtimeImppath) {
25 error("You must set the runtime import path with -E"); 36 error("You must set the runtime import path with -E");
26 fatal(); 37 fatal();
27 } 38 }
28 std::string filename(global.params.runtimeImppath); 39 std::string filename(global.params.runtimeImppath);
45 runtime_failed = true; 56 runtime_failed = true;
46 } 57 }
47 58
48 delete buffer; 59 delete buffer;
49 return retval; 60 return retval;
61 */
50 } 62 }
51 63
52 void LLVM_D_FreeRuntime() 64 void LLVM_D_FreeRuntime()
53 { 65 {
54 if (M) { 66 if (M) {
55 Logger::println("*** Freeing D runtime ***"); 67 Logger::println("*** Freeing D runtime declarations ***");
56 delete M; 68 delete M;
69 M = NULL;
57 } 70 }
58 } 71 }
59 72
60 ////////////////////////////////////////////////////////////////////////////////////////////////// 73 //////////////////////////////////////////////////////////////////////////////////////////////////
61 74
88 101
89 ////////////////////////////////////////////////////////////////////////////////////////////////// 102 //////////////////////////////////////////////////////////////////////////////////////////////////
90 103
91 llvm::GlobalVariable* LLVM_D_GetRuntimeGlobal(llvm::Module* target, const char* name) 104 llvm::GlobalVariable* LLVM_D_GetRuntimeGlobal(llvm::Module* target, const char* name)
92 { 105 {
93 // TODO maybe check the target module first, to allow overriding the runtime on a pre module basis?
94 // could be done and seems like it could be neat too :)
95
96 llvm::GlobalVariable* gv = target->getNamedGlobal(name); 106 llvm::GlobalVariable* gv = target->getNamedGlobal(name);
97 if (gv) { 107 if (gv) {
98 return gv; 108 return gv;
99 } 109 }
100 110
116 } 126 }
117 127
118 const llvm::PointerType* t = g->getType(); 128 const llvm::PointerType* t = g->getType();
119 return new llvm::GlobalVariable(t->getElementType(),g->isConstant(),g->getLinkage(),NULL,g->getName(),target); 129 return new llvm::GlobalVariable(t->getElementType(),g->isConstant(),g->getLinkage(),NULL,g->getName(),target);
120 } 130 }
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