Mercurial > projects > ldc
comparison gen/toir.cpp @ 155:7f92f477ff53 trunk
[svn r171] starting to move IR data from AST nodes into IRState; started with IrFunction
author | ChristianK |
---|---|
date | Tue, 29 Apr 2008 21:33:50 +0200 |
parents | d11848349f97 |
children | ccd07d9f2ce9 |
comparison
equal
deleted
inserted
replaced
154:5cb946f323d2 | 155:7f92f477ff53 |
---|---|
60 | 60 |
61 // referenced by nested delegate? | 61 // referenced by nested delegate? |
62 if (vd->nestedref) { | 62 if (vd->nestedref) { |
63 Logger::println("has nestedref set"); | 63 Logger::println("has nestedref set"); |
64 assert(vd->irLocal); | 64 assert(vd->irLocal); |
65 vd->irLocal->value = p->func()->decl->irFunc->nestedVar; | 65 vd->irLocal->value = gIR->irFunc[p->func()->decl]->nestedVar; |
66 assert(vd->irLocal->value); | 66 assert(vd->irLocal->value); |
67 assert(vd->irLocal->nestedIndex >= 0); | 67 assert(vd->irLocal->nestedIndex >= 0); |
68 } | 68 } |
69 // normal stack variable | 69 // normal stack variable |
70 else { | 70 else { |
155 Logger::println("Id::_arguments"); | 155 Logger::println("Id::_arguments"); |
156 /*if (!vd->getIrValue()) | 156 /*if (!vd->getIrValue()) |
157 vd->getIrValue() = p->func()->decl->irFunc->_arguments; | 157 vd->getIrValue() = p->func()->decl->irFunc->_arguments; |
158 assert(vd->getIrValue()); | 158 assert(vd->getIrValue()); |
159 return new DVarValue(vd, vd->getIrValue(), true);*/ | 159 return new DVarValue(vd, vd->getIrValue(), true);*/ |
160 llvm::Value* v = p->func()->decl->irFunc->_arguments; | 160 llvm::Value* v = gIR->irFunc[p->func()->decl]->_arguments; |
161 assert(v); | 161 assert(v); |
162 return new DVarValue(vd, v, true); | 162 return new DVarValue(vd, v, true); |
163 } | 163 } |
164 // _argptr | 164 // _argptr |
165 else if (vd->ident == Id::_argptr) | 165 else if (vd->ident == Id::_argptr) |
167 Logger::println("Id::_argptr"); | 167 Logger::println("Id::_argptr"); |
168 /*if (!vd->getIrValue()) | 168 /*if (!vd->getIrValue()) |
169 vd->getIrValue() = p->func()->decl->irFunc->_argptr; | 169 vd->getIrValue() = p->func()->decl->irFunc->_argptr; |
170 assert(vd->getIrValue()); | 170 assert(vd->getIrValue()); |
171 return new DVarValue(vd, vd->getIrValue(), true);*/ | 171 return new DVarValue(vd, vd->getIrValue(), true);*/ |
172 llvm::Value* v = p->func()->decl->irFunc->_argptr; | 172 llvm::Value* v = gIR->irFunc[p->func()->decl]->_argptr; |
173 assert(v); | 173 assert(v); |
174 return new DVarValue(vd, v, true); | 174 return new DVarValue(vd, v, true); |
175 } | 175 } |
176 // _dollar | 176 // _dollar |
177 else if (vd->ident == Id::dollar) | 177 else if (vd->ident == Id::dollar) |
241 { | 241 { |
242 Logger::println("FuncDeclaration"); | 242 Logger::println("FuncDeclaration"); |
243 if (fdecl->llvmInternal != LLVMva_arg) {// && fdecl->llvmValue == 0) | 243 if (fdecl->llvmInternal != LLVMva_arg) {// && fdecl->llvmValue == 0) |
244 DtoForceDeclareDsymbol(fdecl); | 244 DtoForceDeclareDsymbol(fdecl); |
245 } | 245 } |
246 return new DFuncValue(fdecl, fdecl->irFunc->func); | 246 return new DFuncValue(fdecl, gIR->irFunc[fdecl]->func); |
247 } | 247 } |
248 else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) | 248 else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) |
249 { | 249 { |
250 // this seems to be the static initialiser for structs | 250 // this seems to be the static initialiser for structs |
251 Type* sdecltype = DtoDType(sdecl->type); | 251 Type* sdecltype = DtoDType(sdecl->type); |
1315 Logger::println("is func"); | 1315 Logger::println("is func"); |
1316 //Logger::println("FuncDeclaration"); | 1316 //Logger::println("FuncDeclaration"); |
1317 FuncDeclaration* fd = fv->func; | 1317 FuncDeclaration* fd = fv->func; |
1318 assert(fd); | 1318 assert(fd); |
1319 DtoForceDeclareDsymbol(fd); | 1319 DtoForceDeclareDsymbol(fd); |
1320 return new DFuncValue(fd, fd->irFunc->func); | 1320 return new DFuncValue(fd, gIR->irFunc[fd]->func); |
1321 } | 1321 } |
1322 else if (DImValue* im = v->isIm()) { | 1322 else if (DImValue* im = v->isIm()) { |
1323 Logger::println("is immediate"); | 1323 Logger::println("is immediate"); |
1324 return v; | 1324 return v; |
1325 } | 1325 } |
1420 //unsigned cc = (unsigned)-1; | 1420 //unsigned cc = (unsigned)-1; |
1421 | 1421 |
1422 // super call | 1422 // super call |
1423 if (e1->op == TOKsuper) { | 1423 if (e1->op == TOKsuper) { |
1424 DtoForceDeclareDsymbol(fdecl); | 1424 DtoForceDeclareDsymbol(fdecl); |
1425 funcval = fdecl->irFunc->func; | 1425 funcval = gIR->irFunc[fdecl]->func; |
1426 assert(funcval); | 1426 assert(funcval); |
1427 } | 1427 } |
1428 // normal virtual call | 1428 // normal virtual call |
1429 else if (fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual())) { | 1429 else if (fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual())) { |
1430 assert(fdecl->vtblIndex > 0); | 1430 assert(fdecl->vtblIndex > 0); |
1441 //cc = DtoCallingConv(fdecl->linkage); | 1441 //cc = DtoCallingConv(fdecl->linkage); |
1442 } | 1442 } |
1443 // static call | 1443 // static call |
1444 else { | 1444 else { |
1445 DtoForceDeclareDsymbol(fdecl); | 1445 DtoForceDeclareDsymbol(fdecl); |
1446 funcval = fdecl->irFunc->func; | 1446 funcval = gIR->irFunc[fdecl]->func; |
1447 assert(funcval); | 1447 assert(funcval); |
1448 //assert(funcval->getType() == DtoType(fdecl->type)); | 1448 //assert(funcval->getType() == DtoType(fdecl->type)); |
1449 } | 1449 } |
1450 return new DFuncValue(fdecl, funcval, vthis2); | 1450 return new DFuncValue(fdecl, funcval, vthis2); |
1451 } | 1451 } |
1464 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1464 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1465 LOG_SCOPE; | 1465 LOG_SCOPE; |
1466 | 1466 |
1467 if (VarDeclaration* vd = var->isVarDeclaration()) { | 1467 if (VarDeclaration* vd = var->isVarDeclaration()) { |
1468 llvm::Value* v; | 1468 llvm::Value* v; |
1469 v = p->func()->decl->irFunc->thisVar; | 1469 v = gIR->irFunc[p->func()->decl]->thisVar; |
1470 if (llvm::isa<llvm::AllocaInst>(v)) | 1470 if (llvm::isa<llvm::AllocaInst>(v)) |
1471 v = new llvm::LoadInst(v, "tmp", p->scopebb()); | 1471 v = new llvm::LoadInst(v, "tmp", p->scopebb()); |
1472 return new DThisValue(vd, v); | 1472 return new DThisValue(vd, v); |
1473 } | 1473 } |
1474 | 1474 |
2214 DValue* u = e1->toElem(p); | 2214 DValue* u = e1->toElem(p); |
2215 llvm::Value* uval; | 2215 llvm::Value* uval; |
2216 if (DFuncValue* f = u->isFunc()) { | 2216 if (DFuncValue* f = u->isFunc()) { |
2217 //assert(f->vthis); | 2217 //assert(f->vthis); |
2218 //uval = f->vthis; | 2218 //uval = f->vthis; |
2219 llvm::Value* nestvar = p->func()->decl->irFunc->nestedVar; | 2219 llvm::Value* nestvar = gIR->irFunc[p->func()->decl]->nestedVar; |
2220 if (nestvar) | 2220 if (nestvar) |
2221 uval = nestvar; | 2221 uval = nestvar; |
2222 else | 2222 else |
2223 uval = llvm::ConstantPointerNull::get(int8ptrty); | 2223 uval = llvm::ConstantPointerNull::get(int8ptrty); |
2224 } | 2224 } |
2254 else if (func->toParent()->isInterfaceDeclaration()) | 2254 else if (func->toParent()->isInterfaceDeclaration()) |
2255 assert(0 && "TODO delegate to interface method"); | 2255 assert(0 && "TODO delegate to interface method"); |
2256 else | 2256 else |
2257 { | 2257 { |
2258 DtoForceDeclareDsymbol(func); | 2258 DtoForceDeclareDsymbol(func); |
2259 castfptr = func->irFunc->func; | 2259 castfptr = gIR->irFunc[func]->func; |
2260 } | 2260 } |
2261 | 2261 |
2262 castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); | 2262 castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); |
2263 DtoStore(castfptr, fptr); | 2263 DtoStore(castfptr, fptr); |
2264 | 2264 |
2488 temp = true; | 2488 temp = true; |
2489 } | 2489 } |
2490 | 2490 |
2491 llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); | 2491 llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); |
2492 const llvm::PointerType* pty = isaPointer(context->getType()->getContainedType(0)); | 2492 const llvm::PointerType* pty = isaPointer(context->getType()->getContainedType(0)); |
2493 llvm::Value* llvmNested = p->func()->decl->irFunc->nestedVar; | 2493 llvm::Value* llvmNested = gIR->irFunc[p->func()->decl]->nestedVar; |
2494 if (llvmNested == NULL) { | 2494 if (llvmNested == NULL) { |
2495 llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); | 2495 llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); |
2496 p->ir->CreateStore(nullcontext, context); | 2496 p->ir->CreateStore(nullcontext, context); |
2497 } | 2497 } |
2498 else { | 2498 else { |
2500 p->ir->CreateStore(nestedcontext, context); | 2500 p->ir->CreateStore(nestedcontext, context); |
2501 } | 2501 } |
2502 | 2502 |
2503 llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); | 2503 llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); |
2504 | 2504 |
2505 assert(fd->irFunc->func); | 2505 assert(gIR->irFunc[fd]->func); |
2506 llvm::Value* castfptr = new llvm::BitCastInst(fd->irFunc->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | 2506 llvm::Value* castfptr = new llvm::BitCastInst(gIR->irFunc[fd]->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); |
2507 new llvm::StoreInst(castfptr, fptr, p->scopebb()); | 2507 new llvm::StoreInst(castfptr, fptr, p->scopebb()); |
2508 | 2508 |
2509 if (temp) | 2509 if (temp) |
2510 return new DVarValue(type, lval, true); | 2510 return new DVarValue(type, lval, true); |
2511 else | 2511 else |