comparison gen/toir.cpp @ 1148:3d1b16dabd25

Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 21:50:32 +0100
parents dbe4af57b240
children 5ebe8224988b
comparison
equal deleted inserted replaced
1147:dbe4af57b240 1148:3d1b16dabd25
93 } 93 }
94 // typeinfo 94 // typeinfo
95 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) 95 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration())
96 { 96 {
97 Logger::println("TypeInfoDeclaration"); 97 Logger::println("TypeInfoDeclaration");
98 DtoForceDeclareDsymbol(tid); 98 tid->codegen(Type::sir);
99 assert(tid->ir.getIrValue()); 99 assert(tid->ir.getIrValue());
100 const LLType* vartype = DtoType(type); 100 const LLType* vartype = DtoType(type);
101 LLValue* m = tid->ir.getIrValue(); 101 LLValue* m = tid->ir.getIrValue();
102 if (m->getType() != getPtrToType(vartype)) 102 if (m->getType() != getPtrToType(vartype))
103 m = p->ir->CreateBitCast(m, vartype, "tmp"); 103 m = p->ir->CreateBitCast(m, vartype, "tmp");
105 } 105 }
106 // classinfo 106 // classinfo
107 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration()) 107 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration())
108 { 108 {
109 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); 109 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars());
110 DtoForceDeclareDsymbol(cid->cd); 110 cid->cd->codegen(Type::sir);;
111 assert(cid->cd->ir.irStruct->classInfo); 111 assert(cid->cd->ir.irStruct->classInfo);
112 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo); 112 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo);
113 } 113 }
114 // nested variable 114 // nested variable
115 #if DMDV2 115 #if DMDV2
173 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) 173 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
174 { 174 {
175 Logger::println("FuncDeclaration"); 175 Logger::println("FuncDeclaration");
176 LLValue* func = 0; 176 LLValue* func = 0;
177 if (fdecl->llvmInternal != LLVMva_arg) { 177 if (fdecl->llvmInternal != LLVMva_arg) {
178 DtoForceDeclareDsymbol(fdecl); 178 fdecl->codegen(Type::sir);
179 func = fdecl->ir.irFunc->func; 179 func = fdecl->ir.irFunc->func;
180 } 180 }
181 return new DFuncValue(fdecl, func); 181 return new DFuncValue(fdecl, func);
182 } 182 }
183 else if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration()) 183 else if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration())
186 Type* sdecltype = sdecl->type->toBasetype(); 186 Type* sdecltype = sdecl->type->toBasetype();
187 Logger::print("Sym: type=%s\n", sdecltype->toChars()); 187 Logger::print("Sym: type=%s\n", sdecltype->toChars());
188 assert(sdecltype->ty == Tstruct); 188 assert(sdecltype->ty == Tstruct);
189 TypeStruct* ts = (TypeStruct*)sdecltype; 189 TypeStruct* ts = (TypeStruct*)sdecltype;
190 assert(ts->sym); 190 assert(ts->sym);
191 DtoForceConstInitDsymbol(ts->sym); 191 ts->sym->codegen(Type::sir);
192 assert(ts->sym->ir.irStruct->init); 192 assert(ts->sym->ir.irStruct->init);
193 return new DVarValue(type, ts->sym->ir.irStruct->init); 193 return new DVarValue(type, ts->sym->ir.irStruct->init);
194 } 194 }
195 else 195 else
196 { 196 {
212 // this seems to be the static initialiser for structs 212 // this seems to be the static initialiser for structs
213 Type* sdecltype = sdecl->type->toBasetype(); 213 Type* sdecltype = sdecl->type->toBasetype();
214 Logger::print("Sym: type=%s\n", sdecltype->toChars()); 214 Logger::print("Sym: type=%s\n", sdecltype->toChars());
215 assert(sdecltype->ty == Tstruct); 215 assert(sdecltype->ty == Tstruct);
216 TypeStruct* ts = (TypeStruct*)sdecltype; 216 TypeStruct* ts = (TypeStruct*)sdecltype;
217 DtoForceConstInitDsymbol(ts->sym); 217 ts->sym->codegen(Type::sir);
218 assert(ts->sym->ir.irStruct->constInit); 218 assert(ts->sym->ir.irStruct->constInit);
219 return ts->sym->ir.irStruct->constInit; 219 return ts->sym->ir.irStruct->constInit;
220 } 220 }
221 221
222 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) 222 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration())
920 else if (DFuncValue* fv = v->isFunc()) { 920 else if (DFuncValue* fv = v->isFunc()) {
921 Logger::println("is func"); 921 Logger::println("is func");
922 //Logger::println("FuncDeclaration"); 922 //Logger::println("FuncDeclaration");
923 FuncDeclaration* fd = fv->func; 923 FuncDeclaration* fd = fv->func;
924 assert(fd); 924 assert(fd);
925 DtoForceDeclareDsymbol(fd); 925 fd->codegen(Type::sir);
926 return new DFuncValue(fd, fd->ir.irFunc->func); 926 return new DFuncValue(fd, fd->ir.irFunc->func);
927 } 927 }
928 else if (DImValue* im = v->isIm()) { 928 else if (DImValue* im = v->isIm()) {
929 Logger::println("is immediate"); 929 Logger::println("is immediate");
930 return v; 930 return v;
974 return llc; 974 return llc;
975 } 975 }
976 // static function 976 // static function
977 else if (FuncDeclaration* fd = vexp->var->isFuncDeclaration()) 977 else if (FuncDeclaration* fd = vexp->var->isFuncDeclaration())
978 { 978 {
979 DtoForceDeclareDsymbol(fd); 979 fd->codegen(Type::sir);
980 IrFunction* irfunc = fd->ir.irFunc; 980 IrFunction* irfunc = fd->ir.irFunc;
981 return irfunc->func; 981 return irfunc->func;
982 } 982 }
983 // something else 983 // something else
984 else 984 else
1123 1123
1124 // 1124 //
1125 // look up function 1125 // look up function
1126 // 1126 //
1127 if (!vtbllookup) { 1127 if (!vtbllookup) {
1128 DtoForceDeclareDsymbol(fdecl); 1128 fdecl->codegen(Type::sir);
1129 funcval = fdecl->ir.irFunc->func; 1129 funcval = fdecl->ir.irFunc->func;
1130 assert(funcval); 1130 assert(funcval);
1131 } 1131 }
1132 else { 1132 else {
1133 assert(fdecl->vtblIndex > 0); 1133 assert(fdecl->vtblIndex > 0);
1632 if (ts->isZeroInit()) { 1632 if (ts->isZeroInit()) {
1633 DtoAggrZeroInit(mem); 1633 DtoAggrZeroInit(mem);
1634 } 1634 }
1635 else { 1635 else {
1636 assert(ts->sym); 1636 assert(ts->sym);
1637 DtoForceConstInitDsymbol(ts->sym); 1637 ts->sym->codegen(Type::sir);
1638 DtoAggrCopy(mem,ts->sym->ir.irStruct->init); 1638 DtoAggrCopy(mem,ts->sym->ir.irStruct->init);
1639 } 1639 }
1640 return new DImValue(type, mem); 1640 return new DImValue(type, mem);
1641 } 1641 }
1642 // new basic type 1642 // new basic type
2025 assert(0 && "TODO delegate to abstract method"); 2025 assert(0 && "TODO delegate to abstract method");
2026 else if (func->toParent()->isInterfaceDeclaration()) 2026 else if (func->toParent()->isInterfaceDeclaration())
2027 assert(0 && "TODO delegate to interface method"); 2027 assert(0 && "TODO delegate to interface method");
2028 else 2028 else
2029 { 2029 {
2030 DtoForceDeclareDsymbol(func); 2030 func->codegen(Type::sir);
2031 castfptr = func->ir.irFunc->func; 2031 castfptr = func->ir.irFunc->func;
2032 } 2032 }
2033 2033
2034 castfptr = DtoBitCast(castfptr, dgty->getContainedType(1)); 2034 castfptr = DtoBitCast(castfptr, dgty->getContainedType(1));
2035 2035
2250 assert(fd); 2250 assert(fd);
2251 2251
2252 if (fd->isNested()) Logger::println("nested"); 2252 if (fd->isNested()) Logger::println("nested");
2253 Logger::println("kind = %s\n", fd->kind()); 2253 Logger::println("kind = %s\n", fd->kind());
2254 2254
2255 DtoForceDefineDsymbol(fd); 2255 fd->codegen(Type::sir);
2256 assert(fd->ir.irFunc->func); 2256 assert(fd->ir.irFunc->func);
2257 2257
2258 if(fd->tok == TOKdelegate) { 2258 if(fd->tok == TOKdelegate) {
2259 const LLType* dgty = DtoType(type); 2259 const LLType* dgty = DtoType(type);
2260 2260
2287 LOG_SCOPE; 2287 LOG_SCOPE;
2288 2288
2289 assert(fd); 2289 assert(fd);
2290 assert(fd->tok == TOKfunction); 2290 assert(fd->tok == TOKfunction);
2291 2291
2292 DtoForceDefineDsymbol(fd); 2292 fd->codegen(Type::sir);
2293 assert(fd->ir.irFunc->func); 2293 assert(fd->ir.irFunc->func);
2294 2294
2295 return fd->ir.irFunc->func; 2295 return fd->ir.irFunc->func;
2296 } 2296 }
2297 2297