comparison gen/runtime.cpp @ 719:7261ff0f95ff

Implemented first class delegates. closes #101
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 22 Oct 2008 21:50:08 +0200
parents 30b42a283c8e
children 635f91212b78
comparison
equal deleted inserted replaced
718:72ee105be27b 719:7261ff0f95ff
117 { 117 {
118 std::vector<const LLType*> types; 118 std::vector<const LLType*> types;
119 types.push_back(rt_ptr(LLType::Int8Ty)); 119 types.push_back(rt_ptr(LLType::Int8Ty));
120 types.push_back(rt_ptr(LLType::Int8Ty)); 120 types.push_back(rt_ptr(LLType::Int8Ty));
121 const llvm::FunctionType* fty = llvm::FunctionType::get(LLType::Int32Ty, types, false); 121 const llvm::FunctionType* fty = llvm::FunctionType::get(LLType::Int32Ty, types, false);
122 122 return llvm::StructType::get(rt_ptr(LLType::Int8Ty), rt_ptr(fty), 0);
123 std::vector<const LLType*> t;
124 t.push_back(rt_ptr(LLType::Int8Ty));
125 t.push_back(rt_ptr(fty));
126 return rt_ptr(llvm::StructType::get(t));
127 } 123 }
128 124
129 static const LLType* rt_dg2() 125 static const LLType* rt_dg2()
130 { 126 {
131 std::vector<const LLType*> types; 127 std::vector<const LLType*> types;
132 types.push_back(rt_ptr(LLType::Int8Ty)); 128 types.push_back(rt_ptr(LLType::Int8Ty));
133 types.push_back(rt_ptr(LLType::Int8Ty)); 129 types.push_back(rt_ptr(LLType::Int8Ty));
134 types.push_back(rt_ptr(LLType::Int8Ty)); 130 types.push_back(rt_ptr(LLType::Int8Ty));
135 const llvm::FunctionType* fty = llvm::FunctionType::get(LLType::Int32Ty, types, false); 131 const llvm::FunctionType* fty = llvm::FunctionType::get(LLType::Int32Ty, types, false);
136 132 return llvm::StructType::get(rt_ptr(LLType::Int8Ty), rt_ptr(fty), 0);
137 std::vector<const LLType*> t;
138 t.push_back(rt_ptr(LLType::Int8Ty));
139 t.push_back(rt_ptr(fty));
140 return rt_ptr(llvm::StructType::get(t));
141 } 133 }
142 134
143 static void LLVM_D_BuildRuntimeModule() 135 static void LLVM_D_BuildRuntimeModule()
144 { 136 {
145 M = new llvm::Module("ldc internal runtime"); 137 M = new llvm::Module("ldc internal runtime");
363 std::string fname2(b); \ 355 std::string fname2(b); \
364 std::vector<const LLType*> types; \ 356 std::vector<const LLType*> types; \
365 types.push_back(TY); \ 357 types.push_back(TY); \
366 types.push_back(rt_dg1()); \ 358 types.push_back(rt_dg1()); \
367 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ 359 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
368 llvm::AttrListPtr palist; \ 360 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \
369 palist = palist.addAttr(2, llvm::Attribute::ByVal); \ 361 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \
370 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M)->setAttributes(palist); \
371 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M)->setAttributes(palist); \
372 } 362 }
373 STR_APPLY1(stringTy, "_aApplycw1", "_aApplycd1") 363 STR_APPLY1(stringTy, "_aApplycw1", "_aApplycd1")
374 STR_APPLY1(wstringTy, "_aApplywc1", "_aApplywd1") 364 STR_APPLY1(wstringTy, "_aApplywc1", "_aApplywd1")
375 STR_APPLY1(dstringTy, "_aApplydc1", "_aApplydw1") 365 STR_APPLY1(dstringTy, "_aApplydc1", "_aApplydw1")
376 #undef STR_APPLY 366 #undef STR_APPLY
382 std::string fname2(b); \ 372 std::string fname2(b); \
383 std::vector<const LLType*> types; \ 373 std::vector<const LLType*> types; \
384 types.push_back(TY); \ 374 types.push_back(TY); \
385 types.push_back(rt_dg2()); \ 375 types.push_back(rt_dg2()); \
386 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ 376 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
387 llvm::AttrListPtr palist; \ 377 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \
388 palist = palist.addAttr(2, llvm::Attribute::ByVal); \ 378 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \
389 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M)->setAttributes(palist); \
390 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M)->setAttributes(palist); \
391 } 379 }
392 STR_APPLY2(stringTy, "_aApplycw2", "_aApplycd2") 380 STR_APPLY2(stringTy, "_aApplycw2", "_aApplycd2")
393 STR_APPLY2(wstringTy, "_aApplywc2", "_aApplywd2") 381 STR_APPLY2(wstringTy, "_aApplywc2", "_aApplywd2")
394 STR_APPLY2(dstringTy, "_aApplydc2", "_aApplydw2") 382 STR_APPLY2(dstringTy, "_aApplydc2", "_aApplydw2")
395 #undef STR_APPLY2 383 #undef STR_APPLY2
400 std::string fname2(b); \ 388 std::string fname2(b); \
401 std::vector<const LLType*> types; \ 389 std::vector<const LLType*> types; \
402 types.push_back(TY); \ 390 types.push_back(TY); \
403 types.push_back(rt_dg1()); \ 391 types.push_back(rt_dg1()); \
404 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ 392 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
405 llvm::AttrListPtr palist; \ 393 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \
406 palist = palist.addAttr(2, llvm::Attribute::ByVal); \ 394 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \
407 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M)->setAttributes(palist); \
408 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M)->setAttributes(palist); \
409 } 395 }
410 STR_APPLY_R1(stringTy, "_aApplyRcw1", "_aApplyRcd1") 396 STR_APPLY_R1(stringTy, "_aApplyRcw1", "_aApplyRcd1")
411 STR_APPLY_R1(wstringTy, "_aApplyRwc1", "_aApplyRwd1") 397 STR_APPLY_R1(wstringTy, "_aApplyRwc1", "_aApplyRwd1")
412 STR_APPLY_R1(dstringTy, "_aApplyRdc1", "_aApplyRdw1") 398 STR_APPLY_R1(dstringTy, "_aApplyRdc1", "_aApplyRdw1")
413 #undef STR_APPLY 399 #undef STR_APPLY
418 std::string fname2(b); \ 404 std::string fname2(b); \
419 std::vector<const LLType*> types; \ 405 std::vector<const LLType*> types; \
420 types.push_back(TY); \ 406 types.push_back(TY); \
421 types.push_back(rt_dg2()); \ 407 types.push_back(rt_dg2()); \
422 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ 408 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \
423 llvm::AttrListPtr palist; \ 409 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); \
424 palist = palist.addAttr(2, llvm::Attribute::ByVal); \ 410 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); \
425 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M)->setAttributes(palist); \
426 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M)->setAttributes(palist); \
427 } 411 }
428 STR_APPLY_R2(stringTy, "_aApplyRcw2", "_aApplyRcd2") 412 STR_APPLY_R2(stringTy, "_aApplyRcw2", "_aApplyRcd2")
429 STR_APPLY_R2(wstringTy, "_aApplyRwc2", "_aApplyRwd2") 413 STR_APPLY_R2(wstringTy, "_aApplyRwc2", "_aApplyRwd2")
430 STR_APPLY_R2(dstringTy, "_aApplyRdc2", "_aApplyRdw2") 414 STR_APPLY_R2(dstringTy, "_aApplyRdc2", "_aApplyRdw2")
431 #undef STR_APPLY2 415 #undef STR_APPLY2
660 std::vector<const LLType*> types; 644 std::vector<const LLType*> types;
661 types.push_back(aaTy); 645 types.push_back(aaTy);
662 types.push_back(sizeTy); 646 types.push_back(sizeTy);
663 types.push_back(rt_dg1()); 647 types.push_back(rt_dg1());
664 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); 648 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false);
665 llvm::AttrListPtr palist; 649 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
666 palist = palist.addAttr(3, llvm::Attribute::ByVal);
667 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M)->setAttributes(palist);
668 } 650 }
669 651
670 // int _aaApply2(AA aa, size_t keysize, dg2_t dg) 652 // int _aaApply2(AA aa, size_t keysize, dg2_t dg)
671 { 653 {
672 std::string fname("_aaApply2"); 654 std::string fname("_aaApply2");
673 std::vector<const LLType*> types; 655 std::vector<const LLType*> types;
674 types.push_back(aaTy); 656 types.push_back(aaTy);
675 types.push_back(sizeTy); 657 types.push_back(sizeTy);
676 types.push_back(rt_dg2()); 658 types.push_back(rt_dg2());
677 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); 659 const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false);
678 llvm::AttrListPtr palist; 660 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
679 palist = palist.addAttr(3, llvm::Attribute::ByVal);
680 llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M)->setAttributes(palist);
681 } 661 }
682 662
683 ///////////////////////////////////////////////////////////////////////////////////// 663 /////////////////////////////////////////////////////////////////////////////////////
684 ///////////////////////////////////////////////////////////////////////////////////// 664 /////////////////////////////////////////////////////////////////////////////////////
685 ///////////////////////////////////////////////////////////////////////////////////// 665 /////////////////////////////////////////////////////////////////////////////////////