comparison gen/statements.cpp @ 271:1e6e2b5d5bfe trunk

[svn r292] Fixed: string switch was broken in several ways. Fixed: TypeInfo_Typedef.next was incorrect (return base of base instead of just base). Fixed: ClassInfo offset type info (offTi) had invalid offsets.
author lindquist
date Wed, 18 Jun 2008 21:31:05 +0200
parents d9d5d59873d8
children 3b8ada4c9f8b
comparison
equal deleted inserted replaced
270:d9d5d59873d8 271:1e6e2b5d5bfe
679 { 679 {
680 llval = val->getRVal(); 680 llval = val->getRVal();
681 } 681 }
682 assert(llval->getType() == fn->getFunctionType()->getParamType(1)); 682 assert(llval->getType() == fn->getFunctionType()->getParamType(1));
683 683
684 return gIR->ir->CreateCall2(fn, table, llval, "tmp"); 684 llvm::CallInst* call = gIR->ir->CreateCall2(fn, table, llval, "tmp");
685
686 llvm::PAListPtr palist;
687 palist = palist.addAttr(1, llvm::ParamAttr::ByVal);
688 palist = palist.addAttr(2, llvm::ParamAttr::ByVal);
689 call->setParamAttrs(palist);
690
691 return call;
685 } 692 }
686 693
687 void SwitchStatement::toIR(IRState* p) 694 void SwitchStatement::toIR(IRState* p)
688 { 695 {
689 Logger::println("SwitchStatement::toIR(): %s", loc.toChars()); 696 Logger::println("SwitchStatement::toIR(): %s", loc.toChars());
707 Array caseArray; 714 Array caseArray;
708 if (!condition->type->isintegral()) 715 if (!condition->type->isintegral())
709 { 716 {
710 Logger::println("is string switch"); 717 Logger::println("is string switch");
711 // build array of the stringexpS 718 // build array of the stringexpS
719 caseArray.reserve(cases->dim);
712 for (int i=0; i<cases->dim; ++i) 720 for (int i=0; i<cases->dim; ++i)
713 { 721 {
714 CaseStatement* cs = (CaseStatement*)cases->data[i]; 722 CaseStatement* cs = (CaseStatement*)cases->data[i];
715 723
716 assert(cs->exp->op == TOKstring); 724 assert(cs->exp->op == TOKstring);
717 caseArray.push(new Case((StringExp*)cs->exp, i)); 725 caseArray.push(new Case((StringExp*)cs->exp, i));
718 } 726 }
719 // first sort it 727 // first sort it
720 caseArray.sort(); 728 caseArray.sort();
721 // iterate and add indices to cases 729 // iterate and add indices to cases
722 std::vector<LLConstant*> inits; 730 std::vector<LLConstant*> inits(caseArray.dim);
723 for (size_t i=0; i<caseArray.dim; ++i) 731 for (size_t i=0; i<caseArray.dim; ++i)
724 { 732 {
725 CaseStatement* cs = (CaseStatement*)cases->data[i]; 733 Case* c = (Case*)caseArray.data[i];
734 CaseStatement* cs = (CaseStatement*)cases->data[c->index];
726 cs->llvmIdx = DtoConstUint(i); 735 cs->llvmIdx = DtoConstUint(i);
727 Case* c = (Case*)caseArray.data[i]; 736 inits[i] = c->str->toConstElem(p);
728 inits.push_back(c->str->toConstElem(p));
729 } 737 }
730 // build static array for ptr or final array 738 // build static array for ptr or final array
731 const LLType* elemTy = DtoType(condition->type); 739 const LLType* elemTy = DtoType(condition->type);
732 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size()); 740 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size());
733 LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits); 741 LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits);
809 { 817 {
810 llvm::BranchInst::Create(nbb, bodyBB); 818 llvm::BranchInst::Create(nbb, bodyBB);
811 } 819 }
812 bodyBB = nbb; 820 bodyBB = nbb;
813 821
814 if (exp->type->isintegral()) { 822 if (llvmIdx == NULL) {
815 LLConstant* c = exp->toConstElem(p); 823 LLConstant* c = exp->toConstElem(p);
816 llvmIdx = isaConstantInt(c); 824 llvmIdx = isaConstantInt(c);
817 }
818 else {
819 assert(llvmIdx);
820 } 825 }
821 826
822 if (!p->scopereturned()) 827 if (!p->scopereturned())
823 llvm::BranchInst::Create(bodyBB, p->scopebb()); 828 llvm::BranchInst::Create(bodyBB, p->scopebb());
824 829