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

Class SetLocalNodeType

libchigraph/src/GraphModule.cpp:486–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

484};
485
486struct SetLocalNodeType : public NodeType {
487 SetLocalNodeType(ChiModule& mod, NamedDataType ty) : NodeType(mod), mDataType{std::move(ty)} {
488 setName("_set_" + mDataType.name);
489 setDescription("Set " + mDataType.name);
490
491 setDataInputs({{"", mDataType.type}});
492
493 setExecInputs({""});
494 setExecOutputs({""});
495 }
496
497 Result codegen(size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation,
498 const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto,
499 const std::vector<llvm::BasicBlock*>& outputBlocks,
500 std::unordered_map<std::string, std::shared_ptr<void>>& compileCache) override {
501 llvm::IRBuilder<> builder{codegenInto};
502 builder.SetCurrentDebugLocation(nodeLocation);
503
504 std::shared_ptr<void>& local = compileCache[mDataType.name];
505
506 if (local == nullptr) {
507 // create a new one!
508 local = std::make_shared<llvm::Value*>(builder.CreateAlloca(mDataType.type.llvmType()));
509 }
510
511 // set the value!
512 builder.CreateStore(io[0], *static_cast<llvm::Value**>(local.get()));
513
514 builder.CreateBr(outputBlocks[0]);
515
516 return {};
517 }
518
519 nlohmann::json toJSON() const override { return mDataType.type.qualifiedName(); }
520 std::unique_ptr<NodeType> clone() const override {
521 return std::make_unique<SetLocalNodeType>(module(), mDataType);
522 }
523
524 NamedDataType mDataType;
525};
526
527struct GetLocalNodeType : public NodeType {
528 GetLocalNodeType(ChiModule& mod, NamedDataType ty) : NodeType(mod), mDataType{std::move(ty)} {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected