]>
Commit | Line | Data |
---|---|---|
0bf4aa26 | 1 | #![feature(nll)] |
b7449926 | 2 | #![feature(static_nobundle)] |
1b1a35ee | 3 | #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] |
1a4d82fc | 4 | |
b7449926 | 5 | // NOTE: This crate only exists to allow linking on mingw targets. |
1a4d82fc | 6 | |
dfeec247 | 7 | use libc::{c_char, size_t}; |
60c5eb7d XL |
8 | use std::cell::RefCell; |
9 | use std::slice; | |
60c5eb7d XL |
10 | |
11 | #[repr(C)] | |
12 | pub struct RustString { | |
13 | pub bytes: RefCell<Vec<u8>>, | |
14 | } | |
15 | ||
3dfed10e XL |
16 | impl RustString { |
17 | pub fn len(&self) -> usize { | |
18 | self.bytes.borrow().len() | |
19 | } | |
c295e0f8 XL |
20 | |
21 | pub fn is_empty(&self) -> bool { | |
22 | self.bytes.borrow().is_empty() | |
23 | } | |
3dfed10e XL |
24 | } |
25 | ||
60c5eb7d XL |
26 | /// Appending to a Rust string -- used by RawRustStringOstream. |
27 | #[no_mangle] | |
dfeec247 XL |
28 | pub unsafe extern "C" fn LLVMRustStringWriteImpl( |
29 | sr: &RustString, | |
30 | ptr: *const c_char, | |
31 | size: size_t, | |
32 | ) { | |
60c5eb7d XL |
33 | let slice = slice::from_raw_parts(ptr as *const u8, size as usize); |
34 | ||
35 | sr.bytes.borrow_mut().extend_from_slice(slice); | |
36 | } | |
37 | ||
b7449926 | 38 | /// Initialize targets enabled by the build script via `cfg(llvm_component = "...")`. |
0731742a | 39 | /// N.B., this function can't be moved to `rustc_codegen_llvm` because of the `cfg`s. |
9cc50fc6 SL |
40 | pub fn initialize_available_targets() { |
41 | macro_rules! init_target( | |
7453a54e | 42 | ($cfg:meta, $($method:ident),*) => { { |
9cc50fc6 SL |
43 | #[cfg($cfg)] |
44 | fn init() { | |
5869c6ff | 45 | extern "C" { |
7453a54e SL |
46 | $(fn $method();)* |
47 | } | |
9cc50fc6 | 48 | unsafe { |
7453a54e | 49 | $($method();)* |
9cc50fc6 SL |
50 | } |
51 | } | |
52 | #[cfg(not($cfg))] | |
53 | fn init() { } | |
54 | init(); | |
55 | } } | |
56 | ); | |
dfeec247 XL |
57 | init_target!( |
58 | llvm_component = "x86", | |
59 | LLVMInitializeX86TargetInfo, | |
60 | LLVMInitializeX86Target, | |
61 | LLVMInitializeX86TargetMC, | |
62 | LLVMInitializeX86AsmPrinter, | |
63 | LLVMInitializeX86AsmParser | |
64 | ); | |
65 | init_target!( | |
66 | llvm_component = "arm", | |
67 | LLVMInitializeARMTargetInfo, | |
68 | LLVMInitializeARMTarget, | |
69 | LLVMInitializeARMTargetMC, | |
70 | LLVMInitializeARMAsmPrinter, | |
71 | LLVMInitializeARMAsmParser | |
72 | ); | |
73 | init_target!( | |
74 | llvm_component = "aarch64", | |
75 | LLVMInitializeAArch64TargetInfo, | |
76 | LLVMInitializeAArch64Target, | |
77 | LLVMInitializeAArch64TargetMC, | |
78 | LLVMInitializeAArch64AsmPrinter, | |
79 | LLVMInitializeAArch64AsmParser | |
80 | ); | |
81 | init_target!( | |
82 | llvm_component = "amdgpu", | |
83 | LLVMInitializeAMDGPUTargetInfo, | |
84 | LLVMInitializeAMDGPUTarget, | |
85 | LLVMInitializeAMDGPUTargetMC, | |
86 | LLVMInitializeAMDGPUAsmPrinter, | |
87 | LLVMInitializeAMDGPUAsmParser | |
88 | ); | |
f035d41b XL |
89 | init_target!( |
90 | llvm_component = "avr", | |
91 | LLVMInitializeAVRTargetInfo, | |
92 | LLVMInitializeAVRTarget, | |
93 | LLVMInitializeAVRTargetMC, | |
94 | LLVMInitializeAVRAsmPrinter, | |
95 | LLVMInitializeAVRAsmParser | |
96 | ); | |
c295e0f8 XL |
97 | init_target!( |
98 | llvm_component = "m68k", | |
99 | LLVMInitializeM68kTargetInfo, | |
100 | LLVMInitializeM68kTarget, | |
101 | LLVMInitializeM68kTargetMC, | |
102 | LLVMInitializeM68kAsmPrinter, | |
103 | LLVMInitializeM68kAsmParser | |
104 | ); | |
dfeec247 XL |
105 | init_target!( |
106 | llvm_component = "mips", | |
107 | LLVMInitializeMipsTargetInfo, | |
108 | LLVMInitializeMipsTarget, | |
109 | LLVMInitializeMipsTargetMC, | |
110 | LLVMInitializeMipsAsmPrinter, | |
111 | LLVMInitializeMipsAsmParser | |
112 | ); | |
113 | init_target!( | |
114 | llvm_component = "powerpc", | |
115 | LLVMInitializePowerPCTargetInfo, | |
116 | LLVMInitializePowerPCTarget, | |
117 | LLVMInitializePowerPCTargetMC, | |
118 | LLVMInitializePowerPCAsmPrinter, | |
119 | LLVMInitializePowerPCAsmParser | |
120 | ); | |
121 | init_target!( | |
122 | llvm_component = "systemz", | |
123 | LLVMInitializeSystemZTargetInfo, | |
124 | LLVMInitializeSystemZTarget, | |
125 | LLVMInitializeSystemZTargetMC, | |
126 | LLVMInitializeSystemZAsmPrinter, | |
127 | LLVMInitializeSystemZAsmParser | |
128 | ); | |
129 | init_target!( | |
130 | llvm_component = "jsbackend", | |
131 | LLVMInitializeJSBackendTargetInfo, | |
132 | LLVMInitializeJSBackendTarget, | |
133 | LLVMInitializeJSBackendTargetMC | |
134 | ); | |
135 | init_target!( | |
136 | llvm_component = "msp430", | |
137 | LLVMInitializeMSP430TargetInfo, | |
138 | LLVMInitializeMSP430Target, | |
139 | LLVMInitializeMSP430TargetMC, | |
cdc7bbd5 | 140 | LLVMInitializeMSP430AsmPrinter, |
dfeec247 XL |
141 | LLVMInitializeMSP430AsmParser |
142 | ); | |
143 | init_target!( | |
144 | llvm_component = "riscv", | |
145 | LLVMInitializeRISCVTargetInfo, | |
146 | LLVMInitializeRISCVTarget, | |
147 | LLVMInitializeRISCVTargetMC, | |
148 | LLVMInitializeRISCVAsmPrinter, | |
149 | LLVMInitializeRISCVAsmParser | |
150 | ); | |
151 | init_target!( | |
152 | llvm_component = "sparc", | |
153 | LLVMInitializeSparcTargetInfo, | |
154 | LLVMInitializeSparcTarget, | |
155 | LLVMInitializeSparcTargetMC, | |
156 | LLVMInitializeSparcAsmPrinter, | |
157 | LLVMInitializeSparcAsmParser | |
158 | ); | |
159 | init_target!( | |
160 | llvm_component = "nvptx", | |
161 | LLVMInitializeNVPTXTargetInfo, | |
162 | LLVMInitializeNVPTXTarget, | |
163 | LLVMInitializeNVPTXTargetMC, | |
164 | LLVMInitializeNVPTXAsmPrinter | |
165 | ); | |
166 | init_target!( | |
167 | llvm_component = "hexagon", | |
168 | LLVMInitializeHexagonTargetInfo, | |
169 | LLVMInitializeHexagonTarget, | |
170 | LLVMInitializeHexagonTargetMC, | |
171 | LLVMInitializeHexagonAsmPrinter, | |
172 | LLVMInitializeHexagonAsmParser | |
173 | ); | |
174 | init_target!( | |
175 | llvm_component = "webassembly", | |
176 | LLVMInitializeWebAssemblyTargetInfo, | |
177 | LLVMInitializeWebAssemblyTarget, | |
178 | LLVMInitializeWebAssemblyTargetMC, | |
fc512014 XL |
179 | LLVMInitializeWebAssemblyAsmPrinter, |
180 | LLVMInitializeWebAssemblyAsmParser | |
dfeec247 | 181 | ); |
17df50a5 XL |
182 | init_target!( |
183 | llvm_component = "bpf", | |
184 | LLVMInitializeBPFTargetInfo, | |
185 | LLVMInitializeBPFTarget, | |
186 | LLVMInitializeBPFTargetMC, | |
187 | LLVMInitializeBPFAsmPrinter, | |
188 | LLVMInitializeBPFAsmParser | |
189 | ); | |
7453a54e | 190 | } |