changeset 331:04e1b4930975 trunk

[svn r352] Implement SwitchErrorStatement. Fixes #52.
author ChristianK
date Fri, 11 Jul 2008 21:06:39 +0200
parents 5bea8a1ef905
children d7e6ace5cca4
files dmd/mars.c gen/statements.cpp
diffstat 2 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mars.c	Fri Jul 11 20:23:42 2008 +0200
+++ b/dmd/mars.c	Fri Jul 11 21:06:39 2008 +0200
@@ -264,7 +264,7 @@
     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;
--- a/gen/statements.cpp	Fri Jul 11 20:23:42 2008 +0200
+++ b/gen/statements.cpp	Fri Jul 11 21:06:39 2008 +0200
@@ -1224,6 +1224,50 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
+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<LLValue*> 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 @@
 //STUBST(DefaultStatement);
 //STUBST(CaseStatement);
 //STUBST(SwitchStatement);
-STUBST(SwitchErrorStatement);
+//STUBST(SwitchErrorStatement);
 STUBST(Statement);
 //STUBST(IfStatement);
 //STUBST(ForeachStatement);