From 485b638272ab069dfc7504fa7d2b089543d36c38 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 11 Jul 2008 21:06:39 +0200 Subject: [PATCH] [svn r352] Implement SwitchErrorStatement. Fixes #52. --- dmd/mars.c | 2 +- gen/statements.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/dmd/mars.c b/dmd/mars.c index d554ae3a..d19ab501 100644 --- a/dmd/mars.c +++ b/dmd/mars.c @@ -264,7 +264,7 @@ int main(int argc, char *argv[]) global.params.useIn = 1; global.params.useOut = 1; global.params.useArrayBounds = 0; - global.params.useSwitchError = 0; + global.params.useSwitchError = 1; global.params.useInline = 0; // this one messes things up to a point where codegen breaks global.params.llvmInline = 0; // use this one instead to know if inline passes should be run global.params.obj = 1; diff --git a/gen/statements.cpp b/gen/statements.cpp index ac8ed1c2..c4906408 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -1224,6 +1224,50 @@ void VolatileStatement::toIR(IRState* p) ////////////////////////////////////////////////////////////////////////////// +void SwitchErrorStatement::toIR(IRState* p) +{ + Logger::println("SwitchErrorStatement::toIR(): %s", loc.toChars()); + LOG_SCOPE; + + llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_switch_error"); + + // param attrs + llvm::PAListPtr palist; + int idx = 1; + + std::vector args; + LLConstant* c; + + // file param + // FIXME: every use creates a global for the filename !!! + c = DtoConstString(loc.filename); + llvm::AllocaInst* alloc = gIR->func()->srcfileArg; + if (!alloc) + { + alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); + gIR->func()->srcfileArg = alloc; + } + LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp"); + DtoStore(c->getOperand(0), ptr); + ptr = DtoGEPi(alloc, 0,1, "tmp"); + DtoStore(c->getOperand(1), ptr); + + args.push_back(alloc); + palist = palist.addAttr(idx++, llvm::ParamAttr::ByVal); + + // line param + c = DtoConstUint(loc.linnum); + args.push_back(c); + + // call + CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); + call->setParamAttrs(palist); + + gIR->ir->CreateUnreachable(); +} + +////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();} @@ -1236,7 +1280,7 @@ void VolatileStatement::toIR(IRState* p) //STUBST(DefaultStatement); //STUBST(CaseStatement); //STUBST(SwitchStatement); -STUBST(SwitchErrorStatement); +//STUBST(SwitchErrorStatement); STUBST(Statement); //STUBST(IfStatement); //STUBST(ForeachStatement);