[llvm-dev] question about llvmlite
Samaneh Berenjian via llvm-dev
llvm-dev at lists.llvm.org
Wed Jun 21 06:57:37 PDT 2017
Hi all,
I am using llvmlite for pyvex and I want the output of my code (which is written based on llvmlite) to be like pyvex. In pyvex, (https://github.com/angr/pyvex). Considering pyvex, I tried to implement the following statements in pyvex to llvmlite:
for stmt in irsb.statements: if isinstance(stmt, pyvex.IRStmt.Store): print "ST%s(%s) = %s" % (self.endness[-2:].lower(), self.addr, self.data) (which gets the data in a register and store it in another register)
I translate it in llvmlite as follows:
from ctypes import CFUNCTYPE, c_intimport archinfoimport llvmlite.ir as llimport llvmlite.binding as llvmimport pyvex
CODE = b"\x55\x48\x8b\x05\xb8\x13\x00\x00"mehran = -100
llvm.initialize()llvm.initialize_native_target()llvm.initialize_native_asmprinter()
module = ll.Module()func_ty = ll.FunctionType(ll.VoidType(), [])func = ll.Function(module, func_ty, name='read_instructions')a = func.argsbb_entry = func.append_basic_block('entry')irbuilder = ll.IRBuilder(bb_entry)int_type = ll.IntType(64);irsb = pyvex.block.IRSB(CODE, 0x400400, archinfo.ArchAMD64())
for stmt in irsb.statements:
#if isinstance(pyvex.IRStmt.Store): with irbuilder.if_then(stmt, pyvex.IRStmt.Store):
t = irbuilder.load_reg(ll.IntType(64), stmt.data) t1 = irbuilder.load_reg(ll.IntType(64), stmt.addr) tcall = irbuilder.call(func, [t]) t1call = irbuilder.call(func, [t1]) result = irbuilder.store_reg(ll.Constant(ll.IntType(64), t), ll.IntType(64), t1) irbuilder.ret( result ) print( module ) target = llvm.Target.from_default_triple() target_machine = target.create_target_machine() backing_mod = llvm.parse_assembly("") engine = llvm.create_mcjit_compiler(backing_mod, target_machine) mod = llvm.parse_assembly( str( module ) ) mod.verify() engine.add_module(mod) engine.finalize_object() func_ptr = engine.get_function_address("read_instructions") c_fn_fib = CFUNCTYPE(c_int64, c_int64)(func_ptr)
Having the above code, when running it, I am stopped with error:AttributeError: 'IMark' object has no attribute 'data'
Can anyone help me in this way?Thank you
--
This email was Anti Virus checked by Security Gateway.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170621/3ef002fa/attachment.html>
More information about the llvm-dev
mailing list