| 338 | } |
| 339 | |
| 340 | Result codegen(size_t execInputID, const llvm::DebugLoc& nodeLocation, |
| 341 | const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto, |
| 342 | const std::vector<llvm::BasicBlock*>& outputBlocks, |
| 343 | std::unordered_map<std::string, std::shared_ptr<void>>& compileCache) override { |
| 344 | Result res = {}; |
| 345 | |
| 346 | llvm::IRBuilder<> builder(codegenInto); |
| 347 | builder.SetCurrentDebugLocation(nodeLocation); |
| 348 | |
| 349 | auto func = codegenInto |
| 350 | -> |
| 351 | #if LLVM_VERSION_LESS_EQUAL(3, 6) |
| 352 | getParent() |
| 353 | ->getParent() |
| 354 | #else |
| 355 | getModule() |
| 356 | #endif |
| 357 | ->getFunction(mangleFunctionName(module().fullName(), name())); |
| 358 | |
| 359 | if (func == nullptr) { |
| 360 | res.addEntry("EINT", "Could not find function in llvm module", |
| 361 | {{"Requested Function", name()}}); |
| 362 | return res; |
| 363 | } |
| 364 | |
| 365 | // add the execInputID to the argument list |
| 366 | std::vector<llvm::Value*> passingIO; |
| 367 | passingIO.push_back(builder.getInt32(execInputID)); |
| 368 | |
| 369 | std::copy(io.begin(), io.end(), std::back_inserter(passingIO)); |
| 370 | |
| 371 | auto ret = builder.CreateCall(func, passingIO, "call_function"); |
| 372 | |
| 373 | // create switch on return |
| 374 | auto switchInst = builder.CreateSwitch(ret, outputBlocks[0]); // TODO: better default |
| 375 | |
| 376 | auto id = 0ull; |
| 377 | for (auto out : outputBlocks) { |
| 378 | switchInst->addCase(builder.getInt32(id), out); |
| 379 | ++id; |
| 380 | } |
| 381 | |
| 382 | return res; |
| 383 | } |
| 384 | |
| 385 | nlohmann::json toJSON() const override { return {}; } |
| 386 | std::unique_ptr<NodeType> clone() const override { |
nothing calls this directly
no test coverage detected