Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert miasm IR to llvm IR: AttributeError: 'LLVMContext_IRCompilation' object has no attribute 'vmcpu' #1458

Open
fishfacegit opened this issue Oct 4, 2023 · 2 comments

Comments

@fishfacegit
Copy link

Hi,

i try to convert miasm ir to llvm ir for further optimization.
Is there an easy way to implement missing operators such as FLAG_EQ_CMP?

Best Regards

context = LLVMContext_IRCompilation()
context.ir_arch = ir_arch
context.lifter = machine.lifter(loc_db)
func = LLVMFunction_IRCompilation(context, name="test")
func.ret_type = llvm_ir.VoidType()
func.init_fc()
func.from_ircfg(ircfg, append_ret=False)
NotImplementedError                       Traceback (most recent call last)
Cell In[13], line 12
      9 func.init_fc()
     11 # IRCFG is imported, without the final "ret void"
---> 12 func.from_ircfg(ircfg, append_ret=False)
     14 # Finish the function
     15 func.builder.ret_void()

File [~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1922](https://file+.vscode-resource.vscode-cdn.net/media/hadrian/int1TB/workspace/MasterArbeit/miasm/~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1922), in LLVMFunction_IRCompilation.from_ircfg(self, ircfg, append_ret)
   1920 for label, irblock in viewitems(ircfg.blocks):
   1921     self.builder.position_at_end(self.get_basic_block_by_loc_key(label))
-> 1922     self.gen_irblock(irblock)
   1924 # Branch the entry BBL on the IRCFG head
   1925 self.builder.position_at_end(self.entry_bbl)

File [~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1910](https://file+.vscode-resource.vscode-cdn.net/media/hadrian/int1TB/workspace/MasterArbeit/miasm/~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1910), in LLVMFunction_IRCompilation.gen_irblock(self, irblock)
   1908 attributes = [Attributes() for _ in range(len(irblock.assignblks))]
   1909 instr_offsets = None
-> 1910 return super(LLVMFunction_IRCompilation, self).gen_irblock(
   1911     instr_attrib, attributes, instr_offsets, irblock
   1912 )

File [~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1569](https://file+.vscode-resource.vscode-cdn.net/media/hadrian/int1TB/workspace/MasterArbeit/miasm/~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1569), in LLVMFunction.gen_irblock(self, instr_attrib, attributes, instr_offsets, irblock)
   1567         case2dst, case_value = self.expr2cases(src)
...
-> 1203     raise NotImplementedError('Unknown op: %s' % op)
   1205 last = self.add_ir(expr.args[0])
   1207 for i in range(1, len(expr.args)):

NotImplementedError: Unknown op: FLAG_EQ_CMP
@fishfacegit
Copy link
Author

Solved via:

expr_simp.enable_passes(ExpressionSimplifier.PASS_HIGH_TO_EXPLICIT)
ircfg.simplify(expr_simp)

@fishfacegit
Copy link
Author

How to resolve this vmcpu?

AttributeError                            Traceback (most recent call last)
Cell In[36], line 9
      6 func.init_fc()
      8 # IRCFG is imported, without the final "ret void"
----> 9 func.from_ircfg(ircfg, append_ret=False)
     11 # Finish the function
     12 func.builder.ret_void()

File [~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1922](https://file+.vscode-resource.vscode-cdn.net/media/hadrian/int1TB/workspace/MasterArbeit/miasm/~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1922), in LLVMFunction_IRCompilation.from_ircfg(self, ircfg, append_ret)
   1920 for label, irblock in viewitems(ircfg.blocks):
   1921     self.builder.position_at_end(self.get_basic_block_by_loc_key(label))
-> 1922     self.gen_irblock(irblock)
   1924 # Branch the entry BBL on the IRCFG head
   1925 self.builder.position_at_end(self.entry_bbl)

File [~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1910](https://file+.vscode-resource.vscode-cdn.net/media/hadrian/int1TB/workspace/MasterArbeit/miasm/~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1910), in LLVMFunction_IRCompilation.gen_irblock(self, irblock)
   1908 attributes = [Attributes() for _ in range(len(irblock.assignblks))]
   1909 instr_offsets = None
-> 1910 return super(LLVMFunction_IRCompilation, self).gen_irblock(
   1911     instr_attrib, attributes, instr_offsets, irblock
   1912 )

File [~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1569](https://file+.vscode-resource.vscode-cdn.net/media/hadrian/int1TB/workspace/MasterArbeit/miasm/~/miniconda3/envs/miasm/lib/python3.12/site-packages/miasm/jitter/llvmconvert.py:1569), in LLVMFunction.gen_irblock(self, instr_attrib, attributes, instr_offsets, irblock)
   1567         case2dst, case_value = self.expr2cases(src)
...
   (...)
    612     ]
    613 )

AttributeError: 'LLVMContext_IRCompilation' object has no attribute 'vmcpu'

@fishfacegit fishfacegit reopened this Oct 4, 2023
@fishfacegit fishfacegit changed the title Convert miasm IR to llvm IR: NotImplementedError: Unknown op: FLAG_EQ_CMP Convert miasm IR to llvm IR: AttributeError: 'LLVMContext_IRCompilation' object has no attribute 'vmcpu' Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant