rust/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
C
Raw Normal View History

2024-11-03 04:09:01 -06:00
#ifndef INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H
#define INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H
2023-11-22 11:10:53 -06:00
#include "SuppressLLVMWarnings.h"
2024-11-03 04:09:01 -06:00
#include "llvm/Config/llvm-config.h" // LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR
#include "llvm/Support/raw_ostream.h" // llvm::raw_ostream
#include <cstddef> // size_t etc
#include <cstdint> // uint64_t etc
#define LLVM_VERSION_GE(major, minor) \
(LLVM_VERSION_MAJOR > (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
2017-07-21 06:13:37 -05:00
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
extern "C" void LLVMRustSetLastError(const char *);
2014-09-10 01:12:09 -05:00
enum class LLVMRustResult { Success, Failure };
2014-09-10 01:12:09 -05:00
typedef struct OpaqueRustString *RustStringRef;
typedef struct LLVMOpaqueTwine *LLVMTwineRef;
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
2014-09-10 01:12:09 -05:00
extern "C" void LLVMRustStringWriteImpl(RustStringRef buf,
const char *slice_ptr,
size_t slice_len);
2014-09-10 01:12:09 -05:00
class RawRustStringOstream : public llvm::raw_ostream {
RustStringRef Str;
uint64_t Pos;
2014-09-10 01:12:09 -05:00
void write_impl(const char *Ptr, size_t Size) override {
LLVMRustStringWriteImpl(Str, Ptr, Size);
Pos += Size;
}
2014-09-10 01:12:09 -05:00
uint64_t current_pos() const override { return Pos; }
2014-09-10 01:12:09 -05:00
public:
explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
2014-09-10 01:12:09 -05:00
~RawRustStringOstream() {
// LLVM requires this.
flush();
}
2014-09-10 01:12:09 -05:00
};
2024-11-03 04:09:01 -06:00
#endif // INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H