[llvm] r220620 - [OCaml] Unbreak Llvm_executionengine.initialize_native_target.

Peter Zotov whitequark at whitequark.org
Sat Oct 25 11:50:02 PDT 2014


Author: whitequark
Date: Sat Oct 25 13:50:02 2014
New Revision: 220620

URL: http://llvm.org/viewvc/llvm-project?rev=220620&view=rev
Log:
[OCaml] Unbreak Llvm_executionengine.initialize_native_target.

First, return true on success, as it is the OCaml convention.
Second, also initialize the native assembly printer, which is,
despite the name, required for MCJIT operation.

Since this function did not initialize the assembly printer earlier
and no function to initialize native assembly printer was available
elsewhere, it is safe to break its interface: it means that it
simply could not be used successfully before.

Modified:
    llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c
    llvm/trunk/test/Bindings/Ocaml/executionengine.ml

Modified: llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c?rev=220620&r1=220619&r2=220620&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c Sat Oct 25 13:50:02 2014
@@ -32,7 +32,9 @@ void llvm_initialize(void) {
 
 /* unit -> bool */
 CAMLprim value llvm_initialize_native_target(value Unit) {
-  return Val_bool(LLVMInitializeNativeTarget());
+  return Val_bool(!LLVMInitializeNativeTarget() &&
+                  !LLVMInitializeNativeAsmParser() &&
+                  !LLVMInitializeNativeAsmPrinter());
 }
 
 /* Can't use the recommended caml_named_value mechanism for backwards
@@ -48,10 +50,10 @@ CAMLprim value llvm_register_ee_exns(val
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
   CAMLlocal1(CamlMessage);
-  
+
   CamlMessage = copy_string(Message);
   LLVMDisposeMessage(Message);
-  
+
   raise_with_arg(Prototype, CamlMessage);
   abort(); /* NOTREACHED */
 #ifdef CAMLnoreturn
@@ -258,14 +260,14 @@ CAMLprim value llvm_ee_run_function(LLVM
   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);
 }
@@ -291,21 +293,21 @@ CAMLprim value llvm_ee_run_function_as_m
   int I, NumArgs, NumEnv, EnvSize, Result;
   const char **CArgs, **CEnv;
   char *CEnvBuf, *Pos;
-  
+
   NumArgs = Wosize_val(Args);
   NumEnv = Wosize_val(Env);
-  
+
   /* Build the environment. */
   CArgs = (const char **) malloc(NumArgs * sizeof(char*));
   for (I = 0; I != NumArgs; ++I)
     CArgs[I] = String_val(Field(Args, I));
-  
+
   /* Compute the size of the environment string buffer. */
   for (I = 0, EnvSize = 0; I != NumEnv; ++I) {
     EnvSize += strlen(String_val(Field(Field(Env, I), 0))) + 1;
     EnvSize += strlen(String_val(Field(Field(Env, I), 1))) + 1;
   }
-  
+
   /* Build the environment. */
   CEnv = (const char **) malloc((NumEnv + 1) * sizeof(char*));
   CEnvBuf = (char*) malloc(EnvSize);
@@ -315,7 +317,7 @@ CAMLprim value llvm_ee_run_function_as_m
          *Value = String_val(Field(Field(Env, I), 1));
     int NameLen  = strlen(Name),
         ValueLen = strlen(Value);
-    
+
     CEnv[I] = Pos;
     memcpy(Pos, Name, NameLen);
     Pos += NameLen;
@@ -325,13 +327,13 @@ CAMLprim value llvm_ee_run_function_as_m
     *Pos++ = '\0';
   }
   CEnv[NumEnv] = NULL;
-  
+
   Result = LLVMRunFunctionAsMain(EE, F, NumArgs, CArgs, CEnv);
-  
+
   free(CArgs);
   free(CEnv);
   free(CEnvBuf);
-  
+
   CAMLreturn(Val_int(Result));
 }
 

Modified: llvm/trunk/test/Bindings/Ocaml/executionengine.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/executionengine.ml?rev=220620&r1=220619&r2=220620&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/executionengine.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/executionengine.ml Sat Oct 25 13:50:02 2014
@@ -19,6 +19,9 @@ let i32_type = Llvm.i32_type context
 let i64_type = Llvm.i64_type context
 let double_type = Llvm.double_type context
 
+let () =
+  assert (Llvm_executionengine.initialize_native_target ())
+
 let bomb msg =
   prerr_endline msg;
   exit 2





More information about the llvm-commits mailing list