[llvm-commits] [llvm] r44899 - in /llvm/trunk: bindings/ocaml/llvm/llvm.ml bindings/ocaml/llvm/llvm.mli bindings/ocaml/llvm/llvm_ocaml.c include/llvm-c/BitReader.h include/llvm-c/Core.h lib/VMCore/Core.cpp test/Bindings/Ocaml/vmcore.ml
Gordon Henriksen
gordonhenriksen at mac.com
Tue Dec 11 17:04:30 PST 2007
Author: gordon
Date: Tue Dec 11 19:04:30 2007
New Revision: 44899
URL: http://llvm.org/viewvc/llvm-project?rev=44899&view=rev
Log:
Add (very basic) bindings for ModuleProvider.
Modified:
llvm/trunk/bindings/ocaml/llvm/llvm.ml
llvm/trunk/bindings/ocaml/llvm/llvm.mli
llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
llvm/trunk/include/llvm-c/BitReader.h
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/VMCore/Core.cpp
llvm/trunk/test/Bindings/Ocaml/vmcore.ml
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Tue Dec 11 19:04:30 2007
@@ -14,6 +14,7 @@
type llvalue
type llbasicblock
type llbuilder
+type llmoduleprovider
type type_kind =
Void_type
@@ -427,6 +428,13 @@
llbuilder -> llvalue = "llvm_build_shufflevector"
+(*===-- Module providers --------------------------------------------------===*)
+external create_module_provider : llmodule -> llmoduleprovider
+ = "LLVMCreateModuleProviderForExistingModule"
+external dispose_module_provider : llmoduleprovider -> unit
+ = "llvm_dispose_module_provider"
+
+
(*===-- Non-Externs -------------------------------------------------------===*)
(* These functions are built using the externals, so must be declared late. *)
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Tue Dec 11 19:04:30 2007
@@ -40,6 +40,9 @@
class. **)
type llbuilder
+(** Used to provide a module to JIT or interpreter. **)
+type llmoduleprovider
+
(** The kind of an [lltype], the result of [classify_type ty]. See the
[llvm::Type::TypeID] enumeration. **)
type type_kind =
@@ -1217,3 +1220,17 @@
See the method [llvm::LLVMBuilder::CreateShuffleVector]. **)
external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
llbuilder -> llvalue = "llvm_build_shufflevector"
+
+
+(*===-- Module providers --------------------------------------------------===*)
+
+(** [create_module_provider m] encapsulates [m] in a module provider and takes
+ ownership of the module. See the constructor
+ [llvm::ExistingModuleProvider::ExistingModuleProvider]. **)
+external create_module_provider : llmodule -> llmoduleprovider
+ = "LLVMCreateModuleProviderForExistingModule"
+
+(** [dispose_module_provider mp] destroys the module provider [mp] as well as
+ the contained module. **)
+external dispose_module_provider : llmoduleprovider -> unit
+ = "llvm_dispose_module_provider"
Modified: llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Tue Dec 11 19:04:30 2007
@@ -1047,3 +1047,11 @@
return LLVMBuildShuffleVector(Builder_val(B), V1, V2, Mask, String_val(Name));
}
+
+/*===-- Module Providers --------------------------------------------------===*/
+
+/* llmoduleprovider -> unit */
+CAMLprim value llvm_dispose_module_provider(LLVMModuleProviderRef MP) {
+ LLVMDisposeModuleProvider(MP);
+ return Val_unit;
+}
Modified: llvm/trunk/include/llvm-c/BitReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/BitReader.h?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/BitReader.h (original)
+++ llvm/trunk/include/llvm-c/BitReader.h Tue Dec 11 19:04:30 2007
@@ -32,6 +32,13 @@
int LLVMReadBitcodeFromFile(const char *Path, LLVMModuleRef *OutModule,
char **OutMessage);
+/* Reads a module from the specified path, returning a reference to a lazy
+ module provider via the OutModule parameter. Returns 0 on success. Optionally
+ returns a human-readable error message. */
+int LLVMCreateModuleProviderFromFile(const char *Path,
+ LLVMModuleProviderRef *OutMP,
+ char **OutMessage);
+
/* Disposes of the message allocated by the bitcode reader, if any. */
void LLVMDisposeBitcodeReaderMessage(char *Message);
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Tue Dec 11 19:04:30 2007
@@ -51,6 +51,7 @@
typedef struct LLVMOpaqueValue *LLVMValueRef;
typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
+typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
typedef enum {
LLVMVoidTypeKind, /* type with no size */
@@ -489,10 +490,26 @@
LLVMValueRef V2, LLVMValueRef Mask,
const char *Name);
+/*===-- Module providers --------------------------------------------------===*/
+
+/* Encapsulates the module M in a module provider, taking ownership of the
+ * module.
+ * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
+ */
+LLVMModuleProviderRef
+LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
+
+/* Destroys the module provider MP as well as the contained module.
+ * See the destructor llvm::ModuleProvider::~ModuleProvider.
+ */
+void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
+
#ifdef __cplusplus
}
namespace llvm {
+ class ModuleProvider;
+
/* Opaque module conversions
*/
inline Module *unwrap(LLVMModuleRef M) {
@@ -587,6 +604,16 @@
inline LLVMTypeHandleRef wrap(PATypeHolder *B) {
return reinterpret_cast<LLVMTypeHandleRef>(B);
}
+
+ /* Opaque module provider conversions.
+ */
+ inline ModuleProvider *unwrap(LLVMModuleProviderRef P) {
+ return reinterpret_cast<ModuleProvider*>(P);
+ }
+
+ inline LLVMModuleProviderRef wrap(ModuleProvider *P) {
+ return reinterpret_cast<LLVMModuleProviderRef>(P);
+ }
}
#endif /* !defined(__cplusplus) */
Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Tue Dec 11 19:04:30 2007
@@ -18,6 +18,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/TypeSymbolTable.h"
+#include "llvm/ModuleProvider.h"
#include <cassert>
using namespace llvm;
@@ -1030,3 +1031,16 @@
return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
unwrap(Mask), Name));
}
+
+
+/*===-- Module providers --------------------------------------------------===*/
+
+LLVMModuleProviderRef
+LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
+ return wrap(new ExistingModuleProvider(unwrap(M)));
+}
+
+void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
+ delete unwrap(MP);
+}
+
Modified: llvm/trunk/test/Bindings/Ocaml/vmcore.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/vmcore.ml?rev=44899&r1=44898&r2=44899&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/vmcore.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/vmcore.ml Tue Dec 11 19:04:30 2007
@@ -790,6 +790,14 @@
end
+(*===-- Module Provider ---------------------------------------------------===*)
+
+let test_module_provider () =
+ let m = create_module "test" in
+ let mp = create_module_provider m in
+ dispose_module_provider mp
+
+
(*===-- Writer ------------------------------------------------------------===*)
let test_writer () =
@@ -814,5 +822,6 @@
suite "functions" test_functions;
suite "basic blocks" test_basic_blocks;
suite "builder" test_builder;
+ suite "module provider" test_module_provider;
suite "writer" test_writer;
exit !exit_status
More information about the llvm-commits
mailing list