diff options
| author | Keegan McAllister <kmcallister@mozilla.com> | 2014-09-09 23:12:09 -0700 |
|---|---|---|
| committer | Keegan McAllister <kmcallister@mozilla.com> | 2014-09-12 11:46:38 -0700 |
| commit | 225353d8bbad5730c941fc88e854627004e74f2c (patch) | |
| tree | d4f49fece5c0eb6a6f230149e6bec1b46edbda24 /src/rustllvm/rustllvm.h | |
| parent | 77b3a7ba8bf3ea0dd75bbe696c60275807bfe4ae (diff) | |
| download | rust-225353d8bbad5730c941fc88e854627004e74f2c.tar.gz rust-225353d8bbad5730c941fc88e854627004e74f2c.zip | |
Add a Rust string ostream for LLVM
Diffstat (limited to 'src/rustllvm/rustllvm.h')
| -rw-r--r-- | src/rustllvm/rustllvm.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h index 5722eea48d7..92f94b0e8e5 100644 --- a/src/rustllvm/rustllvm.h +++ b/src/rustllvm/rustllvm.h @@ -69,3 +69,31 @@ #endif void LLVMRustSetLastError(const char*); + +typedef struct OpaqueRustString *RustStringRef; + +extern "C" void +rust_llvm_string_write_impl(RustStringRef str, const char *ptr, size_t size); + +class raw_rust_string_ostream : public llvm::raw_ostream { + RustStringRef str; + uint64_t pos; + + void write_impl(const char *ptr, size_t size) override { + rust_llvm_string_write_impl(str, ptr, size); + pos += size; + } + + uint64_t current_pos() const override { + return pos; + } + +public: + explicit raw_rust_string_ostream(RustStringRef str) + : str(str), pos(0) { } + + ~raw_rust_string_ostream() { + // LLVM requires this. + flush(); + } +}; |
