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

Class BreakStructNodeType

libchigraph/src/GraphModule.cpp:437–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435};
436
437struct BreakStructNodeType : public NodeType {
438 BreakStructNodeType(GraphStruct& ty) : NodeType(ty.module()), mStruct{&ty} {
439 setName("_break_" + ty.name());
440 setDescription("Break a " + ty.name() + " structure");
441 makePure();
442
443 // set input to just be the struct
444 setDataInputs({{"", ty.dataType()}});
445
446 // set outputs
447 setDataOutputs(ty.types());
448 }
449
450 Result codegen(size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation,
451 const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto,
452 const std::vector<llvm::BasicBlock*>& outputBlocks,
453 std::unordered_map<std::string, std::shared_ptr<void>>& compileCache) override {
454 llvm::IRBuilder<> builder{codegenInto};
455 builder.SetCurrentDebugLocation(nodeLocation);
456
457 // create temp struct
458 auto tempStruct = builder.CreateAlloca(mStruct->dataType().llvmType());
459 builder.CreateStore(io[0], tempStruct);
460
461 for (auto id = 1; id < io.size(); ++id) {
462 auto ptr = builder.CreateStructGEP(
463#if LLVM_VERSION_AT_LEAST(3, 7)
464 nullptr,
465#endif
466 tempStruct, id - 1);
467 std::string s = stringifyLLVMType(ptr->getType());
468
469 auto val = builder.CreateLoad(ptr);
470 builder.CreateStore(val, io[id]);
471 }
472
473 builder.CreateBr(outputBlocks[0]);
474
475 return {};
476 }
477
478 nlohmann::json toJSON() const override { return {}; }
479 std::unique_ptr<NodeType> clone() const override {
480 return std::make_unique<BreakStructNodeType>(*mStruct);
481 }
482
483 GraphStruct* mStruct;
484};
485
486struct SetLocalNodeType : public NodeType {
487 SetLocalNodeType(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