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
|
2013-05-27 18:15:31 -05:00
|
|
|
|
2016-12-30 05:22:11 -06:00
|
|
|
#define LLVM_VERSION_GE(major, minor) \
|
|
|
|
(LLVM_VERSION_MAJOR > (major) || \
|
|
|
|
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
2016-09-24 09:44:21 -05:00
|
|
|
|
2017-07-21 06:13:37 -05:00
|
|
|
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
|
|
|
|
|
2018-01-04 14:19:23 -06:00
|
|
|
extern "C" void LLVMRustSetLastError(const char *);
|
2014-09-10 01:12:09 -05:00
|
|
|
|
2016-12-30 05:22:11 -06:00
|
|
|
enum class LLVMRustResult { Success, Failure };
|
2016-08-01 16:16:16 -05:00
|
|
|
|
2014-09-10 01:12:09 -05:00
|
|
|
typedef struct OpaqueRustString *RustStringRef;
|
2014-09-12 10:17:58 -05:00
|
|
|
typedef struct LLVMOpaqueTwine *LLVMTwineRef;
|
2014-09-27 03:33:36 -05:00
|
|
|
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
|
2014-09-10 01:12:09 -05:00
|
|
|
|
2024-11-02 20:40:26 -05:00
|
|
|
extern "C" void LLVMRustStringWriteImpl(RustStringRef buf,
|
|
|
|
const char *slice_ptr,
|
|
|
|
size_t slice_len);
|
2014-09-10 01:12:09 -05:00
|
|
|
|
2016-12-31 11:01:23 -06:00
|
|
|
class RawRustStringOstream : public llvm::raw_ostream {
|
|
|
|
RustStringRef Str;
|
|
|
|
uint64_t Pos;
|
2014-09-10 01:12:09 -05:00
|
|
|
|
2016-12-31 11:01:23 -06:00
|
|
|
void write_impl(const char *Ptr, size_t Size) override {
|
|
|
|
LLVMRustStringWriteImpl(Str, Ptr, Size);
|
|
|
|
Pos += Size;
|
2016-12-30 05:22:11 -06:00
|
|
|
}
|
2014-09-10 01:12:09 -05:00
|
|
|
|
2016-12-31 11:01:23 -06:00
|
|
|
uint64_t current_pos() const override { return Pos; }
|
2014-09-10 01:12:09 -05:00
|
|
|
|
|
|
|
public:
|
2016-12-31 11:01:23 -06:00
|
|
|
explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
|
2014-09-10 01:12:09 -05:00
|
|
|
|
2016-12-31 11:01:23 -06:00
|
|
|
~RawRustStringOstream() {
|
2016-12-30 05:22:11 -06:00
|
|
|
// 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
|