comparison gen/arrays.cpp @ 100:5071469303d4 trunk

[svn r104] TONS OF FIXES. Split up declaration, constant initializer gen and definition for globals, structs, classes and functions. Improved ClassInfo support (not complete), not in vtable yet. Fixed a bunch of forward reference problems. Much more. Major commit! :)
author lindquist
date Fri, 16 Nov 2007 08:21:47 +0100
parents a676a7743642
children 027b8d8b71ec
comparison
equal deleted inserted replaced
99:a676a7743642 100:5071469303d4
40 ////////////////////////////////////////////////////////////////////////////////////////// 40 //////////////////////////////////////////////////////////////////////////////////////////
41 41
42 const llvm::ArrayType* DtoStaticArrayType(Type* t) 42 const llvm::ArrayType* DtoStaticArrayType(Type* t)
43 { 43 {
44 if (t->llvmType) 44 if (t->llvmType)
45 return isaArray(t->llvmType); 45 return isaArray(t->llvmType->get());
46 46
47 assert(t->ty == Tsarray); 47 assert(t->ty == Tsarray);
48 assert(t->next); 48 assert(t->next);
49 49
50 const llvm::Type* at = DtoType(t->next); 50 const llvm::Type* at = DtoType(t->next);
51 51
52 TypeSArray* tsa = (TypeSArray*)t; 52 TypeSArray* tsa = (TypeSArray*)t;
53 assert(tsa->dim->type->isintegral()); 53 assert(tsa->dim->type->isintegral());
54 const llvm::ArrayType* arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger()); 54 const llvm::ArrayType* arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger());
55 55
56 tsa->llvmType = arrty; 56 assert(!tsa->llvmType);
57 tsa->llvmType = new llvm::PATypeHolder(arrty);
57 return arrty; 58 return arrty;
58 } 59 }
59 60
60 ////////////////////////////////////////////////////////////////////////////////////////// 61 //////////////////////////////////////////////////////////////////////////////////////////
61 62
545 DtoMemCpy(mem,src2,len2); 546 DtoMemCpy(mem,src2,len2);
546 } 547 }
547 548
548 ////////////////////////////////////////////////////////////////////////////////////////// 549 //////////////////////////////////////////////////////////////////////////////////////////
549 // helper for eq and cmp 550 // helper for eq and cmp
550 static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r) 551 static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti)
551 { 552 {
552 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func); 553 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func);
553 assert(fn); 554 assert(fn);
554 555
555 llvm::Value* lmem; 556 llvm::Value* lmem;
586 587
587 std::vector<llvm::Value*> args; 588 std::vector<llvm::Value*> args;
588 args.push_back(DtoBitCast(lmem,pt)); 589 args.push_back(DtoBitCast(lmem,pt));
589 args.push_back(DtoBitCast(rmem,pt)); 590 args.push_back(DtoBitCast(rmem,pt));
590 591
591 TypeInfoDeclaration* ti = DtoDType(l->getType())->next->getTypeInfoDeclaration(); 592 // pass element typeinfo ?
592 if (!ti->llvmValue) { 593 if (useti) {
593 ti->toObjFile(); 594 TypeInfoDeclaration* ti = DtoDType(l->getType())->next->getTypeInfoDeclaration();
594 } 595 if (!ti->llvmValue) {
595 Logger::cout() << "typeinfo decl: " << *ti->llvmValue << '\n'; 596 ti->toObjFile();
596 597 }
597 pt = fn->getFunctionType()->getParamType(2); 598 Logger::cout() << "typeinfo decl: " << *ti->llvmValue << '\n';
598 args.push_back(DtoBitCast(ti->llvmValue, pt)); 599
600 pt = fn->getFunctionType()->getParamType(2);
601 args.push_back(DtoBitCast(ti->llvmValue, pt));
602 }
599 603
600 return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp"); 604 return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp");
601 } 605 }
602 606
603 ////////////////////////////////////////////////////////////////////////////////////////// 607 //////////////////////////////////////////////////////////////////////////////////////////
604 llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r) 608 llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r)
605 { 609 {
606 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_adEq"); 610 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_adEq");
607 assert(fn); 611 assert(fn);
608 612
609 llvm::Value* res = DtoArrayEqCmp_impl("_adEq", l, r); 613 llvm::Value* res = DtoArrayEqCmp_impl("_adEq", l, r, true);
610 if (op == TOKnotequal) 614 if (op == TOKnotequal)
611 res = gIR->ir->CreateNot(res, "tmp"); 615 res = gIR->ir->CreateNot(res, "tmp");
612 616
613 return res; 617 return res;
614 } 618 }
658 assert(0); 662 assert(0);
659 } 663 }
660 664
661 if (!skip) 665 if (!skip)
662 { 666 {
663 res = DtoArrayEqCmp_impl("_adCmp", l, r); 667 Type* t = DtoDType(DtoDType(l->getType())->next);
668 if (t->ty == Tchar)
669 res = DtoArrayEqCmp_impl("_adCmpChar", l, r, false);
670 else
671 res = DtoArrayEqCmp_impl("_adCmp", l, r, true);
664 res = new llvm::ICmpInst(cmpop, res, DtoConstInt(0), "tmp", gIR->scopebb()); 672 res = new llvm::ICmpInst(cmpop, res, DtoConstInt(0), "tmp", gIR->scopebb());
665 } 673 }
666 674
667 assert(res); 675 assert(res);
668 return res; 676 return res;