NodeType for conditionals
| 22 | namespace { |
| 23 | /// NodeType for conditionals |
| 24 | struct IfNodeType : NodeType { |
| 25 | IfNodeType(LangModule& mod) : NodeType(mod, "if", "branch on a bools") { |
| 26 | setExecInputs({""}); |
| 27 | setExecOutputs({"True", "False"}); |
| 28 | |
| 29 | setDataInputs({{"condition", mod.typeFromName("i1")}}); |
| 30 | } |
| 31 | |
| 32 | Result codegen( |
| 33 | size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation, |
| 34 | const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto, |
| 35 | const std::vector<llvm::BasicBlock*>& outputBlocks, |
| 36 | std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override { |
| 37 | assert(io.size() == 1 && codegenInto != nullptr && outputBlocks.size() == 2); |
| 38 | |
| 39 | llvm::IRBuilder<> builder(codegenInto); |
| 40 | builder.SetCurrentDebugLocation(nodeLocation); |
| 41 | |
| 42 | builder.CreateCondBr(io[0], outputBlocks[0], outputBlocks[1]); |
| 43 | |
| 44 | return {}; |
| 45 | } |
| 46 | |
| 47 | std::unique_ptr<NodeType> clone() const override { return std::make_unique<IfNodeType>(*this); } |
| 48 | }; |
| 49 | |
| 50 | struct EntryNodeType : NodeType { |
| 51 | EntryNodeType(LangModule& mod, std::vector<NamedDataType> dataInputs, |
nothing calls this directly
no outgoing calls
no test coverage detected