comparison gen/toir.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 b5f55f471e0b
children 47b64d06eb9f
comparison
equal deleted inserted replaced
433:b5f55f471e0b 435:74101be2a553
63 if (vd->ident == Id::_arguments) 63 if (vd->ident == Id::_arguments)
64 { 64 {
65 Logger::println("Id::_arguments"); 65 Logger::println("Id::_arguments");
66 LLValue* v = p->func()->_arguments; 66 LLValue* v = p->func()->_arguments;
67 assert(v); 67 assert(v);
68 return new DVarValue(vd, v, true); 68 return new DVarValue(type, vd, v, true);
69 } 69 }
70 // _argptr 70 // _argptr
71 else if (vd->ident == Id::_argptr) 71 else if (vd->ident == Id::_argptr)
72 { 72 {
73 Logger::println("Id::_argptr"); 73 Logger::println("Id::_argptr");
74 LLValue* v = p->func()->_argptr; 74 LLValue* v = p->func()->_argptr;
75 assert(v); 75 assert(v);
76 return new DVarValue(vd, v, true); 76 return new DVarValue(type, vd, v, true);
77 } 77 }
78 // _dollar 78 // _dollar
79 else if (vd->ident == Id::dollar) 79 else if (vd->ident == Id::dollar)
80 { 80 {
81 Logger::println("Id::dollar"); 81 Logger::println("Id::dollar");
82 assert(!p->arrays.empty()); 82 assert(!p->arrays.empty());
83 LLValue* tmp = DtoArrayLen(p->arrays.back()); 83 LLValue* tmp = DtoArrayLen(p->arrays.back());
84 return new DVarValue(vd, tmp, false); 84 return new DVarValue(type, vd, tmp, false);
85 } 85 }
86 // typeinfo 86 // typeinfo
87 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) 87 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration())
88 { 88 {
89 Logger::println("TypeInfoDeclaration"); 89 Logger::println("TypeInfoDeclaration");
93 LLValue* m; 93 LLValue* m;
94 if (tid->ir.getIrValue()->getType() != getPtrToType(vartype)) 94 if (tid->ir.getIrValue()->getType() != getPtrToType(vartype))
95 m = p->ir->CreateBitCast(tid->ir.getIrValue(), vartype, "tmp"); 95 m = p->ir->CreateBitCast(tid->ir.getIrValue(), vartype, "tmp");
96 else 96 else
97 m = tid->ir.getIrValue(); 97 m = tid->ir.getIrValue();
98 return new DVarValue(vd, m, true); 98 return new DVarValue(type, vd, m, true);
99 } 99 }
100 // classinfo 100 // classinfo
101 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration()) 101 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration())
102 { 102 {
103 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); 103 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars());
104 DtoForceDeclareDsymbol(cid->cd); 104 DtoForceDeclareDsymbol(cid->cd);
105 assert(cid->cd->ir.irStruct->classInfo); 105 assert(cid->cd->ir.irStruct->classInfo);
106 return new DVarValue(vd, cid->cd->ir.irStruct->classInfo, true); 106 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo, true);
107 } 107 }
108 // nested variable 108 // nested variable
109 else if (vd->nestedref) { 109 else if (vd->nestedref) {
110 Logger::println("nested variable"); 110 Logger::println("nested variable");
111 return new DVarValue(vd, DtoNestedVariable(vd), true); 111 return new DVarValue(type, vd, DtoNestedVariable(vd), true);
112 } 112 }
113 // function parameter 113 // function parameter
114 else if (vd->isParameter()) { 114 else if (vd->isParameter()) {
115 Logger::println("function param"); 115 Logger::println("function param");
116 FuncDeclaration* fd = vd->toParent2()->isFuncDeclaration(); 116 FuncDeclaration* fd = vd->toParent2()->isFuncDeclaration();
117 if (fd && fd != p->func()->decl) { 117 if (fd && fd != p->func()->decl) {
118 Logger::println("nested parameter"); 118 Logger::println("nested parameter");
119 return new DVarValue(vd, DtoNestedVariable(vd), true); 119 return new DVarValue(type, vd, DtoNestedVariable(vd), true);
120 } 120 }
121 else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) { 121 else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) {
122 return new DVarValue(vd, vd->ir.getIrValue(), true); 122 return new DVarValue(type, vd, vd->ir.getIrValue(), true);
123 } 123 }
124 else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) { 124 else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) {
125 return new DImValue(type, vd->ir.getIrValue()); 125 return new DImValue(type, vd->ir.getIrValue());
126 } 126 }
127 else assert(0); 127 else assert(0);
135 if (!vd->ir.getIrValue() || DtoType(vd->type)->isAbstract()) { 135 if (!vd->ir.getIrValue() || DtoType(vd->type)->isAbstract()) {
136 error("global variable %s not resolved", vd->toChars()); 136 error("global variable %s not resolved", vd->toChars());
137 Logger::cout() << "unresolved global had type: " << *DtoType(vd->type) << '\n'; 137 Logger::cout() << "unresolved global had type: " << *DtoType(vd->type) << '\n';
138 fatal(); 138 fatal();
139 } 139 }
140 return new DVarValue(vd, vd->ir.getIrValue(), true); 140 return new DVarValue(type, vd, vd->ir.getIrValue(), true);
141 } 141 }
142 } 142 }
143 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) 143 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
144 { 144 {
145 Logger::println("FuncDeclaration"); 145 Logger::println("FuncDeclaration");
895 } 895 }
896 else 896 else
897 assert(0); 897 assert(0);
898 898
899 //Logger::cout() << "mem: " << *arrptr << '\n'; 899 //Logger::cout() << "mem: " << *arrptr << '\n';
900 return new DVarValue(vd, arrptr, true); 900 return new DVarValue(type, vd, arrptr, true);
901 } 901 }
902 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) 902 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
903 { 903 {
904 DtoResolveDsymbol(fdecl); 904 DtoResolveDsymbol(fdecl);
905 905
975 if (llvm::isa<llvm::AllocaInst>(v)) 975 if (llvm::isa<llvm::AllocaInst>(v))
976 v = DtoLoad(v); 976 v = DtoLoad(v);
977 const LLType* t = DtoType(type); 977 const LLType* t = DtoType(type);
978 if (v->getType() != t) 978 if (v->getType() != t)
979 v = DtoBitCast(v, t); 979 v = DtoBitCast(v, t);
980 return new DThisValue(vd, v); 980 return new DThisValue(type, vd, v);
981 } 981 }
982 982
983 // anything we're not yet handling ? 983 // anything we're not yet handling ?
984 assert(0); 984 assert(0);
985 return 0; 985 return 0;
2120 for (unsigned i=0; i<n; ++i) { 2120 for (unsigned i=0; i<n; ++i) {
2121 Expression* vx = (Expression*)elements->data[i]; 2121 Expression* vx = (Expression*)elements->data[i];
2122 if (!vx) continue; 2122 if (!vx) continue;
2123 tys.push_back(DtoType(vx->type)); 2123 tys.push_back(DtoType(vx->type));
2124 } 2124 }
2125 const LLStructType* t = LLStructType::get(tys); 2125 const LLStructType* t = LLStructType::get(tys, sd->ir.irStruct->packed);
2126 if (t != llt) { 2126 if (t != llt) {
2127 if (getABITypeSize(t) != getABITypeSize(llt)) { 2127 if (getABITypeSize(t) != getABITypeSize(llt)) {
2128 Logger::cout() << "got size " << getABITypeSize(t) << ", expected " << getABITypeSize(llt) << '\n'; 2128 Logger::cout() << "got size " << getABITypeSize(t) << ", expected " << getABITypeSize(llt) << '\n';
2129 assert(0 && "type size mismatch"); 2129 assert(0 && "type size mismatch");
2130 } 2130 }