comparison gen/toir.cpp @ 143:336ec4f4bbb3 trunk

[svn r147] tango.io.Console is now working. True this time :) Yay!
author lindquist
date Fri, 25 Jan 2008 01:42:36 +0100
parents ce7b81fb957f
children a27941d00351
comparison
equal deleted inserted replaced
142:a123dca8349b 143:336ec4f4bbb3
2171 DValue* DelegateExp::toElem(IRState* p) 2171 DValue* DelegateExp::toElem(IRState* p)
2172 { 2172 {
2173 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars()); 2173 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars());
2174 LOG_SCOPE; 2174 LOG_SCOPE;
2175 2175
2176 DValue* u = e1->toElem(p);
2177
2178 const llvm::PointerType* int8ptrty = getPtrToType(llvm::Type::Int8Ty); 2176 const llvm::PointerType* int8ptrty = getPtrToType(llvm::Type::Int8Ty);
2179 2177
2180 llvm::Value* lval; 2178 llvm::Value* lval;
2179 bool inplace = false;
2181 if (p->topexp() && p->topexp()->e2 == this) { 2180 if (p->topexp() && p->topexp()->e2 == this) {
2182 assert(p->topexp()->v); 2181 assert(p->topexp()->v);
2183 lval = p->topexp()->v->getLVal(); 2182 lval = p->topexp()->v->getLVal();
2183 inplace = true;
2184 } 2184 }
2185 else { 2185 else {
2186 lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); 2186 lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint());
2187 } 2187 }
2188 2188
2189 DValue* u = e1->toElem(p);
2189 llvm::Value* uval; 2190 llvm::Value* uval;
2190 if (DFuncValue* f = u->isFunc()) { 2191 if (DFuncValue* f = u->isFunc()) {
2191 //assert(f->vthis); 2192 //assert(f->vthis);
2192 //uval = f->vthis; 2193 //uval = f->vthis;
2193 llvm::Value* nestvar = p->func()->decl->irFunc->nestedVar; 2194 llvm::Value* nestvar = p->func()->decl->irFunc->nestedVar;
2195 uval = nestvar; 2196 uval = nestvar;
2196 else 2197 else
2197 uval = llvm::ConstantPointerNull::get(int8ptrty); 2198 uval = llvm::ConstantPointerNull::get(int8ptrty);
2198 } 2199 }
2199 else { 2200 else {
2200 uval = u->getRVal(); 2201 DValue* src = u;
2201 } 2202 if (ClassDeclaration* cd = u->getType()->isClassHandle())
2203 {
2204 Logger::println("context type is class handle");
2205 if (cd->isInterfaceDeclaration())
2206 {
2207 Logger::println("context type is interface");
2208 src = DtoCastInterfaceToObject(u, ClassDeclaration::object->type);
2209 }
2210 }
2211 uval = src->getRVal();
2212 }
2213
2214 Logger::cout() << "context = " << *uval << '\n';
2202 2215
2203 llvm::Value* context = DtoGEPi(lval,0,0,"tmp"); 2216 llvm::Value* context = DtoGEPi(lval,0,0,"tmp");
2204 llvm::Value* castcontext = DtoBitCast(uval, int8ptrty); 2217 llvm::Value* castcontext = DtoBitCast(uval, int8ptrty);
2205 DtoStore(castcontext, context); 2218 DtoStore(castcontext, context);
2206 2219
2219 castfptr = func->irFunc->func; 2232 castfptr = func->irFunc->func;
2220 2233
2221 castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); 2234 castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0));
2222 DtoStore(castfptr, fptr); 2235 DtoStore(castfptr, fptr);
2223 2236
2224 return new DVarValue(type, lval, true); 2237 return new DImValue(type, lval, inplace);
2225 } 2238 }
2226 2239
2227 ////////////////////////////////////////////////////////////////////////////////////////// 2240 //////////////////////////////////////////////////////////////////////////////////////////
2228 2241
2229 DValue* IdentityExp::toElem(IRState* p) 2242 DValue* IdentityExp::toElem(IRState* p)