Mercurial > projects > ldc
comparison gen/toir.c @ 18:c05ef76f1c20 trunk
[svn r22] * Forgot to add std.stdio
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 01:47:53 +0200 |
parents | 37a4fdab33fc |
children | 8d45266bbabe |
comparison
equal
deleted
inserted
replaced
17:6c6cd097bcdf | 18:c05ef76f1c20 |
---|---|
758 Logger::print("CallExp::toElem: %s\n", toChars()); | 758 Logger::print("CallExp::toElem: %s\n", toChars()); |
759 LOG_SCOPE; | 759 LOG_SCOPE; |
760 elem* e = new elem; | 760 elem* e = new elem; |
761 elem* fn = e1->toElem(p); | 761 elem* fn = e1->toElem(p); |
762 LINK dlink = LINKdefault; | 762 LINK dlink = LINKdefault; |
763 | 763 |
764 bool delegateCall = false; | 764 bool delegateCall = false; |
765 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); | 765 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); |
766 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); | 766 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); |
767 | 767 |
768 // hidden struct return parameter handling | 768 // hidden struct return parameter handling |
769 bool retinptr = false; | 769 bool retinptr = false; |
770 | 770 |
771 TypeFunction* tf = 0; | 771 TypeFunction* tf = 0; |
772 | 772 |
773 // regular functions | 773 // regular functions |
774 if (e1->type->ty == Tfunction) { | 774 if (e1->type->ty == Tfunction) { |
775 tf = (TypeFunction*)e1->type; | 775 tf = (TypeFunction*)e1->type; |
776 if (tf->llvmRetInPtr) { | 776 if (tf->llvmRetInPtr) { |
777 retinptr = true; | 777 retinptr = true; |
778 } | 778 } |
779 dlink = tf->linkage; | 779 dlink = tf->linkage; |
780 } | 780 } |
781 | 781 |
782 // delegates | 782 // delegates |
783 else if (e1->type->ty == Tdelegate) { | 783 else if (e1->type->ty == Tdelegate) { |
784 Logger::println("delegateTy = %s\n", e1->type->toChars()); | 784 Logger::println("delegateTy = %s\n", e1->type->toChars()); |
785 assert(e1->type->next->ty == Tfunction); | 785 assert(e1->type->next->ty == Tfunction); |
786 tf = (TypeFunction*)e1->type->next; | 786 tf = (TypeFunction*)e1->type->next; |
788 retinptr = true; | 788 retinptr = true; |
789 } | 789 } |
790 dlink = tf->linkage; | 790 dlink = tf->linkage; |
791 delegateCall = true; | 791 delegateCall = true; |
792 } | 792 } |
793 | 793 |
794 // invalid | 794 // invalid |
795 else { | 795 else { |
796 assert(tf); | 796 assert(tf); |
797 } | 797 } |
798 | 798 |
799 size_t n = arguments->dim; | 799 size_t n = arguments->dim; |
800 if (fn->arg || delegateCall) n++; | 800 if (fn->arg || delegateCall) n++; |
801 if (retinptr) n++; | 801 if (retinptr) n++; |
802 | 802 |
803 llvm::Value* funcval = fn->getValue(); | 803 llvm::Value* funcval = fn->getValue(); |
804 assert(funcval != 0); | |
804 std::vector<llvm::Value*> llargs(n, 0); | 805 std::vector<llvm::Value*> llargs(n, 0); |
805 | 806 |
806 const llvm::FunctionType* llfnty = 0; | 807 const llvm::FunctionType* llfnty = 0; |
807 | 808 |
808 // normal function call | 809 // normal function call |
809 if (llvm::isa<llvm::FunctionType>(funcval->getType())) { | 810 if (llvm::isa<llvm::FunctionType>(funcval->getType())) { |
810 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()); | 811 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()); |
811 } | 812 } |
812 // pointer to something | 813 // pointer to something |
814 // pointer to function pointer - I think this not really supposed to happen, but does :/ | 815 // pointer to function pointer - I think this not really supposed to happen, but does :/ |
815 // seems like sometimes we get a func* other times a func** | 816 // seems like sometimes we get a func* other times a func** |
816 if (llvm::isa<llvm::PointerType>(funcval->getType()->getContainedType(0))) { | 817 if (llvm::isa<llvm::PointerType>(funcval->getType()->getContainedType(0))) { |
817 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 818 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
818 } | 819 } |
819 | |
820 // function pointer | 820 // function pointer |
821 if (llvm::isa<llvm::FunctionType>(funcval->getType()->getContainedType(0))) { | 821 if (llvm::isa<llvm::FunctionType>(funcval->getType()->getContainedType(0))) { |
822 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; | 822 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; |
823 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); | 823 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); |
824 } | 824 } |
954 for (int i=0; i<n; ++i) | 954 for (int i=0; i<n; ++i) |
955 { | 955 { |
956 Logger::cout() << *llargs[i] << '\n'; | 956 Logger::cout() << *llargs[i] << '\n'; |
957 } | 957 } |
958 | 958 |
959 Logger::cout() << "Calling: " << *funcval->getType() << '\n'; | 959 //Logger::cout() << "Calling: " << *funcval->getType() << '\n'; |
960 | 960 |
961 // call the function | 961 // call the function |
962 llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); | 962 llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); |
963 e->val = call; | 963 e->val = call; |
964 | 964 |