rustc: Add support for LLVM memory buffer creation via a wrapper function
This commit is contained in:
parent
bd9dd5ed1a
commit
736969f9fe
@ -311,7 +311,8 @@ RUNTIME_HDR := rt/globals.h \
|
||||
RUNTIME_INCS := -Irt/isaac -Irt/uthash
|
||||
RUNTIME_OBJS := $(RUNTIME_CS:.cpp=.o)
|
||||
|
||||
SUPPORT_CS := llvmext/MachOObjectFile.cpp llvmext/Object.cpp
|
||||
SUPPORT_CS := $(addprefix llvmext/, \
|
||||
MachOObjectFile.cpp Object.cpp RustWrapper.cpp)
|
||||
|
||||
SUPPORT_HDR := llvmext/include/llvm-c/Object.h
|
||||
|
||||
|
@ -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. */
|
||||
|
31
src/llvmext/RustWrapper.cpp
Normal file
31
src/llvmext/RustWrapper.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
//===- RustWrapper.cpp - Rust wrapper for core functions --------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines alternate interfaces to core functions that are more
|
||||
// readily callable by Rust's FFI.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Object.h"
|
||||
#include <cstdlib>
|
||||
|
||||
static char *LLVMRustError;
|
||||
|
||||
extern "C" LLVMMemoryBufferRef
|
||||
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
||||
LLVMMemoryBufferRef MemBuf = NULL;
|
||||
LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, &LLVMRustError);
|
||||
return MemBuf;
|
||||
}
|
||||
|
||||
extern "C" const char *LLVMRustGetLastError(void) {
|
||||
return LLVMRustError;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user