]> git.lizzy.rs Git - rust.git/blob - src/rustllvm/rustllvm.h
Auto merge of #55678 - Aaronepower:master, r=Mark-Simulacrum
[rust.git] / src / rustllvm / rustllvm.h
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #include "llvm-c/BitReader.h"
12 #include "llvm-c/Core.h"
13 #include "llvm-c/ExecutionEngine.h"
14 #include "llvm-c/Object.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/DenseSet.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Analysis/Lint.h"
19 #include "llvm/Analysis/Passes.h"
20 #include "llvm/ExecutionEngine/ExecutionEngine.h"
21 #include "llvm/ExecutionEngine/Interpreter.h"
22 #include "llvm/ExecutionEngine/MCJIT.h"
23 #include "llvm/IR/IRBuilder.h"
24 #include "llvm/IR/InlineAsm.h"
25 #include "llvm/IR/LLVMContext.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/DynamicLibrary.h"
30 #include "llvm/Support/FormattedStream.h"
31 #include "llvm/Support/Host.h"
32 #include "llvm/Support/Memory.h"
33 #include "llvm/Support/SourceMgr.h"
34 #include "llvm/Support/TargetRegistry.h"
35 #include "llvm/Support/TargetSelect.h"
36 #include "llvm/Support/Timer.h"
37 #include "llvm/Support/raw_ostream.h"
38 #include "llvm/Target/TargetMachine.h"
39 #include "llvm/Target/TargetOptions.h"
40 #include "llvm/Transforms/IPO.h"
41 #include "llvm/Transforms/Instrumentation.h"
42 #include "llvm/Transforms/Scalar.h"
43 #include "llvm/Transforms/Vectorize.h"
44
45 #define LLVM_VERSION_GE(major, minor)                                          \
46   (LLVM_VERSION_MAJOR > (major) ||                                             \
47    LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
48
49 #define LLVM_VERSION_EQ(major, minor)                                          \
50   (LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
51
52 #define LLVM_VERSION_LE(major, minor)                                          \
53   (LLVM_VERSION_MAJOR < (major) ||                                             \
54    LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
55
56 #define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
57
58 #include "llvm/IR/LegacyPassManager.h"
59
60 #include "llvm/Bitcode/BitcodeReader.h"
61 #include "llvm/Bitcode/BitcodeWriter.h"
62
63 #include "llvm/IR/DIBuilder.h"
64 #include "llvm/IR/DebugInfo.h"
65 #include "llvm/IR/IRPrintingPasses.h"
66 #include "llvm/Linker/Linker.h"
67
68 extern "C" void LLVMRustSetLastError(const char *);
69
70 enum class LLVMRustResult { Success, Failure };
71
72 enum LLVMRustAttribute {
73   AlwaysInline = 0,
74   ByVal = 1,
75   Cold = 2,
76   InlineHint = 3,
77   MinSize = 4,
78   Naked = 5,
79   NoAlias = 6,
80   NoCapture = 7,
81   NoInline = 8,
82   NonNull = 9,
83   NoRedZone = 10,
84   NoReturn = 11,
85   NoUnwind = 12,
86   OptimizeForSize = 13,
87   ReadOnly = 14,
88   SExt = 15,
89   StructRet = 16,
90   UWTable = 17,
91   ZExt = 18,
92   InReg = 19,
93   SanitizeThread = 20,
94   SanitizeAddress = 21,
95   SanitizeMemory = 22,
96   NonLazyBind = 23,
97 };
98
99 typedef struct OpaqueRustString *RustStringRef;
100 typedef struct LLVMOpaqueTwine *LLVMTwineRef;
101 typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
102
103 extern "C" void LLVMRustStringWriteImpl(RustStringRef Str, const char *Ptr,
104                                         size_t Size);
105
106 class RawRustStringOstream : public llvm::raw_ostream {
107   RustStringRef Str;
108   uint64_t Pos;
109
110   void write_impl(const char *Ptr, size_t Size) override {
111     LLVMRustStringWriteImpl(Str, Ptr, Size);
112     Pos += Size;
113   }
114
115   uint64_t current_pos() const override { return Pos; }
116
117 public:
118   explicit RawRustStringOstream(RustStringRef Str) : Str(Str), Pos(0) {}
119
120   ~RawRustStringOstream() {
121     // LLVM requires this.
122     flush();
123   }
124 };