[llvm-dev] question about llvmlite

Samaneh Berenjian via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 21 08:41:04 PDT 2017

Thank you for the reply. In the case of my code, it does not matter to use stmt or self. I even did your suggestion but right now it does not know the self. :( 

On Wed, 06/21/2017 10:44 AM, Brian Cain <bcain at codeaurora.org> wrote:

I think you want “stmt.addr” and “stmt.data” instead of “self.addr”, “self.data”.
You can check what attributes an object has with “dir(self)” and “dir(stmt)”.  The error indicates you’ve referenced an attribute of “self” that doesn’t exist.
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Samaneh Berenjian via llvm-dev
> Sent: Wednesday, June 21, 2017 8:58 AM
> To: llvm-dev at lists.llvm.org
> Subject: [llvm-dev] question about llvmlite
​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_int
import archinfo
import llvmlite.ir as ll
import llvmlite.binding as llvm
import pyvex
CODE = b"\x55\x48\x8b\x05\xb8\x13\x00\x00"
mehran = -100
module = ll.Module()
func_ty = ll.FunctionType(ll.VoidType(), [])
func = ll.Function(module, func_ty, name='read_instructions')
a = func.args
bb_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 ) )
       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.
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/79a3253a/attachment.html>

More information about the llvm-dev mailing list