MCPcopy Create free account
hub / github.com/chigraph/chigraph / IfNodeType

Class IfNodeType

libchigraph/src/LangModule.cpp:24–48  ·  view source on GitHub ↗

NodeType for conditionals

Source from the content-addressed store, hash-verified

22namespace {
23/// NodeType for conditionals
24struct 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
50struct EntryNodeType : NodeType {
51 EntryNodeType(LangModule& mod, std::vector<NamedDataType> dataInputs,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected