Changeset 435:74101be2a553
- Timestamp:
- 07/30/08 04:12:55
(5 months ago)
- Author:
- Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
- branch:
- default
- Message:
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration?.
Added support for align(1)/packed structs, other alignments are still ignored.
Fixed some problems with accessing lazy arguments.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r347 |
r435 |
|
| 11 | 11 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 12 | 12 | |
|---|
| 13 | | DVarValue::DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue) |
|---|
| | 13 | DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue, bool lvalue) |
|---|
| 14 | 14 | { |
|---|
| 15 | 15 | var = vd; |
|---|
| … | … | |
| 17 | 17 | rval = 0; |
|---|
| 18 | 18 | lval = lvalue; |
|---|
| 19 | | type = var->type; |
|---|
| | 19 | type = t; |
|---|
| 20 | 20 | } |
|---|
| 21 | 21 | |
|---|
| r361 |
r435 |
|
| 112 | 112 | bool lval; |
|---|
| 113 | 113 | |
|---|
| 114 | | DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue); |
|---|
| 115 | | DVarValue(Type* vd, LLValue* lv, LLValue* rv); |
|---|
| | 114 | DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue, bool lvalue); |
|---|
| | 115 | DVarValue(Type* t, LLValue* lv, LLValue* rv); |
|---|
| 116 | 116 | DVarValue(Type* t, LLValue* llvmValue, bool lvalue); |
|---|
| 117 | 117 | |
|---|
| … | … | |
| 134 | 134 | struct DThisValue : DVarValue |
|---|
| 135 | 135 | { |
|---|
| 136 | | DThisValue(VarDeclaration* vd, LLValue* llvmValue) : DVarValue(vd, llvmValue, true) {} |
|---|
| | 136 | DThisValue(Type* t, VarDeclaration* vd, LLValue* llvmValue) : DVarValue(t, vd, llvmValue, true) {} |
|---|
| 137 | 137 | virtual DThisValue* isThis() { return this; } |
|---|
| 138 | 138 | }; |
|---|
| r428 |
r435 |
|
| 23 | 23 | const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bool ismain) |
|---|
| 24 | 24 | { |
|---|
| | 25 | assert(type->ty == Tfunction); |
|---|
| 25 | 26 | TypeFunction* f = (TypeFunction*)type; |
|---|
| 26 | | assert(f != 0); |
|---|
| 27 | 27 | |
|---|
| 28 | 28 | if (type->ir.type != NULL) { |
|---|
| r433 |
r435 |
|
| 1265 | 1265 | } |
|---|
| 1266 | 1266 | |
|---|
| 1267 | | return new DVarValue(vd, vd->ir.getIrValue(), true); |
|---|
| | 1267 | return new DVarValue(vd->type, vd, vd->ir.getIrValue(), true); |
|---|
| 1268 | 1268 | } |
|---|
| 1269 | 1269 | // struct declaration |
|---|
| r433 |
r435 |
|
| 107 | 107 | |
|---|
| 108 | 108 | /// |
|---|
| 109 | | TypeFunction* DtoTypeFunction(Type* type); |
|---|
| | 109 | TypeFunction* DtoTypeFunction(DValue* fnval); |
|---|
| 110 | 110 | |
|---|
| 111 | 111 | /// |
|---|
| r351 |
r435 |
|
| 125 | 125 | TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); |
|---|
| 126 | 126 | |
|---|
| | 127 | bool ispacked = (ts->alignsize() == 1); |
|---|
| | 128 | |
|---|
| 127 | 129 | IrStruct* irstruct = new IrStruct(ts); |
|---|
| 128 | 130 | sd->ir.irStruct = irstruct; |
|---|
| 129 | 131 | gIR->structs.push_back(irstruct); |
|---|
| | 132 | |
|---|
| | 133 | irstruct->packed = ispacked; |
|---|
| 130 | 134 | |
|---|
| 131 | 135 | // fields |
|---|
| … | … | |
| 171 | 175 | Logger::println("has no fields"); |
|---|
| 172 | 176 | fieldtypes.push_back(LLType::Int8Ty); |
|---|
| 173 | | structtype = llvm::StructType::get(fieldtypes); |
|---|
| | 177 | structtype = llvm::StructType::get(fieldtypes, ispacked); |
|---|
| 174 | 178 | } |
|---|
| 175 | 179 | else |
|---|
| … | … | |
| 240 | 244 | |
|---|
| 241 | 245 | Logger::println("creating struct type"); |
|---|
| 242 | | structtype = llvm::StructType::get(fieldtypes); |
|---|
| | 246 | structtype = llvm::StructType::get(fieldtypes, ispacked); |
|---|
| 243 | 247 | } |
|---|
| 244 | 248 | |
|---|
| … | … | |
| 330 | 334 | |
|---|
| 331 | 335 | // generate the union mapper |
|---|
| 332 | | sd->ir.irStruct->dunion = new DUnion; // uses gIR->topstruct() |
|---|
| | 336 | sd->ir.irStruct->dunion = new DUnion(); // uses gIR->topstruct() |
|---|
| 333 | 337 | |
|---|
| 334 | 338 | // always generate the constant initalizer |
|---|
| … | … | |
| 446 | 450 | } |
|---|
| 447 | 451 | |
|---|
| | 452 | ispacked = topstruct->packed; |
|---|
| | 453 | |
|---|
| 448 | 454 | /*{ |
|---|
| 449 | 455 | LOG_SCOPE; |
|---|
| … | … | |
| 534 | 540 | tys.push_back(out[i]->getType()); |
|---|
| 535 | 541 | |
|---|
| 536 | | const llvm::StructType* st = llvm::StructType::get(tys); |
|---|
| | 542 | const llvm::StructType* st = llvm::StructType::get(tys, ispacked); |
|---|
| 537 | 543 | return llvm::ConstantStruct::get(st, out); |
|---|
| 538 | 544 | } |
|---|
| r344 |
r435 |
|
| 67 | 67 | { |
|---|
| 68 | 68 | std::vector<DUnionField> fields; |
|---|
| | 69 | bool ispacked; |
|---|
| 69 | 70 | public: |
|---|
| 70 | 71 | DUnion(); |
|---|
| r422 |
r435 |
|
| 14 | 14 | ////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 15 | 15 | |
|---|
| 16 | | TypeFunction* DtoTypeFunction(Type* type) |
|---|
| 17 | | { |
|---|
| 18 | | TypeFunction* tf = 0; |
|---|
| 19 | | type = type->toBasetype(); |
|---|
| | 16 | TypeFunction* DtoTypeFunction(DValue* fnval) |
|---|
| | 17 | { |
|---|
| | 18 | Type* type = fnval->getType()->toBasetype(); |
|---|
| 20 | 19 | if (type->ty == Tfunction) |
|---|
| 21 | 20 | { |
|---|
| 22 | | tf = (TypeFunction*)type; |
|---|
| | 21 | return (TypeFunction*)type; |
|---|
| 23 | 22 | } |
|---|
| 24 | 23 | else if (type->ty == Tdelegate) |
|---|
| 25 | 24 | { |
|---|
| 26 | 25 | assert(type->next->ty == Tfunction); |
|---|
| 27 | | tf = (TypeFunction*)type->next; |
|---|
| 28 | | } |
|---|
| 29 | | return tf; |
|---|
| | 26 | return (TypeFunction*)type->next; |
|---|
| | 27 | } |
|---|
| | 28 | |
|---|
| | 29 | assert(0 && "cant get TypeFunction* from non lazy/function/delegate"); |
|---|
| | 30 | return 0; |
|---|
| 30 | 31 | } |
|---|
| 31 | 32 | |
|---|
| … | … | |
| 193 | 194 | |
|---|
| 194 | 195 | // get function type info |
|---|
| 195 | | TypeFunction* tf = DtoTypeFunction(calleeType); |
|---|
| 196 | | assert(tf); |
|---|
| | 196 | TypeFunction* tf = DtoTypeFunction(fnval); |
|---|
| 197 | 197 | |
|---|
| 198 | 198 | // misc |
|---|
| r433 |
r435 |
|
| 66 | 66 | LLValue* v = p->func()->_arguments; |
|---|
| 67 | 67 | assert(v); |
|---|
| 68 | | return new DVarValue(vd, v, true); |
|---|
| | 68 | return new DVarValue(type, vd, v, true); |
|---|
| 69 | 69 | } |
|---|
| 70 | 70 | // _argptr |
|---|
| … | … | |
| 74 | 74 | LLValue* v = p->func()->_argptr; |
|---|
| 75 | 75 | assert(v); |
|---|
| 76 | | return new DVarValue(vd, v, true); |
|---|
| | 76 | return new DVarValue(type, vd, v, true); |
|---|
| 77 | 77 | } |
|---|
| 78 | 78 | // _dollar |
|---|
| … | … | |
| 82 | 82 | assert(!p->arrays.empty()); |
|---|
| 83 | 83 | LLValue* tmp = DtoArrayLen(p->arrays.back()); |
|---|
| 84 | | return new DVarValue(vd, tmp, false); |
|---|
| | 84 | return new DVarValue(type, vd, tmp, false); |
|---|
| 85 | 85 | } |
|---|
| 86 | 86 | // typeinfo |
|---|
| … | … | |
| 96 | 96 | else |
|---|
| 97 | 97 | m = tid->ir.getIrValue(); |
|---|
| 98 | | return new DVarValue(vd, m, true); |
|---|
| | 98 | return new DVarValue(type, vd, m, true); |
|---|
| 99 | 99 | } |
|---|
| 100 | 100 | // classinfo |
|---|
| … | … | |
| 104 | 104 | DtoForceDeclareDsymbol(cid->cd); |
|---|
| 105 | 105 | assert(cid->cd->ir.irStruct->classInfo); |
|---|
| 106 | | return new DVarValue(vd, cid->cd->ir.irStruct->classInfo, true); |
|---|
| | 106 | return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo, true); |
|---|
| 107 | 107 | } |
|---|
| 108 | 108 | // nested variable |
|---|
| 109 | 109 | else if (vd->nestedref) { |
|---|
| 110 | 110 | Logger::println("nested variable"); |
|---|
| 111 | | return new DVarValue(vd, DtoNestedVariable(vd), true); |
|---|
| | 111 | return new DVarValue(type, vd, DtoNestedVariable(vd), true); |
|---|
| 112 | 112 | } |
|---|
| 113 | 113 | // function parameter |
|---|
| … | … | |
| 117 | 117 | if (fd && fd != p->func()->decl) { |
|---|
| 118 | 118 | Logger::println("nested parameter"); |
|---|
| 119 | | return new DVarValue(vd, DtoNestedVariable(vd), true); |
|---|
| | 119 | return new DVarValue(type, vd, DtoNestedVariable(vd), true); |
|---|
| 120 | 120 | } |
|---|
| 121 | 121 | else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) { |
|---|
| 122 | | return new DVarValue(vd, vd->ir.getIrValue(), true); |
|---|
| | 122 | return new DVarValue(type, vd, vd->ir.getIrValue(), true); |
|---|
| 123 | 123 | } |
|---|
| 124 | 124 | else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) { |
|---|
| … | … | |
| 138 | 138 | fatal(); |
|---|
| 139 | 139 | } |
|---|
| 140 | | return new DVarValue(vd, vd->ir.getIrValue(), true); |
|---|
| | 140 | return new DVarValue(type, vd, vd->ir.getIrValue(), true); |
|---|
| 141 | 141 | } |
|---|
| 142 | 142 | } |
|---|
| … | … | |
| 898 | 898 | |
|---|
| 899 | 899 | //Logger::cout() << "mem: " << *arrptr << '\n'; |
|---|
| 900 | | return new DVarValue(vd, arrptr, true); |
|---|
| | 900 | return new DVarValue(type, vd, arrptr, true); |
|---|
| 901 | 901 | } |
|---|
| 902 | 902 | else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) |
|---|
| … | … | |
| 978 | 978 | if (v->getType() != t) |
|---|
| 979 | 979 | v = DtoBitCast(v, t); |
|---|
| 980 | | return new DThisValue(vd, v); |
|---|
| | 980 | return new DThisValue(type, vd, v); |
|---|
| 981 | 981 | } |
|---|
| 982 | 982 | |
|---|
| … | … | |
| 2123 | 2123 | tys.push_back(DtoType(vx->type)); |
|---|
| 2124 | 2124 | } |
|---|
| 2125 | | const LLStructType* t = LLStructType::get(tys); |
|---|
| | 2125 | const LLStructType* t = LLStructType::get(tys, sd->ir.irStruct->packed); |
|---|
| 2126 | 2126 | if (t != llt) { |
|---|
| 2127 | 2127 | if (getABITypeSize(t) != getABITypeSize(llt)) { |
|---|
| r307 |
r435 |
|
| 49 | 49 | classDefined = false; |
|---|
| 50 | 50 | |
|---|
| | 51 | packed = false; |
|---|
| | 52 | |
|---|
| 51 | 53 | dwarfComposite = NULL; |
|---|
| 52 | 54 | } |
|---|
| r307 |
r435 |
|
| 82 | 82 | bool classDefined; |
|---|
| 83 | 83 | |
|---|
| | 84 | bool packed; // true for: align(1) struct S { ... } |
|---|
| | 85 | |
|---|
| 84 | 86 | LLGlobalVariable* dwarfComposite; |
|---|
| 85 | 87 | }; |
|---|