1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::primitives::IntTy;
use crate::{FloatBitness, FloatTy, IntBitness};
use mun_target::abi;
use mun_target::abi::TargetDataLayout;

pub trait ResolveBitness {
    /// Resolves any variable bitness into concrete values.
    fn resolve(&self, target: &abi::TargetDataLayout) -> Self;
}

impl ResolveBitness for IntBitness {
    fn resolve(&self, data_layout: &abi::TargetDataLayout) -> IntBitness {
        match self {
            IntBitness::Xsize => data_layout.ptr_sized_integer().into(),
            IntBitness::X8
            | IntBitness::X16
            | IntBitness::X32
            | IntBitness::X64
            | IntBitness::X128 => *self,
        }
    }
}

impl ResolveBitness for FloatBitness {
    fn resolve(&self, _data_layout: &abi::TargetDataLayout) -> FloatBitness {
        match self {
            FloatBitness::X32 | FloatBitness::X64 => *self,
        }
    }
}

impl ResolveBitness for IntTy {
    fn resolve(&self, target: &TargetDataLayout) -> Self {
        IntTy {
            bitness: self.bitness.resolve(target),
            signedness: self.signedness,
        }
    }
}

impl ResolveBitness for FloatTy {
    fn resolve(&self, target: &TargetDataLayout) -> Self {
        FloatTy {
            bitness: self.bitness.resolve(target),
        }
    }
}