Mercurial > projects > ldc
diff gen/toir.cpp @ 156:ccd07d9f2ce9 trunk
[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
author | ChristianK |
---|---|
date | Thu, 01 May 2008 13:05:53 +0200 |
parents | 7f92f477ff53 |
children | 1856c62af24b |
line wrap: on
line diff
--- a/gen/toir.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/toir.cpp Thu May 01 13:05:53 2008 +0200 @@ -61,10 +61,10 @@ // referenced by nested delegate? if (vd->nestedref) { Logger::println("has nestedref set"); - assert(vd->irLocal); - vd->irLocal->value = gIR->irFunc[p->func()->decl]->nestedVar; - assert(vd->irLocal->value); - assert(vd->irLocal->nestedIndex >= 0); + assert(gIR->irDsymbol[vd].irLocal); + gIR->irDsymbol[vd].irLocal->value = gIR->irDsymbol[p->func()->decl].irFunc->nestedVar; + assert(gIR->irDsymbol[vd].irLocal->value); + assert(gIR->irDsymbol[vd].irLocal->nestedIndex >= 0); } // normal stack variable else { @@ -72,16 +72,16 @@ const llvm::Type* lltype = DtoType(vd->type); llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); //allocainst->setAlignment(vd->type->alignsize()); // TODO - assert(!vd->irLocal); - vd->irLocal = new IrLocal(vd); - vd->irLocal->value = allocainst; + assert(!gIR->irDsymbol[vd].irLocal); + gIR->irDsymbol[vd].irLocal = new IrLocal(vd); + gIR->irDsymbol[vd].irLocal->value = allocainst; } - Logger::cout() << "llvm value for decl: " << *vd->irLocal->value << '\n'; + Logger::cout() << "llvm value for decl: " << *gIR->irDsymbol[vd].irLocal->value << '\n'; DValue* ie = DtoInitializer(vd->init); } - return new DVarValue(vd, vd->getIrValue(), true); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true); } // struct declaration else if (StructDeclaration* s = declaration->isStructDeclaration()) @@ -153,11 +153,11 @@ if (vd->ident == Id::_arguments) { Logger::println("Id::_arguments"); - /*if (!vd->getIrValue()) - vd->getIrValue() = p->func()->decl->irFunc->_arguments; - assert(vd->getIrValue()); - return new DVarValue(vd, vd->getIrValue(), true);*/ - llvm::Value* v = gIR->irFunc[p->func()->decl]->_arguments; + /*if (!gIR->irDsymbol[vd].getIrValue()) + gIR->irDsymbol[vd].getIrValue() = p->func()->decl->irFunc->_arguments; + assert(gIR->irDsymbol[vd].getIrValue()); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true);*/ + llvm::Value* v = gIR->irDsymbol[p->func()->decl].irFunc->_arguments; assert(v); return new DVarValue(vd, v, true); } @@ -165,11 +165,11 @@ else if (vd->ident == Id::_argptr) { Logger::println("Id::_argptr"); - /*if (!vd->getIrValue()) - vd->getIrValue() = p->func()->decl->irFunc->_argptr; - assert(vd->getIrValue()); - return new DVarValue(vd, vd->getIrValue(), true);*/ - llvm::Value* v = gIR->irFunc[p->func()->decl]->_argptr; + /*if (!gIR->irDsymbol[vd].getIrValue()) + gIR->irDsymbol[vd].getIrValue() = p->func()->decl->irFunc->_argptr; + assert(gIR->irDsymbol[vd].getIrValue()); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true);*/ + llvm::Value* v = gIR->irDsymbol[p->func()->decl].irFunc->_argptr; assert(v); return new DVarValue(vd, v, true); } @@ -186,13 +186,13 @@ { Logger::println("TypeInfoDeclaration"); DtoForceDeclareDsymbol(tid); - assert(tid->getIrValue()); + assert(gIR->irDsymbol[tid].getIrValue()); const llvm::Type* vartype = DtoType(type); llvm::Value* m; - if (tid->getIrValue()->getType() != getPtrToType(vartype)) - m = p->ir->CreateBitCast(tid->getIrValue(), vartype, "tmp"); + if (gIR->irDsymbol[tid].getIrValue()->getType() != getPtrToType(vartype)) + m = p->ir->CreateBitCast(gIR->irDsymbol[tid].getIrValue(), vartype, "tmp"); else - m = tid->getIrValue(); + m = gIR->irDsymbol[tid].getIrValue(); return new DVarValue(vd, m, true); } // classinfo @@ -200,8 +200,8 @@ { Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); DtoDeclareClassInfo(cid->cd); - assert(cid->cd->irStruct->classInfo); - return new DVarValue(vd, cid->cd->irStruct->classInfo, true); + assert(gIR->irDsymbol[cid->cd].irStruct->classInfo); + return new DVarValue(vd, gIR->irDsymbol[cid->cd].irStruct->classInfo, true); } // nested variable else if (vd->nestedref) { @@ -211,16 +211,16 @@ // function parameter else if (vd->isParameter()) { Logger::println("function param"); - if (!vd->getIrValue()) { + if (!gIR->irDsymbol[vd].getIrValue()) { // TODO: determine this properly // this happens when the DMD frontend generates by pointer wrappers for struct opEquals(S) and opCmp(S) - vd->getIrValue() = &p->func()->func->getArgumentList().back(); + gIR->irDsymbol[vd].getIrValue() = &p->func()->func->getArgumentList().back(); } - if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->getIrValue())) { - return new DVarValue(vd, vd->getIrValue(), true); + if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(gIR->irDsymbol[vd].getIrValue())) { + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true); } - else if (llvm::isa<llvm::Argument>(vd->getIrValue())) { - return new DImValue(type, vd->getIrValue()); + else if (llvm::isa<llvm::Argument>(gIR->irDsymbol[vd].getIrValue())) { + return new DImValue(type, gIR->irDsymbol[vd].getIrValue()); } else assert(0); } @@ -230,11 +230,11 @@ vd->toObjFile(); DtoConstInitGlobal(vd); } - if (!vd->getIrValue() || vd->getIrValue()->getType()->isAbstract()) { + if (!gIR->irDsymbol[vd].getIrValue() || gIR->irDsymbol[vd].getIrValue()->getType()->isAbstract()) { Logger::println("global variable not resolved :/ %s", vd->toChars()); assert(0); } - return new DVarValue(vd, vd->getIrValue(), true); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true); } } else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) @@ -243,7 +243,7 @@ if (fdecl->llvmInternal != LLVMva_arg) {// && fdecl->llvmValue == 0) DtoForceDeclareDsymbol(fdecl); } - return new DFuncValue(fdecl, gIR->irFunc[fdecl]->func); + return new DFuncValue(fdecl, gIR->irDsymbol[fdecl].irFunc->func); } else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) { @@ -253,8 +253,8 @@ assert(sdecltype->ty == Tstruct); TypeStruct* ts = (TypeStruct*)sdecltype; assert(ts->sym); - assert(ts->sym->irStruct->init); - return new DVarValue(type, ts->sym->irStruct->init, true); + assert(gIR->irDsymbol[ts->sym].irStruct->init); + return new DVarValue(type, gIR->irDsymbol[ts->sym].irStruct->init, true); } else { @@ -278,17 +278,17 @@ assert(sdecltype->ty == Tstruct); TypeStruct* ts = (TypeStruct*)sdecltype; DtoForceConstInitDsymbol(ts->sym); - assert(ts->sym->irStruct->constInit); - return ts->sym->irStruct->constInit; + assert(gIR->irDsymbol[ts->sym].irStruct->constInit); + return gIR->irDsymbol[ts->sym].irStruct->constInit; } else if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) { DtoForceDeclareDsymbol(ti); - assert(ti->getIrValue()); + assert(gIR->irDsymbol[ti].getIrValue()); const llvm::Type* vartype = DtoType(type); - llvm::Constant* m = isaConstant(ti->getIrValue()); + llvm::Constant* m = isaConstant(gIR->irDsymbol[ti].getIrValue()); assert(m); - if (ti->getIrValue()->getType() != getPtrToType(vartype)) + if (gIR->irDsymbol[ti].getIrValue()->getType() != getPtrToType(vartype)) m = llvm::ConstantExpr::getBitCast(m, vartype); return m; } @@ -1079,7 +1079,7 @@ } // build type info array - assert(Type::typeinfo->irStruct->constInit); + assert(gIR->irDsymbol[Type::typeinfo].irStruct->constInit); const llvm::Type* typeinfotype = DtoType(Type::typeinfo->type); const llvm::ArrayType* typeinfoarraytype = llvm::ArrayType::get(typeinfotype,vtype->getNumElements()); @@ -1090,8 +1090,8 @@ Expression* argexp = (Expression*)arguments->data[i]; TypeInfoDeclaration* tidecl = argexp->type->getTypeInfoDeclaration(); DtoForceDeclareDsymbol(tidecl); - assert(tidecl->getIrValue()); - vtypeinfos.push_back(tidecl->getIrValue()); + assert(gIR->irDsymbol[tidecl].getIrValue()); + vtypeinfos.push_back(gIR->irDsymbol[tidecl].getIrValue()); llvm::Value* v = p->ir->CreateBitCast(vtypeinfos[k], typeinfotype, "tmp"); p->ir->CreateStore(v, DtoGEPi(typeinfomem,0,k,"tmp")); } @@ -1233,16 +1233,16 @@ Logger::println("VarDeclaration"); // handle forward reference - if (!vd->llvmDeclared && vd->isDataseg()) { + if (!gIR->irDsymbol[vd].declared && vd->isDataseg()) { vd->toObjFile(); // TODO } - assert(vd->getIrValue()); + assert(gIR->irDsymbol[vd].getIrValue()); Type* t = DtoDType(type); Type* tnext = DtoDType(t->next); Type* vdtype = DtoDType(vd->type); - llvm::Value* llvalue = vd->nestedref ? DtoNestedVariable(vd) : vd->getIrValue(); + llvm::Value* llvalue = vd->nestedref ? DtoNestedVariable(vd) : gIR->irDsymbol[vd].getIrValue(); llvm::Value* varmem = 0; if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) { @@ -1317,7 +1317,7 @@ FuncDeclaration* fd = fv->func; assert(fd); DtoForceDeclareDsymbol(fd); - return new DFuncValue(fd, gIR->irFunc[fd]->func); + return new DFuncValue(fd, gIR->irDsymbol[fd].irFunc->func); } else if (DImValue* im = v->isIm()) { Logger::println("is immediate"); @@ -1422,7 +1422,7 @@ // super call if (e1->op == TOKsuper) { DtoForceDeclareDsymbol(fdecl); - funcval = gIR->irFunc[fdecl]->func; + funcval = gIR->irDsymbol[fdecl].irFunc->func; assert(funcval); } // normal virtual call @@ -1443,7 +1443,7 @@ // static call else { DtoForceDeclareDsymbol(fdecl); - funcval = gIR->irFunc[fdecl]->func; + funcval = gIR->irDsymbol[fdecl].irFunc->func; assert(funcval); //assert(funcval->getType() == DtoType(fdecl->type)); } @@ -1466,7 +1466,7 @@ if (VarDeclaration* vd = var->isVarDeclaration()) { llvm::Value* v; - v = gIR->irFunc[p->func()->decl]->thisVar; + v = gIR->irDsymbol[p->func()->decl].irFunc->thisVar; if (llvm::isa<llvm::AllocaInst>(v)) v = new llvm::LoadInst(v, "tmp", p->scopebb()); return new DThisValue(vd, v); @@ -1932,7 +1932,7 @@ } else { assert(ts->sym); - DtoStructCopy(emem,ts->sym->irStruct->init); + DtoStructCopy(emem,gIR->irDsymbol[ts->sym].irStruct->init); } } @@ -2216,7 +2216,7 @@ if (DFuncValue* f = u->isFunc()) { //assert(f->vthis); //uval = f->vthis; - llvm::Value* nestvar = gIR->irFunc[p->func()->decl]->nestedVar; + llvm::Value* nestvar = gIR->irDsymbol[p->func()->decl].irFunc->nestedVar; if (nestvar) uval = nestvar; else @@ -2256,7 +2256,7 @@ else { DtoForceDeclareDsymbol(func); - castfptr = gIR->irFunc[func]->func; + castfptr = gIR->irDsymbol[func].irFunc->func; } castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); @@ -2490,7 +2490,7 @@ llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); const llvm::PointerType* pty = isaPointer(context->getType()->getContainedType(0)); - llvm::Value* llvmNested = gIR->irFunc[p->func()->decl]->nestedVar; + llvm::Value* llvmNested = gIR->irDsymbol[p->func()->decl].irFunc->nestedVar; if (llvmNested == NULL) { llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); p->ir->CreateStore(nullcontext, context); @@ -2502,8 +2502,8 @@ llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); - assert(gIR->irFunc[fd]->func); - llvm::Value* castfptr = new llvm::BitCastInst(gIR->irFunc[fd]->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); + assert(gIR->irDsymbol[fd].irFunc->func); + llvm::Value* castfptr = new llvm::BitCastInst(gIR->irDsymbol[fd].irFunc->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); new llvm::StoreInst(castfptr, fptr, p->scopebb()); if (temp) @@ -2632,7 +2632,7 @@ unsigned n = elements->dim; // unions might have different types for each literal - if (sd->irStruct->hasUnions) { + if (gIR->irDsymbol[sd].irStruct->hasUnions) { // build the type of the literal std::vector<const llvm::Type*> tys; for (unsigned i=0; i<n; ++i) {