comparison gen/toir.cpp @ 88:058d3925950e trunk

[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
author lindquist
date Tue, 06 Nov 2007 10:03:14 +0100
parents fd32135dca3e
children 16e88334bba7
comparison
equal deleted inserted replaced
87:25d4fcce53f4 88:058d3925950e
25 #include "gen/elem.h" 25 #include "gen/elem.h"
26 #include "gen/logger.h" 26 #include "gen/logger.h"
27 #include "gen/tollvm.h" 27 #include "gen/tollvm.h"
28 #include "gen/runtime.h" 28 #include "gen/runtime.h"
29 #include "gen/arrays.h" 29 #include "gen/arrays.h"
30 #include "gen/structs.h"
30 31
31 #include "gen/dvalue.h" 32 #include "gen/dvalue.h"
32 33
33 ////////////////////////////////////////////////////////////////////////////////////////// 34 //////////////////////////////////////////////////////////////////////////////////////////
34 35
176 } 177 }
177 else assert(0); 178 else assert(0);
178 } 179 }
179 else { 180 else {
180 // take care of forward references of global variables 181 // take care of forward references of global variables
181 if (!vd->llvmTouched && vd->isDataseg()) 182 if (!vd->llvmTouched && (vd->isDataseg() || (vd->storage_class & STCextern))) // !vd->onstack)
182 vd->toObjFile(); 183 vd->toObjFile();
183 assert(vd->llvmValue); 184 if (!vd->llvmValue) {
185 Logger::println("global variable not resolved :/ %s", vd->toChars());
186 assert(0);
187 }
184 return new DVarValue(vd, vd->llvmValue, true); 188 return new DVarValue(vd, vd->llvmValue, true);
185 } 189 }
186 } 190 }
187 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) 191 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
188 { 192 {
223 assert(sdecltype->ty == Tstruct); 227 assert(sdecltype->ty == Tstruct);
224 TypeStruct* ts = (TypeStruct*)sdecltype; 228 TypeStruct* ts = (TypeStruct*)sdecltype;
225 assert(ts->sym->llvmInitZ); 229 assert(ts->sym->llvmInitZ);
226 return ts->sym->llvmInitZ; 230 return ts->sym->llvmInitZ;
227 } 231 }
228 assert(0 && "Only support const var exp is SymbolDeclaration"); 232 assert(0 && "Only supported const VarExp is of a SymbolDeclaration");
229 return NULL; 233 return NULL;
230 } 234 }
231 235
232 ////////////////////////////////////////////////////////////////////////////////////////// 236 //////////////////////////////////////////////////////////////////////////////////////////
233 237
245 { 249 {
246 Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 250 Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars());
247 LOG_SCOPE; 251 LOG_SCOPE;
248 const llvm::Type* t = DtoType(type); 252 const llvm::Type* t = DtoType(type);
249 if (llvm::isa<llvm::PointerType>(t)) { 253 if (llvm::isa<llvm::PointerType>(t)) {
254 Logger::println("pointer");
250 llvm::Constant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); 255 llvm::Constant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false);
251 return llvm::ConstantExpr::getIntToPtr(i, t); 256 return llvm::ConstantExpr::getIntToPtr(i, t);
252 } 257 }
253 else if (llvm::isa<llvm::IntegerType>(t)) { 258 assert(llvm::isa<llvm::IntegerType>(t));
254 return llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); 259 llvm::Constant* c = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned());
255 } 260 assert(c);
256 assert(0); 261 Logger::cout() << "value = " << *c << '\n';
257 return NULL; 262 return c;
258 } 263 }
259 264
260 ////////////////////////////////////////////////////////////////////////////////////////// 265 //////////////////////////////////////////////////////////////////////////////////////////
261 266
262 DValue* RealExp::toElem(IRState* p) 267 DValue* RealExp::toElem(IRState* p)
1445 } 1450 }
1446 1451
1447 if (isslice) { 1452 if (isslice) {
1448 return new DSliceValue(type, rval2, rval); 1453 return new DSliceValue(type, rval2, rval);
1449 } 1454 }
1450 else if (u->isLValueCast() || u->isVar()) { 1455 else if (u->isLValueCast() || (u->isVar() && u->isVar()->lval)) {
1451 return new DLValueCast(type, u->getLVal(), rval); 1456 return new DLValueCast(type, u->getLVal(), rval);
1452 } 1457 }
1453 else if (p->topexp() && p->topexp()->e1 == this) { 1458 else if (p->topexp() && p->topexp()->e1 == this) {
1454 llvm::Value* lval = u->getLVal(); 1459 llvm::Value* lval = u->getLVal();
1455 Logger::cout() << "lval: " << *lval << "rval: " << *rval << '\n'; 1460 Logger::cout() << "lval: " << *lval << "rval: " << *rval << '\n';
2873 STUB(RemoveExp); 2878 STUB(RemoveExp);
2874 //STUB(ArrayLiteralExp); 2879 //STUB(ArrayLiteralExp);
2875 STUB(AssocArrayLiteralExp); 2880 STUB(AssocArrayLiteralExp);
2876 //STUB(StructLiteralExp); 2881 //STUB(StructLiteralExp);
2877 2882
2878 #define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); assert(0); fatal(); return NULL; } 2883 #define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; }
2879 CONSTSTUB(Expression); 2884 CONSTSTUB(Expression);
2880 //CONSTSTUB(IntegerExp); 2885 //CONSTSTUB(IntegerExp);
2881 //CONSTSTUB(RealExp); 2886 //CONSTSTUB(RealExp);
2882 //CONSTSTUB(NullExp); 2887 //CONSTSTUB(NullExp);
2883 //CONSTSTUB(StringExp); 2888 //CONSTSTUB(StringExp);