[LLVMdev] Ocaml bindings for execution engines

Jianzhou Zhao jianzhou at seas.upenn.edu
Mon Oct 25 09:03:10 PDT 2010


Hi All,

Here is the code from bindings/ocam/executionengine/executionengine_ocaml.c.

/* llvalue -> GenericValue.t array -> ExecutionEngine.t -> GenericValue.t */
CAMLprim value llvm_ee_run_function(LLVMValueRef F, value Args,
                                    LLVMExecutionEngineRef EE) {
  unsigned NumArgs;
  LLVMGenericValueRef Result, *GVArgs;
  unsigned I;

  NumArgs = Wosize_val(Args);
  GVArgs = (LLVMGenericValueRef*) malloc(NumArgs * sizeof(LLVMGenericValueRef));
  for (I = 0; I != NumArgs; ++I)
    GVArgs[I] = Genericvalue_val(Field(Args, I));

  Result = LLVMRunFunction(EE, F, NumArgs, GVArgs);

  free(GVArgs);
  return alloc_generic_value(Result);
}

I noticed that the Args parameter has not been protected by CAMLparam
with CAMLreturn. Is this safe in this case, because we allocated a
GVArgs? The other bindings files, sometimes, also ignore CAMLparam and
CAMLreturn if Caml "value" refers to unit, but the Ocaml manual
suggests to use CAMLparam for any value parameters (
http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html#toc140). Is
there any case where we can weak this restriction?

I have been working on defining more bindings for ExecutionEngine, but
got some inconsistent results at runtime. I used valgrind to check my
program, it reports some invalid writes or reads in C overlapping with
some memory space managed by Ocaml, but the report is not detailed
enough. so I doubt if the binding code does any thing wrong.

Thanks.
-- 
Jianzhou



More information about the llvm-dev mailing list