|
1 | | -mod abi { |
2 | | - pub(crate) use crate::Primitive::*; |
3 | | - pub(crate) use crate::Variants; |
4 | | -} |
5 | | - |
6 | | -#[cfg(feature = "nightly")] |
7 | | -use rustc_macros::HashStable_Generic; |
8 | | - |
9 | | -use crate::{Align, HasDataLayout, Size}; |
10 | 1 | #[cfg(feature = "nightly")] |
11 | 2 | use crate::{BackendRepr, FieldsShape, TyAbiInterface, TyAndLayout}; |
| 3 | +use crate::{Primitive, Size, Variants}; |
12 | 4 |
|
13 | | -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] |
14 | | -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
15 | | -pub enum RegKind { |
16 | | - Integer, |
17 | | - Float, |
18 | | - Vector, |
19 | | -} |
20 | | - |
21 | | -#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] |
22 | | -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
23 | | -pub struct Reg { |
24 | | - pub kind: RegKind, |
25 | | - pub size: Size, |
26 | | -} |
27 | | - |
28 | | -macro_rules! reg_ctor { |
29 | | - ($name:ident, $kind:ident, $bits:expr) => { |
30 | | - pub fn $name() -> Reg { |
31 | | - Reg { kind: RegKind::$kind, size: Size::from_bits($bits) } |
32 | | - } |
33 | | - }; |
34 | | -} |
35 | | - |
36 | | -impl Reg { |
37 | | - reg_ctor!(i8, Integer, 8); |
38 | | - reg_ctor!(i16, Integer, 16); |
39 | | - reg_ctor!(i32, Integer, 32); |
40 | | - reg_ctor!(i64, Integer, 64); |
41 | | - reg_ctor!(i128, Integer, 128); |
42 | | - |
43 | | - reg_ctor!(f32, Float, 32); |
44 | | - reg_ctor!(f64, Float, 64); |
45 | | -} |
| 5 | +mod reg; |
46 | 6 |
|
47 | | -impl Reg { |
48 | | - pub fn align<C: HasDataLayout>(&self, cx: &C) -> Align { |
49 | | - let dl = cx.data_layout(); |
50 | | - match self.kind { |
51 | | - RegKind::Integer => match self.size.bits() { |
52 | | - 1 => dl.i1_align.abi, |
53 | | - 2..=8 => dl.i8_align.abi, |
54 | | - 9..=16 => dl.i16_align.abi, |
55 | | - 17..=32 => dl.i32_align.abi, |
56 | | - 33..=64 => dl.i64_align.abi, |
57 | | - 65..=128 => dl.i128_align.abi, |
58 | | - _ => panic!("unsupported integer: {self:?}"), |
59 | | - }, |
60 | | - RegKind::Float => match self.size.bits() { |
61 | | - 16 => dl.f16_align.abi, |
62 | | - 32 => dl.f32_align.abi, |
63 | | - 64 => dl.f64_align.abi, |
64 | | - 128 => dl.f128_align.abi, |
65 | | - _ => panic!("unsupported float: {self:?}"), |
66 | | - }, |
67 | | - RegKind::Vector => dl.vector_align(self.size).abi, |
68 | | - } |
69 | | - } |
70 | | -} |
| 7 | +pub use reg::{Reg, RegKind}; |
71 | 8 |
|
72 | 9 | /// Return value from the `homogeneous_aggregate` test function. |
73 | 10 | #[derive(Copy, Clone, Debug)] |
@@ -134,8 +71,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { |
134 | 71 | // The primitive for this algorithm. |
135 | 72 | BackendRepr::Scalar(scalar) => { |
136 | 73 | let kind = match scalar.primitive() { |
137 | | - abi::Int(..) | abi::Pointer(_) => RegKind::Integer, |
138 | | - abi::Float(_) => RegKind::Float, |
| 74 | + Primitive::Int(..) | Primitive::Pointer(_) => RegKind::Integer, |
| 75 | + Primitive::Float(_) => RegKind::Float, |
139 | 76 | }; |
140 | 77 | Ok(HomogeneousAggregate::Homogeneous(Reg { kind, size: self.size })) |
141 | 78 | } |
@@ -206,8 +143,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { |
206 | 143 | let (mut result, mut total) = from_fields_at(*self, Size::ZERO)?; |
207 | 144 |
|
208 | 145 | match &self.variants { |
209 | | - abi::Variants::Single { .. } | abi::Variants::Empty => {} |
210 | | - abi::Variants::Multiple { variants, .. } => { |
| 146 | + Variants::Single { .. } | Variants::Empty => {} |
| 147 | + Variants::Multiple { variants, .. } => { |
211 | 148 | // Treat enum variants like union members. |
212 | 149 | // HACK(eddyb) pretend the `enum` field (discriminant) |
213 | 150 | // is at the start of every variant (otherwise the gap |
|
0 commit comments