[llvm-dev] Code Execution
Samaneh Berenjian via llvm-dev
llvm-dev at lists.llvm.org
Wed Jun 14 13:34:33 PDT 2017
import llvmlite.binding as llvm
import 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')
bb_entry = func.append_basic_block('entry')
irbuilder = ll.IRBuilder(bb_entry)
irsb = pyvex.block.IRSB(CODE, 0x400400, archinfo.ArchAMD64())
for stmt in irsb.statements:
if isinstance(stmt, pyvex.IRStmt.Store):
result = irbuilder.store_reg(ll.Constant(ll.IntType(64), stmt.data), ll.IntType(64), stmt.addr)
irbuilde.ret(result)
print("****************LLVM***********************")
print(module)
#Execute generated code.
"""
# initialize the LLVM machine
# These are all required (apparently)
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()
# Create engine and attach the generated module
# Create a target machine representing the host
target = llvm.Target.from_default_triple()
target_machine = target.create_target_machine()
# And an execution engine with an empty backing module
backing_mod = llvm.parse_assembly("")
engine = llvm.create_mcjit_compiler(backing_mod, target_machine)
# Parse our generated module
mod = llvm.parse_assembly( str( module ) )
mod.verify()
# Now add the module and make sure it is ready for execution
engine.add_module(mod)
engine.finalize_object()
func = engine.get_function_address('read_instructions')
Actually, I want this code to be compiled and executed and print out the output from:
result = irbuilder.store_reg(ll.Constant(ll.IntType(64), stmt.data), ll.IntType(64), stmt.addr)
Who knows how can I add lines for getting output for it?
--
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/20170615/a55c8c0b/attachment.html>
More information about the llvm-dev
mailing list