Mercurial > projects > ldc
comparison gen/toir.cpp @ 1228:79758fd2f48a
Added Doxygen file.
Completely seperated type and symbol generation. Should fix a lot of bugs, but is not yet 100% complete.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Wed, 15 Apr 2009 20:06:25 +0200 |
parents | 50dc0db06238 |
children | 212ec2d9d176 |
comparison
equal
deleted
inserted
replaced
1215:08f87d8cd101 | 1228:79758fd2f48a |
---|---|
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); |
1132 | 1131 |
1133 LLValue* zero = DtoConstUint(0); | 1132 LLValue* zero = DtoConstUint(0); |
1134 size_t vtblidx = fdecl->vtblIndex; | 1133 size_t vtblidx = fdecl->vtblIndex; |
1135 if (Logger::enabled()) | 1134 if (Logger::enabled()) |
1136 Logger::cout() << "vthis: " << *vthis << '\n'; | 1135 Logger::cout() << "vthis: " << *vthis << '\n'; |
1137 funcval = vthis; | 1136 funcval = DtoGEP(vthis, zero, zero); |
1138 if (!fdecl->isMember2()->isInterfaceDeclaration()) | |
1139 funcval = DtoGEP(funcval, zero, zero); | |
1140 funcval = DtoLoad(funcval); | 1137 funcval = DtoLoad(funcval); |
1141 Logger::println("vtblidx = %lu", vtblidx); | 1138 Logger::println("vtblidx = %lu", vtblidx); |
1142 funcval = DtoGEP(funcval, zero, DtoConstUint(vtblidx), toChars()); | 1139 funcval = DtoGEP(funcval, zero, DtoConstUint(vtblidx), toChars()); |
1143 funcval = DtoLoad(funcval); | 1140 funcval = DtoLoad(funcval); |
1144 | 1141 |
1644 DtoAggrZeroInit(mem); | 1641 DtoAggrZeroInit(mem); |
1645 } | 1642 } |
1646 else { | 1643 else { |
1647 assert(ts->sym); | 1644 assert(ts->sym); |
1648 ts->sym->codegen(Type::sir); | 1645 ts->sym->codegen(Type::sir); |
1649 DtoAggrCopy(mem,ts->sym->ir.irStruct->init); | 1646 DtoAggrCopy(mem,ts->sym->ir.irStruct->getInitSymbol()); |
1650 } | 1647 } |
1651 return new DImValue(type, mem); | 1648 return new DImValue(type, mem); |
1652 } | 1649 } |
1653 // new basic type | 1650 // new basic type |
1654 else | 1651 else |
1656 // allocate | 1653 // allocate |
1657 LLValue* mem = DtoNew(newtype); | 1654 LLValue* mem = DtoNew(newtype); |
1658 DVarValue tmpvar(newtype, mem); | 1655 DVarValue tmpvar(newtype, mem); |
1659 | 1656 |
1660 // default initialize | 1657 // default initialize |
1661 // FIXME: should this use DtoConstExpInit instead ? | 1658 // 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); | 1659 Expression* exp = newtype->defaultInit(loc); |
1664 DValue* iv = exp->toElem(gIR); | 1660 DValue* iv = exp->toElem(gIR); |
1665 DtoAssign(loc, &tmpvar, iv); | 1661 DtoAssign(loc, &tmpvar, iv); |
1666 | 1662 |
1667 // return as pointer-to | 1663 // return as pointer-to |
2411 inits[i] = DtoLoad(inits[i]); | 2407 inits[i] = DtoLoad(inits[i]); |
2412 } | 2408 } |
2413 } | 2409 } |
2414 | 2410 |
2415 // vector of values to build aggregate from | 2411 // vector of values to build aggregate from |
2416 std::vector<LLValue*> values = DtoStructLiteralValues(sd, inits); | 2412 std::vector<LLValue*> values;// = DtoStructLiteralValues(sd, inits); |
2413 assert(0 && "struct literal exp todo"); | |
2417 | 2414 |
2418 // get the struct type from the values | 2415 // get the struct type from the values |
2419 size_t n = values.size(); | 2416 size_t n = values.size(); |
2420 std::vector<const LLType*> types(n, NULL); | 2417 std::vector<const LLType*> types(n, NULL); |
2421 | 2418 |
2460 for (size_t i = 0; i < nexprs; i++) | 2457 for (size_t i = 0; i < nexprs; i++) |
2461 if (exprs[i]) | 2458 if (exprs[i]) |
2462 inits[i] = exprs[i]->toConstElem(p); | 2459 inits[i] = exprs[i]->toConstElem(p); |
2463 | 2460 |
2464 // vector of values to build aggregate from | 2461 // vector of values to build aggregate from |
2465 std::vector<LLValue*> values = DtoStructLiteralValues(sd, inits); | 2462 std::vector<LLValue*> values;// = DtoStructLiteralValues(sd, inits); |
2463 assert(0 && "struct literal const exp todo"); | |
2466 | 2464 |
2467 // we know those values are constants.. cast them | 2465 // we know those values are constants.. cast them |
2468 std::vector<LLConstant*> constvals(values.size(), NULL); | 2466 std::vector<LLConstant*> constvals(values.size(), NULL); |
2469 for (size_t i = 0; i < values.size(); ++i) | 2467 for (size_t i = 0; i < values.size(); ++i) |
2470 constvals[i] = llvm::cast<LLConstant>(values[i]); | 2468 constvals[i] = llvm::cast<LLConstant>(values[i]); |