#include "caml/fail.h"
#include "caml/callback.h"
-static void llvm_raise(value Prototype, char *Message) {
- CAMLparam1(Prototype);
- CAMLlocal1(CamlMessage);
-
- CamlMessage = copy_string(Message);
+value llvm_string_of_message(char* Message) {
+ value String = caml_copy_string(Message);
LLVMDisposeMessage(Message);
- raise_with_arg(Prototype, CamlMessage);
+ return String;
+}
+
+void llvm_raise(value Prototype, char *Message) {
+ CAMLparam1(Prototype);
+ caml_raise_with_arg(Prototype, llvm_string_of_message(Message));
CAMLnoreturn;
}
static value llvm_fatal_error_handler;
static void llvm_fatal_error_trampoline(const char *Reason) {
- callback(llvm_fatal_error_handler, copy_string(Reason));
+ callback(llvm_fatal_error_handler, caml_copy_string(Reason));
}
CAMLprim value llvm_install_fatal_error_handler(value Handler) {
return Val_unit;
}
+CAMLprim value llvm_parse_command_line_options(value Overview, value Args) {
+ char *COverview;
+ if (Overview == Val_int(0)) {
+ COverview = NULL;
+ } else {
+ COverview = String_val(Field(Overview, 0));
+ }
+ LLVMParseCommandLineOptions(Wosize_val(Args), (const char* const*) Op_val(Args), COverview);
+ return Val_unit;
+}
+
static value alloc_variant(int tag, void *Value) {
value Iter = alloc_small(1, tag);
Field(Iter, 0) = Val_op(Value);
/* llmodule -> string */
CAMLprim value llvm_target_triple(LLVMModuleRef M) {
- return copy_string(LLVMGetTarget(M));
+ return caml_copy_string(LLVMGetTarget(M));
}
/* string -> llmodule -> unit */
/* llmodule -> string */
CAMLprim value llvm_data_layout(LLVMModuleRef M) {
- return copy_string(LLVMGetDataLayout(M));
+ return caml_copy_string(LLVMGetDataLayout(M));
}
/* string -> llmodule -> unit */
/* llvalue -> string */
CAMLprim value llvm_value_name(LLVMValueRef Val) {
- return copy_string(LLVMGetValueName(Val));
+ return caml_copy_string(LLVMGetValueName(Val));
}
/* string -> llvalue -> unit */
Wosize_val(ElementVals));
}
+/* llcontext -> llvalue */
+CAMLprim LLVMValueRef llvm_mdnull(LLVMContextRef C) {
+ return NULL;
+}
+
/* llvalue -> string option */
CAMLprim value llvm_get_mdstring(LLVMValueRef V) {
CAMLparam0();
if (LLVMIsAConstantFP(Const)) {
Result = LLVMConstRealGetDouble(Const, &LosesInfo);
if (LosesInfo)
- return Val_int(0);
+ CAMLreturn(Val_int(0));
Option = alloc(1, 0);
Field(Option, 0) = caml_copy_double(Result);
return Val_unit;
}
+/* llvalue -> bool */
+CAMLprim value llvm_unnamed_addr(LLVMValueRef Global) {
+ return Val_bool(LLVMHasUnnamedAddr(Global));
+}
+
+/* bool -> llvalue -> unit */
+CAMLprim value llvm_set_unnamed_addr(value UseUnnamedAddr, LLVMValueRef Global) {
+ LLVMSetUnnamedAddr(Global, Bool_val(UseUnnamedAddr));
+ return Val_unit;
+}
+
/* llvalue -> string */
CAMLprim value llvm_section(LLVMValueRef Global) {
- return copy_string(LLVMGetSection(Global));
+ return caml_copy_string(LLVMGetSection(Global));
}
/* string -> llvalue -> unit */
return Val_unit;
}
+/* llvalue -> DLLStorageClass.t */
+CAMLprim value llvm_dll_storage_class(LLVMValueRef Global) {
+ return Val_int(LLVMGetDLLStorageClass(Global));
+}
+
+/* DLLStorageClass.t -> llvalue -> unit */
+CAMLprim value llvm_set_dll_storage_class(value Viz, LLVMValueRef Global) {
+ LLVMSetDLLStorageClass(Global, Int_val(Viz));
+ return Val_unit;
+}
+
/* llvalue -> int */
CAMLprim value llvm_alignment(LLVMValueRef Global) {
return Val_int(LLVMGetAlignment(Global));
CAMLlocal2(Name, Option);
if ((GC = LLVMGetGC(Fn))) {
- Name = copy_string(GC);
+ Name = caml_copy_string(GC);
Option = alloc(1, 0);
Field(Option, 0) = Name;
CAMLprim LLVMBasicBlockRef llvm_insertion_block(value B) {
LLVMBasicBlockRef InsertBlock = LLVMGetInsertBlock(Builder_val(B));
if (!InsertBlock)
- raise_not_found();
+ caml_raise_not_found();
return InsertBlock;
}
return PhiNode;
}
+/* lltype -> string -> llbuilder -> value */
+CAMLprim LLVMValueRef llvm_build_empty_phi(LLVMTypeRef Type, value Name, value B) {
+ LLVMValueRef PhiNode;
+
+ return LLVMBuildPhi(Builder_val(B), Type, String_val(Name));
+
+ return PhiNode;
+}
+
/* llvalue -> llvalue array -> string -> llbuilder -> llvalue */
CAMLprim LLVMValueRef llvm_build_call(LLVMValueRef Fn, value Params,
value Name, value B) {