rust/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h
bors 4b198d6871 Auto merge of #132584 - Zalathar:includes, r=cuviper
Trim and tidy includes in `rustc_llvm`

These includes tend to accumulate over time, and are usually only removed when something breaks in a new LLVM version, so it's nice to clean them up manually once in a while.

General strategy used for this PR:
- Remove all includes from `LLVMWrapper.h` that aren't needed by the header itself, transplanting them to individual source files as necessary.
- For each source file, temporarily remove each include if doing so doesn't cause a compile error.
- If a “required” include looks like it shouldn't be needed, try replacing it with its sub-includes, then trim that list.
- After doing all of the above, go back and re-add any removed include if the file does actually use things defined in that header, even if the header happens to also be included by something else.
2024-11-09 09:46:08 +00:00

50 lines
1.6 KiB
C++

#ifndef INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H
#define INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H
#include "SuppressLLVMWarnings.h"
#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))
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
extern "C" void LLVMRustSetLastError(const char *);
enum class LLVMRustResult { Success, Failure };
typedef struct OpaqueRustString *RustStringRef;
typedef struct LLVMOpaqueTwine *LLVMTwineRef;
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
extern "C" void LLVMRustStringWriteImpl(RustStringRef buf,
const char *slice_ptr,
size_t slice_len);
class RawRustStringOstream : public llvm::raw_ostream {
RustStringRef Str;
uint64_t Pos;
void write_impl(const char *Ptr, size_t Size) override {
LLVMRustStringWriteImpl(Str, Ptr, Size);
Pos += Size;
}
uint64_t current_pos() const override { return Pos; }
public:
explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
~RawRustStringOstream() {
// LLVM requires this.
flush();
}
};
#endif // INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H