解决LLVM Interpreter

时间:2017-12-16 04:34:37

标签: llvm llvm-clang llvm-ir

我正在使用LLVM解释器。我试图通过使用ExecutionEngine.cpp和Execution.cpp来查找变量值。我可以找到当前值,但我有另一个问题。二进制操作可以用类似的地址完成。我认为他们使用临时地址,但为什么呢?我需要让它们与众不同才能得到一些结果。 更清楚

以下是不同基本块的不同说明,并附有解释信息。

第一条指令是:

About to interpret:   %BB1 = add i32 %4, 1
Basic Block Name: CBB1
 arg0:    %4 = load i32, i32* @BB1
 arg1:  i32 1
visitBinaryOperator
Source1 Current Input ::: 10
Source1 Current Address ::: 0x7fff4582cd90
Source1 [ 0, 41 ]
Source1 Current Input::: 1
Source1 Current Input ::: 10
Sourc2 Current Address::: 0x7fff4582cdc0

第二条指示是

About to interpret:   %10 = add nsw i32 %9, %8
BasicBlock Name: CBB2
     arg0:    %9 = load i32, i32* %sum, align 4
     arg1:    %8 = load i32, i32* %7, align 4
visitBinaryOperator
Source1 Current Input ::: 0
Source1 Current Address ::: 0x7fff4582cd90
Source2 Current Input ::: 0
Source2 Current Address::: 0x7fff4582cdc0

BasicBlock CBB2的一部分

  %8 = load i32, i32* %7, align 4
  %9 = load i32, i32* %sum, align 4
  %10 = add nsw i32 %9, %8
  store i32 %10, i32* %sum, align 4

我需要使用每个指令输入和输出的当前值和先前值进行一些分析。

我从函数Interpreter::visitBinaryOperator得到了值:

ExecutionContext &SF = ECStack.back();
Type *Ty    = I.getOperand(0)->getType();
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
GenericValue R;   // Result

获取地址y1, y2, r和值v1, v2, rv

uint8_t *y1 = reinterpret_cast<uint8_t *>(
               const_cast<uint64_t *>(Src1.IntVal.getRawData()));
int v1 = *reinterpret_cast<int *>(y1);
uint8_t *y2 = reinterpret_cast<uint8_t *>(
               const_cast<uint64_t *>(Src2.IntVal.getRawData()));
int v2 = *reinterpret_cast<int *>(y2);
uint8_t *r = reinterpret_cast<uint8_t *>(
               const_cast<uint64_t *>(R.IntVal.getRawData()));
int rv = *reinterpret_cast<int *>(r);

我还有另一个建议,如果我无法解决add指令的问题,我可以在loadadd指令之前使用store指令{{1}得到我的结果。我已经可以使用有效结果单独获取它们,但是如何连接到二进制操作的参数。

0 个答案:

没有答案
相关问题