Llvm_executionengine无法正确执行指针操作

时间:2014-07-29 20:35:16

标签: ocaml llvm llvm-ir

我尝试使用无类型语言生成代码框和取消框值。为了评估一个简单的整数文字3,我生成:

define i64 @0() {
entry:
  %value = alloca { i64, [10 x i8], <10 x i64> }
  %boxptr = getelementptr inbounds { i64, [10 x i8], <10 x i64> }* %value, i32 0, i32 0
  store i64 3, i64* %boxptr
  %boxptr1 = getelementptr inbounds { i64, [10 x i8], <10 x i64> }* %value, i32 0, i32 0
  %load = load i64* %boxptr1
  ret i64 %load
}

看起来正确,lli将其评估为3,但Llvm_executionengine将函数计算为216172782113783808(垃圾值)。我toplevel.ml的代码如下:

open Llvm_executionengine

let the_execution_engine = ExecutionEngine.create_interpreter the_module

let print_and_jit se =
  let f = sexpr_matcher se in
  let result = ExecutionEngine.run_function f [||] the_execution_engine in
  print_string "Evaluated to ";
  print_int (GenericValue.as_int result);

我的翻译有什么问题?

0 个答案:

没有答案