<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.pl-s
        {mso-style-name:pl-s;}
span.pl-pds
        {mso-style-name:pl-pds;}
span.pl-c1
        {mso-style-name:pl-c1;}
span.pl-k
        {mso-style-name:pl-k;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle25
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>I think you want “stmt.addr” and “stmt.data” instead of “self.addr”, “self.data”.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>-Brian<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] <b>On Behalf Of </b>Samaneh Berenjian via llvm-dev<br><b>Sent:</b> Wednesday, June 21, 2017 8:58 AM<br><b>To:</b> llvm-dev@lists.llvm.org<br><b>Subject:</b> [llvm-dev] question about llvmlite<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>​Hi all,<o:p></o:p></span></p><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>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, (<a href="https://github.com/angr/pyvex">https://github.com/angr/pyvex</a>). Considering pyvex, I tried to implement the following statements in pyvex to llvmlite:<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>for stmt in irsb.statements:<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>   if isinstance(stmt, pyvex.IRStmt.Store):<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>      <span style='color:#D73A49'>print</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'> </span><span class=pl-pds><span style='font-size:9.0pt;font-family:Consolas;color:#032F62;background:white'>"</span></span><span class=pl-s><span style='font-size:9.0pt;font-family:Consolas;color:#032F62;background:white'>ST</span></span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>%s</span></span><span class=pl-s><span style='font-size:9.0pt;font-family:Consolas;color:#032F62;background:white'>(</span></span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>%s</span></span><span class=pl-s><span style='font-size:9.0pt;font-family:Consolas;color:#032F62;background:white'>) = </span></span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>%s</span></span><span class=pl-pds><span style='font-size:9.0pt;font-family:Consolas;color:#032F62;background:white'>"</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'> </span><span class=pl-k><span style='font-size:9.0pt;font-family:Consolas;color:#D73A49;background:white'>%</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'> (</span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>self</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'>.endness[</span><span class=pl-k><span style='font-size:9.0pt;font-family:Consolas;color:#D73A49;background:white'>-</span></span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>2</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'>:].lower(), </span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>self</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'>.addr, </span><span class=pl-c1><span style='font-size:9.0pt;font-family:Consolas;color:#005CC5;background:white'>self</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E;background:white'>.data)  (which gets the data in a register and store it in another register)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>I translate it in llvmlite as follows:</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>from ctypes import CFUNCTYPE, c_int</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>import archinfo</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>import llvmlite.ir as ll</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>import llvmlite.binding as llvm</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>import pyvex</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>CODE = b"\x55\x48\x8b\x05\xb8\x13\x00\x00"</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>mehran = -100</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>llvm.initialize()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>llvm.initialize_native_target()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>llvm.initialize_native_asmprinter()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>module = ll.Module()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>func_ty = ll.FunctionType(ll.VoidType(), [])</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>func = ll.Function(module, func_ty, name='read_instructions')</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>a = func.args</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>bb_entry = func.append_basic_block('entry')</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>irbuilder = ll.IRBuilder(bb_entry)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>int_type = ll.IntType(64);</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>irsb = pyvex.block.IRSB(CODE, 0x400400, archinfo.ArchAMD64())</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>for stmt in irsb.statements:</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>    #if isinstance(pyvex.IRStmt.Store):</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>    with irbuilder.if_then(stmt, pyvex.IRStmt.Store):</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       t = irbuilder.load_reg(ll.IntType(64), stmt.data)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       t1 = irbuilder.load_reg(ll.IntType(64), stmt.addr)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       tcall = irbuilder.call(func, [t])</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       t1call = irbuilder.call(func, [t1])</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       result  =  irbuilder.store_reg(ll.Constant(ll.IntType(64), t), ll.IntType(64), t1)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       irbuilder.ret( result )</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       print( module )</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Tahoma",sans-serif;color:#24292E;background:white'>       target = llvm.Target.from_default_triple()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>       </span><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>target_machine = target.create_target_machine()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       backing_mod = llvm.parse_assembly("")</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       engine = llvm.create_mcjit_compiler(backing_mod, target_machine)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       mod = llvm.parse_assembly( str( module ) )</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       mod.verify()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       engine.add_module(mod)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       engine.finalize_object()</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       func_ptr = engine.get_function_address("read_instructions")</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>       c_fn_fib = CFUNCTYPE(c_int64, c_int64)(func_ptr)</span><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>           <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>Having the above code, when running it, I am stopped with error:<o:p></o:p></span></p></div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>AttributeError: 'IMark' object has no attribute 'data'<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>Can anyone help me in this way?<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>Thank you<o:p></o:p></span></p></div><pre><o:p> </o:p></pre><pre>-- <o:p></o:p></pre><pre>This email was Anti Virus checked by  Security Gateway.<o:p></o:p></pre></div></body></html>