comparison gen/statements.cpp @ 331:04e1b4930975 trunk

[svn r352] Implement SwitchErrorStatement. Fixes #52.
author ChristianK
date Fri, 11 Jul 2008 21:06:39 +0200
parents e9c93739bc4c
children 20446d22f832
comparison
equal deleted inserted replaced
330:5bea8a1ef905 331:04e1b4930975
1222 // FIXME 1222 // FIXME
1223 } 1223 }
1224 1224
1225 ////////////////////////////////////////////////////////////////////////////// 1225 //////////////////////////////////////////////////////////////////////////////
1226 1226
1227 void SwitchErrorStatement::toIR(IRState* p)
1228 {
1229 Logger::println("SwitchErrorStatement::toIR(): %s", loc.toChars());
1230 LOG_SCOPE;
1231
1232 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_switch_error");
1233
1234 // param attrs
1235 llvm::PAListPtr palist;
1236 int idx = 1;
1237
1238 std::vector<LLValue*> args;
1239 LLConstant* c;
1240
1241 // file param
1242 // FIXME: every use creates a global for the filename !!!
1243 c = DtoConstString(loc.filename);
1244 llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
1245 if (!alloc)
1246 {
1247 alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint());
1248 gIR->func()->srcfileArg = alloc;
1249 }
1250 LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
1251 DtoStore(c->getOperand(0), ptr);
1252 ptr = DtoGEPi(alloc, 0,1, "tmp");
1253 DtoStore(c->getOperand(1), ptr);
1254
1255 args.push_back(alloc);
1256 palist = palist.addAttr(idx++, llvm::ParamAttr::ByVal);
1257
1258 // line param
1259 c = DtoConstUint(loc.linnum);
1260 args.push_back(c);
1261
1262 // call
1263 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
1264 call->setParamAttrs(palist);
1265
1266 gIR->ir->CreateUnreachable();
1267 }
1268
1269 //////////////////////////////////////////////////////////////////////////////
1270
1227 ////////////////////////////////////////////////////////////////////////////// 1271 //////////////////////////////////////////////////////////////////////////////
1228 1272
1229 #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();} 1273 #define STUBST(x) void x::toIR(IRState * p) {error("Statement type "#x" not implemented: %s", toChars());fatal();}
1230 //STUBST(BreakStatement); 1274 //STUBST(BreakStatement);
1231 //STUBST(ForStatement); 1275 //STUBST(ForStatement);
1234 //STUBST(ReturnStatement); 1278 //STUBST(ReturnStatement);
1235 //STUBST(ContinueStatement); 1279 //STUBST(ContinueStatement);
1236 //STUBST(DefaultStatement); 1280 //STUBST(DefaultStatement);
1237 //STUBST(CaseStatement); 1281 //STUBST(CaseStatement);
1238 //STUBST(SwitchStatement); 1282 //STUBST(SwitchStatement);
1239 STUBST(SwitchErrorStatement); 1283 //STUBST(SwitchErrorStatement);
1240 STUBST(Statement); 1284 STUBST(Statement);
1241 //STUBST(IfStatement); 1285 //STUBST(IfStatement);
1242 //STUBST(ForeachStatement); 1286 //STUBST(ForeachStatement);
1243 //STUBST(DoStatement); 1287 //STUBST(DoStatement);
1244 //STUBST(WhileStatement); 1288 //STUBST(WhileStatement);