Mercurial > projects > ldc
comparison gen/structs.cpp @ 435:74101be2a553
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.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 30 Jul 2008 10:12:55 +0200 |
parents | f273f5c58a9a |
children | 44f08170f4ef |
comparison
equal
deleted
inserted
replaced
433:b5f55f471e0b | 435:74101be2a553 |
---|---|
122 if (sd->prot() == PROTprivate && sd->getModule() != gIR->dmodule) | 122 if (sd->prot() == PROTprivate && sd->getModule() != gIR->dmodule) |
123 Logger::println("using a private struct from outside its module"); | 123 Logger::println("using a private struct from outside its module"); |
124 | 124 |
125 TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); | 125 TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); |
126 | 126 |
127 bool ispacked = (ts->alignsize() == 1); | |
128 | |
127 IrStruct* irstruct = new IrStruct(ts); | 129 IrStruct* irstruct = new IrStruct(ts); |
128 sd->ir.irStruct = irstruct; | 130 sd->ir.irStruct = irstruct; |
129 gIR->structs.push_back(irstruct); | 131 gIR->structs.push_back(irstruct); |
132 | |
133 irstruct->packed = ispacked; | |
130 | 134 |
131 // fields | 135 // fields |
132 Array* arr = &sd->fields; | 136 Array* arr = &sd->fields; |
133 for (int k=0; k < arr->dim; k++) { | 137 for (int k=0; k < arr->dim; k++) { |
134 VarDeclaration* v = (VarDeclaration*)arr->data[k]; | 138 VarDeclaration* v = (VarDeclaration*)arr->data[k]; |
168 | 172 |
169 if (irstruct->offsets.empty()) | 173 if (irstruct->offsets.empty()) |
170 { | 174 { |
171 Logger::println("has no fields"); | 175 Logger::println("has no fields"); |
172 fieldtypes.push_back(LLType::Int8Ty); | 176 fieldtypes.push_back(LLType::Int8Ty); |
173 structtype = llvm::StructType::get(fieldtypes); | 177 structtype = llvm::StructType::get(fieldtypes, ispacked); |
174 } | 178 } |
175 else | 179 else |
176 { | 180 { |
177 Logger::println("has fields"); | 181 Logger::println("has fields"); |
178 unsigned prevsize = (unsigned)-1; | 182 unsigned prevsize = (unsigned)-1; |
237 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); | 241 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
238 irstruct->defaultFields.push_back(NULL); | 242 irstruct->defaultFields.push_back(NULL); |
239 } | 243 } |
240 | 244 |
241 Logger::println("creating struct type"); | 245 Logger::println("creating struct type"); |
242 structtype = llvm::StructType::get(fieldtypes); | 246 structtype = llvm::StructType::get(fieldtypes, ispacked); |
243 } | 247 } |
244 | 248 |
245 // refine abstract types for stuff like: struct S{S* next;} | 249 // refine abstract types for stuff like: struct S{S* next;} |
246 if (irstruct->recty != 0) | 250 if (irstruct->recty != 0) |
247 { | 251 { |
327 } | 331 } |
328 fieldinits_ll.push_back(c); | 332 fieldinits_ll.push_back(c); |
329 } | 333 } |
330 | 334 |
331 // generate the union mapper | 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 // always generate the constant initalizer | 338 // always generate the constant initalizer |
335 if (!sd->zeroInit) { | 339 if (!sd->zeroInit) { |
336 Logger::println("Not zero initialized"); | 340 Logger::println("Not zero initialized"); |
337 #if 0 | 341 #if 0 |
443 f->initsize = sz; | 447 f->initsize = sz; |
444 f->types.push_back(ft); | 448 f->types.push_back(ft); |
445 } | 449 } |
446 } | 450 } |
447 | 451 |
452 ispacked = topstruct->packed; | |
453 | |
448 /*{ | 454 /*{ |
449 LOG_SCOPE; | 455 LOG_SCOPE; |
450 Logger::println("******** DUnion BEGIN"); | 456 Logger::println("******** DUnion BEGIN"); |
451 size_t n = fields.size(); | 457 size_t n = fields.size(); |
452 for (size_t i=0; i<n; ++i) { | 458 for (size_t i=0; i<n; ++i) { |
531 std::vector<const LLType*> tys; | 537 std::vector<const LLType*> tys; |
532 size_t nout = out.size(); | 538 size_t nout = out.size(); |
533 for (size_t i=0; i<nout; ++i) | 539 for (size_t i=0; i<nout; ++i) |
534 tys.push_back(out[i]->getType()); | 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 return llvm::ConstantStruct::get(st, out); | 543 return llvm::ConstantStruct::get(st, out); |
538 } | 544 } |
539 | 545 |
540 | 546 |
541 | 547 |