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