comparison gen/arrays.cpp @ 295:895e1b50cf2a trunk

[svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42; There was problems with most non basic types... Added an option to premake so we can do: premake --target gnu --no-boehm to disable the Boehm GC.
author lindquist
date Mon, 23 Jun 2008 14:48:42 +0200
parents ebfa488f4abc
children 0548a7720a1b
comparison
equal deleted inserted replaced
294:94435b0ab2dd 295:895e1b50cf2a
109 } 109 }
110 } 110 }
111 111
112 ////////////////////////////////////////////////////////////////////////////////////////// 112 //////////////////////////////////////////////////////////////////////////////////////////
113 113
114 void DtoArrayInit(LLValue* l, LLValue* r)
115 {
116 Logger::println("DtoArrayInit");
117 LOG_SCOPE;
118
119 const LLPointerType* ptrty = isaPointer(l->getType());
120 const LLType* t = ptrty->getContainedType(0);
121 const LLArrayType* arrty = isaArray(t);
122 if (arrty)
123 {
124 LLValue* ptr = DtoGEPi(l,0,0);
125 LLValue* dim = DtoConstSize_t(arrty->getNumElements());
126 DtoArrayInit(ptr, dim, r);
127 }
128 else if (isaStruct(t))
129 {
130 LLValue* dim = DtoLoad(DtoGEPi(l, 0,0));
131 LLValue* ptr = DtoLoad(DtoGEPi(l, 0,1));
132 DtoArrayInit(ptr, dim, r);
133 }
134 else
135 assert(0);
136 }
137
138 //////////////////////////////////////////////////////////////////////////////////////////
139
140 typedef const LLType* constLLVMTypeP; 114 typedef const LLType* constLLVMTypeP;
141 115
142 static size_t checkRectArrayInit(const LLType* pt, constLLVMTypeP& finalty) 116 static size_t checkRectArrayInit(const LLType* pt, constLLVMTypeP& finalty)
143 { 117 {
144 if (const LLArrayType* arrty = isaArray(pt)) { 118 if (const LLArrayType* arrty = isaArray(pt)) {
149 } 123 }
150 finalty = pt; 124 finalty = pt;
151 return 0; 125 return 0;
152 } 126 }
153 127
154 void DtoArrayInit(LLValue* ptr, LLValue* dim, LLValue* val) 128 void DtoArrayInit(DValue* array, DValue* value)
155 { 129 {
156 Logger::println("DtoArrayInit"); 130 Logger::println("DtoArrayInit");
157 LOG_SCOPE; 131 LOG_SCOPE;
158 132
159 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; 133 LLValue* dim = DtoArrayLen(array);
134 LLValue* ptr = DtoArrayPtr(array);
135 LLValue* val = value->getRVal();
136
137 Logger::cout() << "llvm values:\n" << " ptr: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
138
160 const LLType* pt = ptr->getType()->getContainedType(0); 139 const LLType* pt = ptr->getType()->getContainedType(0);
161 const LLType* t = val->getType(); 140 const LLType* t = val->getType();
162 const LLType* finalTy; 141 const LLType* finalTy;
142
163 size_t aggrsz = 0; 143 size_t aggrsz = 0;
164 if (size_t arrsz = checkRectArrayInit(pt, finalTy)) { 144 Type* valtype = value->getType()->toBasetype();
145
146 // handle rectangular init
147 if (size_t arrsz = checkRectArrayInit(pt, finalTy))
148 {
165 assert(finalTy == t); 149 assert(finalTy == t);
166 LLConstant* c = isaConstant(dim); 150 LLConstant* c = isaConstant(dim);
167 assert(c); 151 assert(c);
168 dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz)); 152 dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz));
169 ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(finalTy), "tmp"); 153 ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(finalTy), "tmp");
170 } 154 }
171 else if (isaStruct(t)) { 155 // handle null aggregate
156 else if (isaStruct(t))
157 {
172 aggrsz = getABITypeSize(t); 158 aggrsz = getABITypeSize(t);
173 LLConstant* c = isaConstant(val); 159 LLConstant* c = isaConstant(val);
174 if (c && c->isNullValue()) { 160 assert(c && c->isNullValue());
175 LLValue* nbytes; 161 LLValue* nbytes;
176 if (aggrsz == 1) 162 if (aggrsz == 1)
177 nbytes = dim; 163 nbytes = dim;
178 else 164 else
179 nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(aggrsz), "tmp"); 165 nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(aggrsz), "tmp");
180 DtoMemSetZero(ptr,nbytes); 166 DtoMemSetZero(ptr,nbytes);
181 return; 167 return;
182 } 168 }
183 else { 169 // handle general aggregate case
184 ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(LLType::Int8Ty), "tmp"); 170 else if (DtoIsPassedByRef(valtype))
185 } 171 {
186 } 172 aggrsz = getABITypeSize(pt);
187 else { 173 ptr = gIR->ir->CreateBitCast(ptr, getVoidPtrType(), "tmp");
174 val = gIR->ir->CreateBitCast(val, getVoidPtrType(), "tmp");
175 }
176 else
177 {
178 Logger::cout() << "no special handling" << '\n';
188 assert(t == pt); 179 assert(t == pt);
189 } 180 }
190 181
191 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; 182 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
192 183