]> git.lizzy.rs Git - rust.git/blob - src/rustllvm/rustllvm.h
clean up error codes explanation
[rust.git] / src / rustllvm / rustllvm.h
1 #include "llvm-c/BitReader.h"
2 #include "llvm-c/Core.h"
3 #include "llvm-c/Object.h"
4 #include "llvm/ADT/ArrayRef.h"
5 #include "llvm/ADT/DenseSet.h"
6 #include "llvm/ADT/Triple.h"
7 #include "llvm/Analysis/Lint.h"
8 #include "llvm/Analysis/Passes.h"
9 #include "llvm/IR/IRBuilder.h"
10 #include "llvm/IR/InlineAsm.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/Support/CommandLine.h"
14 #include "llvm/Support/Debug.h"
15 #include "llvm/Support/DynamicLibrary.h"
16 #include "llvm/Support/FormattedStream.h"
17 #include "llvm/Support/Host.h"
18 #include "llvm/Support/Memory.h"
19 #include "llvm/Support/SourceMgr.h"
20 #include "llvm/Support/TargetRegistry.h"
21 #include "llvm/Support/TargetSelect.h"
22 #include "llvm/Support/Timer.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/Target/TargetMachine.h"
25 #include "llvm/Target/TargetOptions.h"
26 #include "llvm/Transforms/IPO.h"
27 #include "llvm/Transforms/Instrumentation.h"
28 #include "llvm/Transforms/Scalar.h"
29 #include "llvm/Transforms/Vectorize.h"
30
31 #define LLVM_VERSION_GE(major, minor)                                          \
32   (LLVM_VERSION_MAJOR > (major) ||                                             \
33    LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
34
35 #define LLVM_VERSION_EQ(major, minor)                                          \
36   (LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
37
38 #define LLVM_VERSION_LE(major, minor)                                          \
39   (LLVM_VERSION_MAJOR < (major) ||                                             \
40    LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
41
42 #define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
43
44 #include "llvm/IR/LegacyPassManager.h"
45
46 #include "llvm/Bitcode/BitcodeReader.h"
47 #include "llvm/Bitcode/BitcodeWriter.h"
48
49 #include "llvm/IR/DIBuilder.h"
50 #include "llvm/IR/DebugInfo.h"
51 #include "llvm/IR/IRPrintingPasses.h"
52 #include "llvm/Linker/Linker.h"
53
54 extern "C" void LLVMRustSetLastError(const char *);
55
56 enum class LLVMRustResult { Success, Failure };
57
58 enum LLVMRustAttribute {
59   AlwaysInline = 0,
60   ByVal = 1,
61   Cold = 2,
62   InlineHint = 3,
63   MinSize = 4,
64   Naked = 5,
65   NoAlias = 6,
66   NoCapture = 7,
67   NoInline = 8,
68   NonNull = 9,
69   NoRedZone = 10,
70   NoReturn = 11,
71   NoUnwind = 12,
72   OptimizeForSize = 13,
73   ReadOnly = 14,
74   SExt = 15,
75   StructRet = 16,
76   UWTable = 17,
77   ZExt = 18,
78   InReg = 19,
79   SanitizeThread = 20,
80   SanitizeAddress = 21,
81   SanitizeMemory = 22,
82   NonLazyBind = 23,
83   OptimizeNone = 24,
84   ReturnsTwice = 25,
85 };
86
87 typedef struct OpaqueRustString *RustStringRef;
88 typedef struct LLVMOpaqueTwine *LLVMTwineRef;
89 typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
90
91 extern "C" void LLVMRustStringWriteImpl(RustStringRef Str, const char *Ptr,
92                                         size_t Size);
93
94 class RawRustStringOstream : public llvm::raw_ostream {
95   RustStringRef Str;
96   uint64_t Pos;
97
98   void write_impl(const char *Ptr, size_t Size) override {
99     LLVMRustStringWriteImpl(Str, Ptr, Size);
100     Pos += Size;
101   }
102
103   uint64_t current_pos() const override { return Pos; }
104
105 public:
106   explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
107
108   ~RawRustStringOstream() {
109     // LLVM requires this.
110     flush();
111   }
112 };