aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-15 14:57:26 -0700
committerPatrick Walton <[email protected]>2011-03-15 14:58:11 -0700
commit736969f9fe49b17174c6e06fbb7b1a8331ca94b2 (patch)
tree762d10760333efd5c9db1bf81007c7c78081fa30 /src/comp
parentChange the numbering of upcall functions. upcall_0 now calls a function (diff)
downloadrust-736969f9fe49b17174c6e06fbb7b1a8331ca94b2.tar.xz
rust-736969f9fe49b17174c6e06fbb7b1a8331ca94b2.zip
rustc: Add support for LLVM memory buffer creation via a wrapper function
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/lib/llvm.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs
index 8884b723..394d56e0 100644
--- a/src/comp/lib/llvm.rs
+++ b/src/comp/lib/llvm.rs
@@ -738,9 +738,7 @@ native mod llvm = llvm_lib {
/** Adds a verification pass. */
fn LLVMAddVerifierPass(PassManagerRef PM);
- // TODO: LLVMCreateMemoryBufferWithContentsOfFile is unrepresentable. Make
- // a shim.
- /** Destroys the memory buffer. */
+ /** Destroys a memory buffer. */
fn LLVMDisposeMemoryBuffer(MemoryBufferRef MemBuf);
}
@@ -770,6 +768,15 @@ native mod llvmext = llvmext_lib {
fn LLVMGetSectionSize(SectionIteratorRef SI) -> uint;
/** Returns the current section contents as a string buffer. */
fn LLVMGetSectionContents(SectionIteratorRef SI) -> sbuf;
+
+ /** Reads the given file and returns it as a memory buffer. Use
+ LLVMDisposeMemoryBuffer() to get rid of it. */
+ fn LLVMRustCreateMemoryBufferWithContentsOfFile(sbuf Path) ->
+ MemoryBufferRef;
+
+ /** Returns a string describing the last error caused by an LLVMRust*
+ call. */
+ fn LLVMRustGetLastError() -> sbuf;
}
/* Slightly more terse object-interface to LLVM's 'builder' functions. */
@@ -1382,8 +1389,13 @@ obj memory_buffer_dtor(MemoryBufferRef MemBuf) {
type memory_buffer = rec(MemoryBufferRef llmb, memory_buffer_dtor dtor);
-fn mk_memory_buffer() -> memory_buffer {
- fail; // TODO
+fn mk_memory_buffer(sbuf path) -> memory_buffer {
+ auto llmb = llvmext.LLVMRustCreateMemoryBufferWithContentsOfFile(path);
+ if ((llmb as int) == 0) {
+ log "failed to create memory buffer";
+ fail;
+ }
+ ret rec(llmb=llmb, dtor=memory_buffer_dtor(llmb));
}
/* Memory-managed interface to object files. */