【发布时间】:2020-02-28 15:19:14
【问题描述】:
我面临的关于 llvmlite 的问题是生成一个简单的 hello world 示例。
我无法在我创建的函数中显示字符串全局变量值。
它似乎总是打印出第一个。
我已经尝试返回产生错误的字符串类型。
from llvmlite import ir
i64 = ir.IntType(64)
i8 = ir.IntType(16)
hellostr = 'hello, world!'
stringtype = ir.ArrayType(i64, len(hellostr))
module = ir.Module( name="m_hello_example" )
hello = ir.GlobalVariable(module, stringtype, '.str4')
fn_int_to_int_type = ir.FunctionType(i64, [stringtype.as_pointer()] )
fn_hel = ir.Function( module, fn_int_to_int_type, name="fn_hel" )
fn_hel_block = fn_hel.append_basic_block( name="fn_hel_entry" )
builder = ir.IRBuilder(fn_hel_block )
# zero = builder.constant(i64, 0)
# const_1 = ir.Constant(stringtype,1);
# builder.ret(const_1)
const_1 = ir.Constant(i64,1);
# print(const_1)
builder.ret(const_1)
print( module )
我期待输出打印出字符串 'hello, world!'。
任何帮助将不胜感激。
谢谢。
【问题讨论】:
标签: llvmlite