diff options
author | Peter Zotov <whitequark@whitequark.org> | 2013-11-03 08:27:45 +0000 |
---|---|---|
committer | Peter Zotov <whitequark@whitequark.org> | 2013-11-03 08:27:45 +0000 |
commit | f00a9e0f79541538df7e3af2e83de37f40d904cc (patch) | |
tree | 3252f086ab4f9d785465fe4d1344ecbba5b48c96 /bindings | |
parent | 88d74c3093de563408ceb834d999613038195e98 (diff) | |
download | external_llvm-f00a9e0f79541538df7e3af2e83de37f40d904cc.zip external_llvm-f00a9e0f79541538df7e3af2e83de37f40d904cc.tar.gz external_llvm-f00a9e0f79541538df7e3af2e83de37f40d904cc.tar.bz2 |
[OCaml] Implement Llvm.MemoryBuffer.{of_string,as_string}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193953 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/ocaml/llvm/llvm.ml | 2 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm.mli | 7 | ||||
-rw-r--r-- | bindings/ocaml/llvm/llvm_ocaml.c | 24 |
3 files changed, 33 insertions, 0 deletions
diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml index 6742708..7596d65 100644 --- a/bindings/ocaml/llvm/llvm.ml +++ b/bindings/ocaml/llvm/llvm.ml @@ -1167,6 +1167,8 @@ external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue module MemoryBuffer = struct external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file" external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin" + external of_string : ?name:string -> string -> llmemorybuffer = "llvm_memorybuffer_of_string" + external as_string : llmemorybuffer -> string = "llvm_memorybuffer_as_string" external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose" end diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index c4375dc..e90fafe 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -2345,6 +2345,13 @@ module MemoryBuffer : sig (** [of_stdin ()] is the memory buffer containing the contents of standard input. If standard input is empty, then [IoError msg] is raised. *) val of_stdin : unit -> llmemorybuffer + + (** [of_string ~name s] is the memory buffer containing the contents of string [s]. + The name of memory buffer is set to [name] if it is provided. *) + val of_string : ?name:string -> string -> llmemorybuffer + + (** [as_string mb] is the string containing the contents of memory buffer [mb]. *) + val as_string : llmemorybuffer -> string (** Disposes of a memory buffer. *) val dispose : llmemorybuffer -> unit diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index 80fa8c3..bd269ac 100644 --- a/bindings/ocaml/llvm/llvm_ocaml.c +++ b/bindings/ocaml/llvm/llvm_ocaml.c @@ -1996,6 +1996,30 @@ CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_stdin(value Unit) { return MemBuf; } +/* ?name:string -> string -> llmemorybuffer */ +CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_string(value Name, value String) { + const char *NameCStr; + if(Name == Val_int(0)) + NameCStr = ""; + else + NameCStr = String_val(Field(Name, 0)); + + LLVMMemoryBufferRef MemBuf; + MemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy( + String_val(String), caml_string_length(String), NameCStr); + + return MemBuf; +} + +/* llmemorybuffer -> string */ +CAMLprim value llvm_memorybuffer_as_string(LLVMMemoryBufferRef MemBuf) { + value String = caml_alloc_string(LLVMGetBufferSize(MemBuf)); + memcpy(String_val(String), LLVMGetBufferStart(MemBuf), + LLVMGetBufferSize(MemBuf)); + + return String; +} + /* llmemorybuffer -> unit */ CAMLprim value llvm_memorybuffer_dispose(LLVMMemoryBufferRef MemBuf) { LLVMDisposeMemoryBuffer(MemBuf); |