| 48 | }; |
| 49 | |
| 50 | struct EntryNodeType : NodeType { |
| 51 | EntryNodeType(LangModule& mod, std::vector<NamedDataType> dataInputs, |
| 52 | std::vector<std::string> execInputs) |
| 53 | : NodeType(mod, "entry", "entry to a function") { |
| 54 | setExecOutputs(std::move(execInputs)); |
| 55 | |
| 56 | setDataOutputs(std::move(dataInputs)); |
| 57 | } |
| 58 | |
| 59 | Result codegen( |
| 60 | size_t /*inputExecID*/, const llvm::DebugLoc& nodeLocation, |
| 61 | const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto, |
| 62 | const std::vector<llvm::BasicBlock*>& outputBlocks, |
| 63 | std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override { |
| 64 | assert(io.size() == dataOutputs().size() && codegenInto != nullptr && |
| 65 | outputBlocks.size() == execOutputs().size()); |
| 66 | |
| 67 | llvm::IRBuilder<> builder(codegenInto); |
| 68 | builder.SetCurrentDebugLocation(nodeLocation); |
| 69 | |
| 70 | // store the arguments |
| 71 | auto arg_iter = codegenInto->getParent()->arg_begin(); |
| 72 | ++arg_iter; // skip the first argument, which is the input exec ID |
| 73 | for (const auto& iovalue : io) { |
| 74 | builder.CreateStore(&*arg_iter, iovalue); |
| 75 | |
| 76 | ++arg_iter; |
| 77 | } |
| 78 | |
| 79 | auto inExecID = &*codegenInto->getParent()->arg_begin(); |
| 80 | auto switchInst = builder.CreateSwitch(inExecID, outputBlocks[0], execOutputs().size()); |
| 81 | |
| 82 | for (auto id = 0ull; id < execOutputs().size(); ++id) { |
| 83 | switchInst->addCase(builder.getInt32(id), outputBlocks[id]); |
| 84 | } |
| 85 | return {}; |
| 86 | } |
| 87 | |
| 88 | std::unique_ptr<NodeType> clone() const override { |
| 89 | return std::make_unique<EntryNodeType>(*this); |
| 90 | } |
| 91 | |
| 92 | nlohmann::json toJSON() const override { |
| 93 | nlohmann::json ret = nlohmann::json::object(); |
| 94 | |
| 95 | auto& data = ret["data"]; |
| 96 | data = nlohmann::json::array(); |
| 97 | for (auto& pair : dataOutputs()) { |
| 98 | data.push_back({{pair.name, pair.type.qualifiedName()}}); |
| 99 | } |
| 100 | |
| 101 | auto& exec = ret["exec"]; |
| 102 | exec = nlohmann::json::array(); |
| 103 | for (auto& name : execOutputs()) { exec.push_back(name); } |
| 104 | |
| 105 | return ret; |
| 106 | } |
| 107 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected