Mercurial > projects > ldc
comparison gen/toir.cpp @ 328:7086a84ab3d6 trunk
[svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
Fixed issues with DMD generated assert statements when using class invariants, generally due to incomplete ASTs.
Removed some dead code.
Added a few comments.
author | lindquist |
---|---|
date | Fri, 11 Jul 2008 00:17:00 +0200 |
parents | 571959608194 |
children | 20446d22f832 |
comparison
equal
deleted
inserted
replaced
327:781af50846b2 | 328:7086a84ab3d6 |
---|---|
71 } | 71 } |
72 // normal stack variable | 72 // normal stack variable |
73 else { | 73 else { |
74 // allocate storage on the stack | 74 // allocate storage on the stack |
75 const LLType* lltype = DtoType(vd->type); | 75 const LLType* lltype = DtoType(vd->type); |
76 | |
77 llvm::Value* allocainst; | |
76 if(gTargetData->getTypeSizeInBits(lltype) == 0) | 78 if(gTargetData->getTypeSizeInBits(lltype) == 0) |
77 { | 79 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); |
78 error("Allocating a variable of type %s and size zero is not implemented. (the behaviour of alloca with zero size is undefined)", vd->type->toChars()); | 80 else |
79 fatal(); | 81 allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); |
80 } | 82 |
81 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); | |
82 //allocainst->setAlignment(vd->type->alignsize()); // TODO | 83 //allocainst->setAlignment(vd->type->alignsize()); // TODO |
83 assert(!vd->ir.irLocal); | 84 assert(!vd->ir.irLocal); |
84 vd->ir.irLocal = new IrLocal(vd); | 85 vd->ir.irLocal = new IrLocal(vd); |
85 vd->ir.irLocal->value = allocainst; | 86 vd->ir.irLocal->value = allocainst; |
86 | 87 |
426 LOG_SCOPE; | 427 LOG_SCOPE; |
427 | 428 |
428 Type* dtype = DtoDType(type); | 429 Type* dtype = DtoDType(type); |
429 Type* cty = DtoDType(dtype->next); | 430 Type* cty = DtoDType(dtype->next); |
430 | 431 |
431 const LLType* ct = DtoType(cty); | 432 const LLType* ct = DtoTypeNotVoid(cty); |
432 if (ct == LLType::VoidTy) | |
433 ct = LLType::Int8Ty; | |
434 //printf("ct = %s\n", type->next->toChars()); | 433 //printf("ct = %s\n", type->next->toChars()); |
435 const LLArrayType* at = LLArrayType::get(ct,len+1); | 434 const LLArrayType* at = LLArrayType::get(ct,len+1); |
436 | 435 |
437 LLConstant* _init; | 436 LLConstant* _init; |
438 if (cty->size() == 1) { | 437 if (cty->size() == 1) { |
1482 DValue* ThisExp::toElem(IRState* p) | 1481 DValue* ThisExp::toElem(IRState* p) |
1483 { | 1482 { |
1484 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1483 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1485 LOG_SCOPE; | 1484 LOG_SCOPE; |
1486 | 1485 |
1487 if (VarDeclaration* vd = var->isVarDeclaration()) { | 1486 // this seems to happen for dmd generated assert statements like: |
1487 // assert(this, "null this"); | |
1488 if (!var) | |
1489 { | |
1490 LLValue* v = p->func()->thisVar; | |
1491 assert(v); | |
1492 return new DImValue(type, v); | |
1493 } | |
1494 // regular this expr | |
1495 else if (VarDeclaration* vd = var->isVarDeclaration()) { | |
1488 LLValue* v; | 1496 LLValue* v; |
1489 v = p->func()->decl->ir.irFunc->thisVar; | 1497 v = p->func()->decl->ir.irFunc->thisVar; |
1490 if (llvm::isa<llvm::AllocaInst>(v)) | 1498 if (llvm::isa<llvm::AllocaInst>(v)) |
1491 v = DtoLoad(v); | 1499 v = DtoLoad(v); |
1492 const LLType* t = DtoType(type); | 1500 const LLType* t = DtoType(type); |
1493 if (v->getType() != t) | 1501 if (v->getType() != t) |
1494 v = DtoBitCast(v, t); | 1502 v = DtoBitCast(v, t); |
1495 return new DThisValue(vd, v); | 1503 return new DThisValue(vd, v); |
1496 } | 1504 } |
1497 | 1505 |
1506 // anything we're not yet handling ? | |
1498 assert(0); | 1507 assert(0); |
1499 return 0; | 1508 return 0; |
1500 } | 1509 } |
1501 | 1510 |
1502 ////////////////////////////////////////////////////////////////////////////////////////// | 1511 ////////////////////////////////////////////////////////////////////////////////////////// |
2003 | 2012 |
2004 ////////////////////////////////////////////////////////////////////////////////////////// | 2013 ////////////////////////////////////////////////////////////////////////////////////////// |
2005 | 2014 |
2006 DValue* AssertExp::toElem(IRState* p) | 2015 DValue* AssertExp::toElem(IRState* p) |
2007 { | 2016 { |
2008 Logger::print("AssertExp::toElem: %s | %s\n", toChars(), type->toChars()); | 2017 Logger::print("AssertExp::toElem: %s\n", toChars()); |
2009 LOG_SCOPE; | 2018 LOG_SCOPE; |
2010 | 2019 |
2011 // condition | 2020 // condition |
2012 DValue* cond = e1->toElem(p); | 2021 DValue* cond = e1->toElem(p); |
2013 | 2022 |