Mercurial > projects > ldc
comparison gen/toir.cpp @ 920:545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Fixed align N; in asm blocks.
Fixed inreg parameter passing on x86 for ref/out params.
Removed support for lazy initialization of function local static variables, I have no idea why I ever implemented this, it's not in the D spec, and DMD doesn't support it :P
Some of the global variable related changes might cause minor regressions, but they should be easily fixable.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Tue, 03 Feb 2009 08:54:57 +0100 |
parents | a4fcc13da3cd |
children | 5e3bb0c3ea8b |
comparison
equal
deleted
inserted
replaced
919:c76f74d09fb1 | 920:545f54041d91 |
---|---|
6 * has been parsed. Substitute your own behaviors for these routimes. | 6 * has been parsed. Substitute your own behaviors for these routimes. |
7 */ | 7 */ |
8 | 8 |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <math.h> | 10 #include <math.h> |
11 #include <sstream> | |
12 #include <fstream> | 11 #include <fstream> |
13 #include <iostream> | 12 #include <iostream> |
14 | 13 |
15 #include "gen/llvm.h" | 14 #include "gen/llvm.h" |
16 | 15 |
203 | 202 |
204 LLConstant* VarExp::toConstElem(IRState* p) | 203 LLConstant* VarExp::toConstElem(IRState* p) |
205 { | 204 { |
206 Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars()); | 205 Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars()); |
207 LOG_SCOPE; | 206 LOG_SCOPE; |
207 | |
208 if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration()) | 208 if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration()) |
209 { | 209 { |
210 // this seems to be the static initialiser for structs | 210 // this seems to be the static initialiser for structs |
211 Type* sdecltype = sdecl->type->toBasetype(); | 211 Type* sdecltype = sdecl->type->toBasetype(); |
212 Logger::print("Sym: type=%s\n", sdecltype->toChars()); | 212 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
214 TypeStruct* ts = (TypeStruct*)sdecltype; | 214 TypeStruct* ts = (TypeStruct*)sdecltype; |
215 DtoForceConstInitDsymbol(ts->sym); | 215 DtoForceConstInitDsymbol(ts->sym); |
216 assert(ts->sym->ir.irStruct->constInit); | 216 assert(ts->sym->ir.irStruct->constInit); |
217 return ts->sym->ir.irStruct->constInit; | 217 return ts->sym->ir.irStruct->constInit; |
218 } | 218 } |
219 else if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) | 219 |
220 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) | |
220 { | 221 { |
221 const LLType* vartype = DtoType(type); | 222 const LLType* vartype = DtoType(type); |
222 LLConstant* m = DtoTypeInfoOf(ti->tinfo, false); | 223 LLConstant* m = DtoTypeInfoOf(ti->tinfo, false); |
223 if (m->getType() != getPtrToType(vartype)) | 224 if (m->getType() != getPtrToType(vartype)) |
224 m = llvm::ConstantExpr::getBitCast(m, vartype); | 225 m = llvm::ConstantExpr::getBitCast(m, vartype); |
225 return m; | 226 return m; |
226 } | 227 } |
227 else if (VarDeclaration* vd = var->isVarDeclaration()) | 228 |
229 VarDeclaration* vd = var->isVarDeclaration(); | |
230 if (vd && vd->isConst() && vd->init) | |
228 { | 231 { |
229 // return the initializer | 232 // return the initializer |
230 assert(vd->init); | |
231 return DtoConstInitializer(loc, type, vd->init); | 233 return DtoConstInitializer(loc, type, vd->init); |
232 } | 234 } |
235 | |
233 // fail | 236 // fail |
234 assert(0 && "Unsupported const VarExp kind"); | 237 error("non-constant expression %s", toChars()); |
235 return NULL; | 238 return llvm::UndefValue::get(DtoType(type)); |
236 } | 239 } |
237 | 240 |
238 ////////////////////////////////////////////////////////////////////////////////////////// | 241 ////////////////////////////////////////////////////////////////////////////////////////// |
239 | 242 |
240 DValue* IntegerExp::toElem(IRState* p) | 243 DValue* IntegerExp::toElem(IRState* p) |