Mercurial > projects > ldc
comparison gen/toir.cpp @ 1248:01909bd1132c
Merge.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Tue, 21 Apr 2009 17:54:43 +0200 |
parents | 837f48560863 465a77c904d4 |
children | 9014d7f0433f |
comparison
equal
deleted
inserted
replaced
1227:a16b587aab58 | 1248:01909bd1132c |
---|---|
129 // classinfo | 129 // classinfo |
130 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration()) | 130 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration()) |
131 { | 131 { |
132 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); | 132 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); |
133 cid->cd->codegen(Type::sir);; | 133 cid->cd->codegen(Type::sir);; |
134 assert(cid->cd->ir.irStruct->classInfo); | 134 return new DVarValue(type, vd, cid->cd->ir.irStruct->getClassInfoSymbol()); |
135 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo); | |
136 } | 135 } |
137 // nested variable | 136 // nested variable |
138 #if DMDV2 | 137 #if DMDV2 |
139 else if (vd->nestedrefs.dim) { | 138 else if (vd->nestedrefs.dim) { |
140 #else | 139 #else |
214 Logger::print("Sym: type=%s\n", sdecltype->toChars()); | 213 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
215 assert(sdecltype->ty == Tstruct); | 214 assert(sdecltype->ty == Tstruct); |
216 TypeStruct* ts = (TypeStruct*)sdecltype; | 215 TypeStruct* ts = (TypeStruct*)sdecltype; |
217 assert(ts->sym); | 216 assert(ts->sym); |
218 ts->sym->codegen(Type::sir); | 217 ts->sym->codegen(Type::sir); |
219 assert(ts->sym->ir.irStruct->init); | 218 |
220 return new DVarValue(type, ts->sym->ir.irStruct->init); | 219 return new DVarValue(type, ts->sym->ir.irStruct->getInitSymbol()); |
221 } | 220 } |
222 else | 221 else |
223 { | 222 { |
224 assert(0 && "Unimplemented VarExp type"); | 223 assert(0 && "Unimplemented VarExp type"); |
225 } | 224 } |
240 Type* sdecltype = sdecl->type->toBasetype(); | 239 Type* sdecltype = sdecl->type->toBasetype(); |
241 Logger::print("Sym: type=%s\n", sdecltype->toChars()); | 240 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
242 assert(sdecltype->ty == Tstruct); | 241 assert(sdecltype->ty == Tstruct); |
243 TypeStruct* ts = (TypeStruct*)sdecltype; | 242 TypeStruct* ts = (TypeStruct*)sdecltype; |
244 ts->sym->codegen(Type::sir); | 243 ts->sym->codegen(Type::sir); |
245 assert(ts->sym->ir.irStruct->constInit); | 244 |
246 return ts->sym->ir.irStruct->constInit; | 245 return ts->sym->ir.irStruct->getDefaultInit(); |
247 } | 246 } |
248 | 247 |
249 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) | 248 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) |
250 { | 249 { |
251 const LLType* vartype = DtoType(type); | 250 const LLType* vartype = DtoType(type); |
981 assert(type->toBasetype()->ty == Tpointer); | 980 assert(type->toBasetype()->ty == Tpointer); |
982 return DtoBitCast(gep, DtoType(type)); | 981 return DtoBitCast(gep, DtoType(type)); |
983 } | 982 } |
984 else if (e1->op == TOKstructliteral) | 983 else if (e1->op == TOKstructliteral) |
985 { | 984 { |
985 // FIXME: is this right? | |
986 StructLiteralExp* slexp = (StructLiteralExp*)e1; | 986 StructLiteralExp* slexp = (StructLiteralExp*)e1; |
987 LLConstant* lit = slexp->toConstElem(p); | 987 LLConstant* lit = slexp->toConstElem(p); |
988 return lit; | 988 return lit; |
989 } | 989 } |
990 // not yet supported | 990 // not yet supported |
1132 | 1132 |
1133 LLValue* zero = DtoConstUint(0); | 1133 LLValue* zero = DtoConstUint(0); |
1134 size_t vtblidx = fdecl->vtblIndex; | 1134 size_t vtblidx = fdecl->vtblIndex; |
1135 if (Logger::enabled()) | 1135 if (Logger::enabled()) |
1136 Logger::cout() << "vthis: " << *vthis << '\n'; | 1136 Logger::cout() << "vthis: " << *vthis << '\n'; |
1137 funcval = vthis; | 1137 funcval = DtoGEP(vthis, zero, zero); |
1138 if (!fdecl->isMember2()->isInterfaceDeclaration()) | |
1139 funcval = DtoGEP(funcval, zero, zero); | |
1140 funcval = DtoLoad(funcval); | 1138 funcval = DtoLoad(funcval); |
1141 Logger::println("vtblidx = %lu", vtblidx); | 1139 Logger::println("vtblidx = %lu", vtblidx); |
1142 funcval = DtoGEP(funcval, zero, DtoConstUint(vtblidx), toChars()); | 1140 funcval = DtoGEP(funcval, zero, DtoConstUint(vtblidx), toChars()); |
1143 funcval = DtoLoad(funcval); | 1141 funcval = DtoLoad(funcval); |
1144 | 1142 |
1644 DtoAggrZeroInit(mem); | 1642 DtoAggrZeroInit(mem); |
1645 } | 1643 } |
1646 else { | 1644 else { |
1647 assert(ts->sym); | 1645 assert(ts->sym); |
1648 ts->sym->codegen(Type::sir); | 1646 ts->sym->codegen(Type::sir); |
1649 DtoAggrCopy(mem,ts->sym->ir.irStruct->init); | 1647 DtoAggrCopy(mem,ts->sym->ir.irStruct->getInitSymbol()); |
1650 } | 1648 } |
1651 return new DImValue(type, mem); | 1649 return new DImValue(type, mem); |
1652 } | 1650 } |
1653 // new basic type | 1651 // new basic type |
1654 else | 1652 else |
1656 // allocate | 1654 // allocate |
1657 LLValue* mem = DtoNew(newtype); | 1655 LLValue* mem = DtoNew(newtype); |
1658 DVarValue tmpvar(newtype, mem); | 1656 DVarValue tmpvar(newtype, mem); |
1659 | 1657 |
1660 // default initialize | 1658 // default initialize |
1661 // FIXME: should this use DtoConstExpInit instead ? | 1659 // static arrays never appear here, so using the defaultInit is ok! |
1662 // or is static arrays the only troublemaker? | |
1663 Expression* exp = newtype->defaultInit(loc); | 1660 Expression* exp = newtype->defaultInit(loc); |
1664 DValue* iv = exp->toElem(gIR); | 1661 DValue* iv = exp->toElem(gIR); |
1665 DtoAssign(loc, &tmpvar, iv); | 1662 DtoAssign(loc, &tmpvar, iv); |
1666 | 1663 |
1667 // return as pointer-to | 1664 // return as pointer-to |
2410 DValue* StructLiteralExp::toElem(IRState* p) | 2407 DValue* StructLiteralExp::toElem(IRState* p) |
2411 { | 2408 { |
2412 Logger::print("StructLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars()); | 2409 Logger::print("StructLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
2413 LOG_SCOPE; | 2410 LOG_SCOPE; |
2414 | 2411 |
2412 // make sure the struct is resolved | |
2413 sd->codegen(Type::sir); | |
2414 | |
2415 // get inits | 2415 // get inits |
2416 std::vector<LLValue*> inits(sd->fields.dim, NULL); | 2416 std::vector<LLValue*> inits(sd->fields.dim, NULL); |
2417 | 2417 |
2418 size_t nexprs = elements->dim;; | 2418 size_t nexprs = elements->dim;; |
2419 Expression** exprs = (Expression**)elements->data; | 2419 Expression** exprs = (Expression**)elements->data; |
2467 | 2467 |
2468 LLConstant* StructLiteralExp::toConstElem(IRState* p) | 2468 LLConstant* StructLiteralExp::toConstElem(IRState* p) |
2469 { | 2469 { |
2470 Logger::print("StructLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); | 2470 Logger::print("StructLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
2471 LOG_SCOPE; | 2471 LOG_SCOPE; |
2472 | |
2473 // make sure the struct is resolved | |
2474 sd->codegen(Type::sir); | |
2472 | 2475 |
2473 // get inits | 2476 // get inits |
2474 std::vector<LLValue*> inits(sd->fields.dim, NULL); | 2477 std::vector<LLValue*> inits(sd->fields.dim, NULL); |
2475 | 2478 |
2476 size_t nexprs = elements->dim;; | 2479 size_t nexprs = elements->dim;; |