Generating Print function for LLVM IR

34 Views Asked by At

The code that I wrote keeps seg-faulting.

void CodeGen::visit(const Print* stmt){
    Value* expr_value = stmt->get_val()->accept(this);
    Function* print_call = llvm_module->getFunction("print");
    if(!print_call){
        FunctionType* func_type = FunctionType::get(Type::getDoubleTy(llvm_context), 0, false);
        print_call = Function::Create(func_type, Function::ExternalLinkage, "print", llvm_module);
    }
    
    
    ir_builder.CreateCall(print_call, {expr_value});
}

I did some "std::cout"ing and it appears to be at getFunction("print"), but even when i try to create a new function, it also segmentation faults.

I'm not sure what I'm doing wrong, although I've never actually dealt with using LLVM IR before. I'm using the llvm doxygen documentation for this.

0

There are 0 best solutions below