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

Class IntToFloatNodeType

libchigraph/src/LangModule.cpp:308–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306};
307
308struct IntToFloatNodeType : NodeType {
309 IntToFloatNodeType(LangModule& mod) : NodeType(mod, "inttofloat", "convert integer to float") {
310 makePure();
311
312 setDataInputs({{"", mod.typeFromName("i32")}});
313 setDataOutputs({{"", mod.typeFromName("float")}});
314 }
315
316 Result codegen(
317 size_t /*execInputID*/, const llvm::DebugLoc& nodeLocation,
318 const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto,
319 const std::vector<llvm::BasicBlock*>& outputBlocks,
320 std::unordered_map<std::string, std::shared_ptr<void>>& /*compileCache*/) override {
321 assert(io.size() == 2 && codegenInto != nullptr && outputBlocks.size() == 1);
322
323 llvm::IRBuilder<> builder(codegenInto);
324 builder.SetCurrentDebugLocation(nodeLocation);
325
326 auto casted =
327 builder.CreateCast(llvm::Instruction::CastOps::SIToFP, io[0], builder.getFloatTy());
328 builder.CreateStore(casted, io[1]);
329
330 builder.CreateBr(outputBlocks[0]);
331
332 return {};
333 }
334
335 std::unique_ptr<NodeType> clone() const override {
336 return std::make_unique<IntToFloatNodeType>(*this);
337 }
338};
339
340struct FloatToIntNodeType : NodeType {
341 FloatToIntNodeType(LangModule& mod) : NodeType(mod, "floattoint", "convert float to integer") {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected