machine_check_common/iir/
ty.rs1use std::fmt::Debug;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6 iir::description::IStructId,
7 ir_common::{IrReference, IrTypeArray},
8};
9
10#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
11pub enum IElementaryType {
12 Bitvector(u32),
13 Array(IrTypeArray),
14 Boolean,
15 Struct(IStructId),
16}
17
18#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
19pub struct IType {
20 pub reference: IrReference,
21 pub inner: IElementaryType,
22}
23
24#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
25pub enum IGeneralType {
26 Normal(IType),
27 PanicResult(IType),
28 PhiArg(IType),
29}
30
31impl Debug for IElementaryType {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 Self::Bitvector(width) => write!(f, "::mck::Bitvector<{}>", width),
35 Self::Array(array) => write!(
36 f,
37 "::mck::Array<{}, {}>",
38 array.index_width, array.element_width
39 ),
40 Self::Boolean => write!(f, "Boolean"),
41 Self::Struct(struct_id) => struct_id.fmt(f),
42 }
43 }
44}
45
46impl Debug for IType {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 match self.reference {
49 IrReference::Immutable => f.write_str("&")?,
50 IrReference::None => {}
51 }
52 self.inner.fmt(f)
53 }
54}
55
56impl Debug for IGeneralType {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 match self {
59 Self::Normal(inner) => write!(f, "{:?}", inner),
60 Self::PanicResult(inner) => write!(f, "::mck::PanicResult<{:?}>", inner),
61 Self::PhiArg(inner) => write!(f, "::mck::PanicResult<{:?}>", inner),
62 }
63 }
64}