Mercurial > projects > ldc
comparison gen/toir.c @ 23:77e3d1ddae3f trunk
[svn r27] * Fixed bug in aggregate field lookup.
* Fixed structs with no fields.
* Added support for NegExp as in -x.
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 09:24:15 +0200 |
parents | 8d45266bbabe |
children | 25bb577878e8 |
comparison
equal
deleted
inserted
replaced
22:a6360e68134a | 23:77e3d1ddae3f |
---|---|
446 | 446 |
447 ////////////////////////////////////////////////////////////////////////////////////////// | 447 ////////////////////////////////////////////////////////////////////////////////////////// |
448 | 448 |
449 elem* AddExp::toElem(IRState* p) | 449 elem* AddExp::toElem(IRState* p) |
450 { | 450 { |
451 Logger::print("AddExp::toElem: %s\n", toChars()); | 451 Logger::print("AddExp::toElem: %s | %s\n", toChars(), type->toChars()); |
452 LOG_SCOPE; | 452 LOG_SCOPE; |
453 elem* e = new elem; | 453 elem* e = new elem; |
454 elem* l = e1->toElem(p); | 454 elem* l = e1->toElem(p); |
455 elem* r = e2->toElem(p); | 455 elem* r = e2->toElem(p); |
456 | 456 |
457 if (e1->type != e2->type) { | 457 if (e1->type != e2->type) { |
458 if (e1->type->ty == Tpointer && e1->type->next->ty == Tstruct) { | 458 if (e1->type->ty == Tpointer && e1->type->next->ty == Tstruct) { |
459 //assert(l->field); | 459 //assert(l->field); |
460 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
461 assert(r->type == elem::CONST); | 460 assert(r->type == elem::CONST); |
462 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); | 461 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); |
463 | 462 |
464 TypeStruct* ts = (TypeStruct*)e1->type->next; | 463 TypeStruct* ts = (TypeStruct*)e1->type->next; |
465 std::vector<unsigned> offsets(1,0); | 464 std::vector<unsigned> offsets(1,0); |
1148 LOG_SCOPE; | 1147 LOG_SCOPE; |
1149 elem* e = 0; | 1148 elem* e = 0; |
1150 if (VarDeclaration* vd = var->isVarDeclaration()) | 1149 if (VarDeclaration* vd = var->isVarDeclaration()) |
1151 { | 1150 { |
1152 Logger::println("VarDeclaration"); | 1151 Logger::println("VarDeclaration"); |
1152 assert(vd->llvmValue); | |
1153 if (vd->type->ty == Tstruct && !(type->ty == Tpointer && type->next == vd->type)) { | 1153 if (vd->type->ty == Tstruct && !(type->ty == Tpointer && type->next == vd->type)) { |
1154 TypeStruct* vdt = (TypeStruct*)vd->type; | 1154 TypeStruct* vdt = (TypeStruct*)vd->type; |
1155 e = new elem; | 1155 e = new elem; |
1156 std::vector<unsigned> dst(1,0); | 1156 std::vector<unsigned> dst(1,0); |
1157 vdt->sym->offsetToIndex(offset, dst); | 1157 vdt->sym->offsetToIndex(offset, dst); |
2236 llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true); | 2236 llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true); |
2237 e->val = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); | 2237 e->val = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); |
2238 | 2238 |
2239 delete u; | 2239 delete u; |
2240 | 2240 |
2241 e->type = elem::VAL; | |
2242 | |
2243 return e; | |
2244 } | |
2245 | |
2246 ////////////////////////////////////////////////////////////////////////////////////////// | |
2247 | |
2248 elem* NegExp::toElem(IRState* p) | |
2249 { | |
2250 Logger::print("NegExp::toElem: %s | %s\n", toChars(), type->toChars()); | |
2251 LOG_SCOPE; | |
2252 elem* e = new elem; | |
2253 elem* l = e1->toElem(p); | |
2254 llvm::Value* val = l->getValue(); | |
2255 delete l; | |
2256 | |
2257 llvm::Value* zero = 0; | |
2258 if (type->isintegral()) | |
2259 zero = llvm::ConstantInt::get(val->getType(), 0, true); | |
2260 else if (type->isfloating()) { | |
2261 if (type->ty == Tfloat32) | |
2262 zero = llvm::ConstantFP::get(val->getType(), float(0)); | |
2263 else if (type->ty == Tfloat64 || type->ty == Tfloat80) | |
2264 zero = llvm::ConstantFP::get(val->getType(), double(0)); | |
2265 else | |
2266 assert(0); | |
2267 } | |
2268 else | |
2269 assert(0); | |
2270 | |
2271 e->val = llvm::BinaryOperator::createSub(zero,val,"tmp",p->scopebb()); | |
2241 e->type = elem::VAL; | 2272 e->type = elem::VAL; |
2242 | 2273 |
2243 return e; | 2274 return e; |
2244 } | 2275 } |
2245 | 2276 |
2302 //STUB(IntegerExp); | 2333 //STUB(IntegerExp); |
2303 STUB(BoolExp); | 2334 STUB(BoolExp); |
2304 | 2335 |
2305 //STUB(NotExp); | 2336 //STUB(NotExp); |
2306 //STUB(ComExp); | 2337 //STUB(ComExp); |
2307 STUB(NegExp); | 2338 //STUB(NegExp); |
2308 //STUB(PtrExp); | 2339 //STUB(PtrExp); |
2309 //STUB(AddrExp); | 2340 //STUB(AddrExp); |
2310 //STUB(SliceExp); | 2341 //STUB(SliceExp); |
2311 //STUB(CastExp); | 2342 //STUB(CastExp); |
2312 //STUB(DeleteExp); | 2343 //STUB(DeleteExp); |