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

Class FloatToIntNodeType

libchigraph/src/LangModule.cpp:340–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338};
339
340struct FloatToIntNodeType : NodeType {
341 FloatToIntNodeType(LangModule& mod) : NodeType(mod, "floattoint", "convert float to integer") {
342 makePure();
343
344 setDataInputs({{"", mod.typeFromName("float")}});
345 setDataOutputs({{"", mod.typeFromName("i32")}});
346 }
347
348 Result codegen(
349 size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation,
350 const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto,
351 const std::vector<llvm::BasicBlock*>& outputBlocks,
352 std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override {
353 assert(io.size() == 2 && codegenInto != nullptr && outputBlocks.size() == 1);
354
355 llvm::IRBuilder<> builder(codegenInto);
356 builder.SetCurrentDebugLocation(nodeLocation);
357
358 auto casted =
359 builder.CreateCast(llvm::Instruction::CastOps::FPToSI, io[0], builder.getInt32Ty());
360 builder.CreateStore(casted, io[1]);
361
362 builder.CreateBr(outputBlocks[0]);
363
364 return {};
365 }
366
367 std::unique_ptr<NodeType> clone() const override {
368 return std::make_unique<FloatToIntNodeType>(*this);
369 }
370};
371
372/// \internal
373enum class BinOp { Add, Subtract, Multiply, Divide };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected