From dda7b25c1596ede7ff69eb813c323ee249fd8f5c Mon Sep 17 00:00:00 2001 From: cfreksen Date: Thu, 9 Nov 2017 18:23:21 +0100 Subject: [PATCH] Support recursive types (through pointers). Increment version. --- llvm_emulator/stepper.py | 24 +++++++++++++++++------- setup.py | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/llvm_emulator/stepper.py b/llvm_emulator/stepper.py index 013756c..ac3aa0e 100644 --- a/llvm_emulator/stepper.py +++ b/llvm_emulator/stepper.py @@ -211,19 +211,26 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap, if not isinstance(actual_oper_ty, ll.PointerType): err('Type of main operand to getelementptr must be a pointer type. It was {}' .format(ll.ty2s(actual_oper_ty))) - elif actual_base_ty != actual_oper_ty.inner_ty: - err(('Type of the main operand does not match the type getelementptr' - ' navigates through.\n' - ' Getelementptr type: {}\n' - ' Operand type: {}') - .format(ll.ty2s(actual_base_ty), ll.ty2s(actual_oper_ty.inner_ty))) else: + oper_inner_ty = ty2base_ty(actual_oper_ty.inner_ty, tdecs) + if actual_base_ty != oper_inner_ty: + warn(('Type of the main operand might not match the type getelementptr' + ' navigates through.\n' + ' Getelementptr type: {}\n' + ' Operand type: {}') + .format(ll.ty2s(actual_base_ty), ll.ty2s(oper_inner_ty))) + oper_v = eval_oper(oper, ssa_env, global_env) gep_res, formula = handle_gep(oper_v, actual_base_ty, steps, ssa_env, global_env) res = gep_res # TODO + print('Getting adress of {}{}'. + format(ll.ty2s(actual_base_ty), + ''.join('[{}]' + .format(eval_oper(step_oper, ssa_env, global_env)) + for _, step_oper in steps))) print('Gep formula: {}' .format(formula)) elif isinstance(next_insn, ll.Zext): @@ -357,6 +364,9 @@ def eval_oper(operand, ssa_env, global_env): err('Unable to find %{} in environment:\n{}' .format(id, ssa_env)) return 0 + else: + err('Unknown operand in eval_oper: {}' + .format(operand)) def eval_binop(bop, left, right): @@ -461,7 +471,7 @@ def ty2base_ty(ty, tdecs, seen=[]): elif isinstance(ty, ll.PointerType): # TODO: Consider if types behind pointers should not be # expanded. They might be allowed for cyclic types - return ll.PointerType(ty2base_ty(ty.inner_ty, tdecs, seen)) + return ty if isinstance(ty, ll.StructType): return ll.StructType([ty2base_ty(t, tdecs, seen) for t in ty.fields]) diff --git a/setup.py b/setup.py index 06eaf60..d4c7cf6 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ with open('pypi_readme.rst') as f: setup( name='llvm-minusminus-emulator', - version='1.0.2', + version='1.0.3', description='A simple hacky emulator/debugger for LLVM--', long_description=long_description, url='https://gitlab.com/cfreksen/llvm--emulator',