|
1 | 1 | use std::fmt;
|
2 | 2 |
|
3 | 3 | use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
4 |
| -use rustc_span::{Span, Symbol, sym}; |
5 | 4 |
|
6 | 5 | #[cfg(test)]
|
7 | 6 | mod tests;
|
@@ -95,14 +94,14 @@ impl Abi {
|
95 | 94 |
|
96 | 95 | #[derive(Copy, Clone)]
|
97 | 96 | pub struct AbiData {
|
98 |
| - abi: Abi, |
| 97 | + pub abi: Abi, |
99 | 98 |
|
100 | 99 | /// Name of this ABI as we like it called.
|
101 |
| - name: &'static str, |
| 100 | + pub name: &'static str, |
102 | 101 | }
|
103 | 102 |
|
104 | 103 | #[allow(non_upper_case_globals)]
|
105 |
| -const AbiDatas: &[AbiData] = &[ |
| 104 | +pub const AbiDatas: &[AbiData] = &[ |
106 | 105 | AbiData { abi: Abi::Rust, name: "Rust" },
|
107 | 106 | AbiData { abi: Abi::C { unwind: false }, name: "C" },
|
108 | 107 | AbiData { abi: Abi::C { unwind: true }, name: "C-unwind" },
|
@@ -142,129 +141,18 @@ const AbiDatas: &[AbiData] = &[
|
142 | 141 | ];
|
143 | 142 |
|
144 | 143 | #[derive(Copy, Clone, Debug)]
|
145 |
| -pub enum AbiUnsupported { |
146 |
| - Unrecognized, |
147 |
| - Reason { explain: &'static str }, |
148 |
| -} |
149 |
| - |
| 144 | +pub struct AbiUnsupported {} |
150 | 145 | /// Returns the ABI with the given name (if any).
|
151 | 146 | pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
|
152 |
| - AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi).ok_or_else(|| match name { |
153 |
| - "riscv-interrupt" => AbiUnsupported::Reason { |
154 |
| - explain: "please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively", |
155 |
| - }, |
156 |
| - "riscv-interrupt-u" => AbiUnsupported::Reason { |
157 |
| - explain: "user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314", |
158 |
| - }, |
159 |
| - "wasm" => AbiUnsupported::Reason { |
160 |
| - explain: "non-standard wasm ABI is no longer supported", |
161 |
| - }, |
162 |
| - |
163 |
| - _ => AbiUnsupported::Unrecognized, |
164 |
| - |
165 |
| - }) |
166 |
| -} |
167 |
| - |
168 |
| -pub fn all_names() -> Vec<&'static str> { |
169 |
| - AbiDatas.iter().map(|d| d.name).collect() |
170 |
| -} |
171 |
| - |
172 |
| -pub fn enabled_names(features: &rustc_feature::Features, span: Span) -> Vec<&'static str> { |
173 | 147 | AbiDatas
|
174 | 148 | .iter()
|
175 |
| - .map(|d| d.name) |
176 |
| - .filter(|name| is_enabled(features, span, name).is_ok()) |
177 |
| - .collect() |
| 149 | + .find(|abi_data| name == abi_data.name) |
| 150 | + .map(|&x| x.abi) |
| 151 | + .ok_or_else(|| AbiUnsupported {}) |
178 | 152 | }
|
179 | 153 |
|
180 |
| -pub enum AbiDisabled { |
181 |
| - Unstable { feature: Symbol, explain: &'static str }, |
182 |
| - Unrecognized, |
183 |
| -} |
184 |
| - |
185 |
| -pub fn is_enabled( |
186 |
| - features: &rustc_feature::Features, |
187 |
| - span: Span, |
188 |
| - name: &str, |
189 |
| -) -> Result<(), AbiDisabled> { |
190 |
| - let s = is_stable(name); |
191 |
| - if let Err(AbiDisabled::Unstable { feature, .. }) = s { |
192 |
| - if features.enabled(feature) || span.allows_unstable(feature) { |
193 |
| - return Ok(()); |
194 |
| - } |
195 |
| - } |
196 |
| - s |
197 |
| -} |
198 |
| - |
199 |
| -/// Returns whether the ABI is stable to use. |
200 |
| -/// |
201 |
| -/// Note that there is a separate check determining whether the ABI is even supported |
202 |
| -/// on the current target; see `fn is_abi_supported` in `rustc_target::spec`. |
203 |
| -pub fn is_stable(name: &str) -> Result<(), AbiDisabled> { |
204 |
| - match name { |
205 |
| - // Stable |
206 |
| - "Rust" | "C" | "C-unwind" | "cdecl" | "cdecl-unwind" | "stdcall" | "stdcall-unwind" |
207 |
| - | "fastcall" | "fastcall-unwind" | "aapcs" | "aapcs-unwind" | "win64" | "win64-unwind" |
208 |
| - | "sysv64" | "sysv64-unwind" | "system" | "system-unwind" | "efiapi" | "thiscall" |
209 |
| - | "thiscall-unwind" => Ok(()), |
210 |
| - "rust-intrinsic" => Err(AbiDisabled::Unstable { |
211 |
| - feature: sym::intrinsics, |
212 |
| - explain: "intrinsics are subject to change", |
213 |
| - }), |
214 |
| - "vectorcall" => Err(AbiDisabled::Unstable { |
215 |
| - feature: sym::abi_vectorcall, |
216 |
| - explain: "vectorcall is experimental and subject to change", |
217 |
| - }), |
218 |
| - "vectorcall-unwind" => Err(AbiDisabled::Unstable { |
219 |
| - feature: sym::abi_vectorcall, |
220 |
| - explain: "vectorcall-unwind ABI is experimental and subject to change", |
221 |
| - }), |
222 |
| - "rust-call" => Err(AbiDisabled::Unstable { |
223 |
| - feature: sym::unboxed_closures, |
224 |
| - explain: "rust-call ABI is subject to change", |
225 |
| - }), |
226 |
| - "rust-cold" => Err(AbiDisabled::Unstable { |
227 |
| - feature: sym::rust_cold_cc, |
228 |
| - explain: "rust-cold is experimental and subject to change", |
229 |
| - }), |
230 |
| - "ptx-kernel" => Err(AbiDisabled::Unstable { |
231 |
| - feature: sym::abi_ptx, |
232 |
| - explain: "PTX ABIs are experimental and subject to change", |
233 |
| - }), |
234 |
| - "unadjusted" => Err(AbiDisabled::Unstable { |
235 |
| - feature: sym::abi_unadjusted, |
236 |
| - explain: "unadjusted ABI is an implementation detail and perma-unstable", |
237 |
| - }), |
238 |
| - "msp430-interrupt" => Err(AbiDisabled::Unstable { |
239 |
| - feature: sym::abi_msp430_interrupt, |
240 |
| - explain: "msp430-interrupt ABI is experimental and subject to change", |
241 |
| - }), |
242 |
| - "x86-interrupt" => Err(AbiDisabled::Unstable { |
243 |
| - feature: sym::abi_x86_interrupt, |
244 |
| - explain: "x86-interrupt ABI is experimental and subject to change", |
245 |
| - }), |
246 |
| - "gpu-kernel" => Err(AbiDisabled::Unstable { |
247 |
| - feature: sym::abi_gpu_kernel, |
248 |
| - explain: "gpu-kernel ABI is experimental and subject to change", |
249 |
| - }), |
250 |
| - "avr-interrupt" | "avr-non-blocking-interrupt" => Err(AbiDisabled::Unstable { |
251 |
| - feature: sym::abi_avr_interrupt, |
252 |
| - explain: "avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change", |
253 |
| - }), |
254 |
| - "riscv-interrupt-m" | "riscv-interrupt-s" => Err(AbiDisabled::Unstable { |
255 |
| - feature: sym::abi_riscv_interrupt, |
256 |
| - explain: "riscv-interrupt ABIs are experimental and subject to change", |
257 |
| - }), |
258 |
| - "C-cmse-nonsecure-call" => Err(AbiDisabled::Unstable { |
259 |
| - feature: sym::abi_c_cmse_nonsecure_call, |
260 |
| - explain: "C-cmse-nonsecure-call ABI is experimental and subject to change", |
261 |
| - }), |
262 |
| - "C-cmse-nonsecure-entry" => Err(AbiDisabled::Unstable { |
263 |
| - feature: sym::cmse_nonsecure_entry, |
264 |
| - explain: "C-cmse-nonsecure-entry ABI is experimental and subject to change", |
265 |
| - }), |
266 |
| - _ => Err(AbiDisabled::Unrecognized), |
267 |
| - } |
| 154 | +pub fn all_names() -> Vec<&'static str> { |
| 155 | + AbiDatas.iter().map(|d| d.name).collect() |
268 | 156 | }
|
269 | 157 |
|
270 | 158 | impl Abi {
|
|
0 commit comments