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

Class GetLocalNodeType

libchigraph/src/GraphModule.cpp:527–566  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525};
526
527struct GetLocalNodeType : public NodeType {
528 GetLocalNodeType(ChiModule& mod, NamedDataType ty) : NodeType(mod), mDataType{std::move(ty)} {
529 setName("_get_" + mDataType.name);
530 setDescription("Get " + mDataType.name);
531
532 setDataOutputs({{"", mDataType.type}});
533
534 makePure();
535 }
536
537 Result codegen(size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation,
538 const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto,
539 const std::vector<llvm::BasicBlock*>& outputBlocks,
540 std::unordered_map<std::string, std::shared_ptr<void>>& compileCache) override {
541 llvm::IRBuilder<> builder{codegenInto};
542 builder.SetCurrentDebugLocation(nodeLocation);
543
544 std::shared_ptr<void>& local = compileCache[mDataType.name];
545
546 if (local == nullptr) {
547 // create a new one!
548 local = std::make_shared<llvm::Value*>(builder.CreateAlloca(mDataType.type.llvmType()));
549
550 // TODO: create an error here
551 }
552
553 builder.CreateStore(builder.CreateLoad(*static_cast<llvm::Value**>(local.get())), io[0]);
554
555 builder.CreateBr(outputBlocks[0]);
556
557 return {};
558 }
559
560 nlohmann::json toJSON() const override { return mDataType.type.qualifiedName(); }
561 std::unique_ptr<NodeType> clone() const override {
562 return std::make_unique<GetLocalNodeType>(module(), mDataType);
563 }
564
565 NamedDataType mDataType;
566};
567
568} // anon namespace
569

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected