I am using llvmpy
to (attempt to) generate IR code. However, I am stuck using printf
and an array of int8
.
The following is an excerpt of what is giving me issues:
# Defining the print function.
# -----
fntype = Type.function(Type.void(), [Type.pointer(Type.int(8))])
myprint = module.add_function(fntype, 'print')
cb = CBuilder(myprint)
x = cb.printf("%s\n", cb.args[0])
cb.ret()
cb.close()
# Creating the string.
# -----
chartype = Type.int(8)
chars = [Constant.int(chartype, ord(c)) for c in "Hello World!"]
string = Constant.array(chartype, chars)
ptr = string.gep([Constant.int(Type.int(8)), 0])
# Calling the print function.
# -----
cfn = exe.get_ctype_function(module.get_function_named('print'),
None, ct.c_char_p)
cfn(ptr)
When I run this code I receive
ctypes.ArgumentError: argument 1: : wrong type
What am I doing wrong? I feel that my usage of .gep()
is at fault, but I'm not sure in what way. Or is there something else that I don't understand?
Also, is there a way to get the expected type from the function?