#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum ControlFlow {
    Bits0 = 0b00000,
    None = 0b00001,
    Returns = 0b00010,
    Bits3 = 0b00011,
    Throws = 0b00100,
    Bits5 = 0b00101,
    Bits6 = 0b00110,
    Bits7 = 0b00111,
    Breaks = 0b01000,
    Bits9 = 0b01001,
    Bits10 = 0b01010,
    Bits11 = 0b01011,
    Bits12 = 0b01100,
    Bits13 = 0b01101,
    Bits14 = 0b01110,
    Bits15 = 0b01111,
    Continues = 0b10000,
    Bits17 = 0b10001,
    Bits18 = 0b10010,
    Bits19 = 0b10011,
    Bits20 = 0b10100,
    Bits21 = 0b10101,
    Bits22 = 0b10110,
    Bits23 = 0b10111,
    Bits24 = 0b11000,
    Bits25 = 0b11001,
    Bits26 = 0b11010,
    Bits27 = 0b11011,
    Bits28 = 0b11100,
    Bits29 = 0b11101,
    Bits30 = 0b11110,
    Bits31 = 0b11111,
}

impl ControlFlow {
    pub const Zero: Self = Self::Bits0;
    pub const None: Self = Self::None;
    pub const Returns: Self = Self::Returns;
    pub const Throws: Self = Self::Throws;
    pub const Breaks: Self = Self::Breaks;
    pub const Continues: Self = Self::Continues;

    pub fn from_bits(bits: u32) -> Self {
        match bits {
            0 => Self::Bits0,
            1 => Self::None,
            2 => Self::Returns,
            3 => Self::Bits3,
            4 => Self::Throws,
            5 => Self::Bits5,
            6 => Self::Bits6,
            7 => Self::Bits7,
            8 => Self::Breaks,
            9 => Self::Bits9,
            10 => Self::Bits10,
            11 => Self::Bits11,
            12 => Self::Bits12,
            13 => Self::Bits13,
            14 => Self::Bits14,
            15 => Self::Bits15,
            16 => Self::Continues,
            17 => Self::Bits17,
            18 => Self::Bits18,
            19 => Self::Bits19,
            20 => Self::Bits20,
            21 => Self::Bits21,
            22 => Self::Bits22,
            23 => Self::Bits23,
            24 => Self::Bits24,
            25 => Self::Bits25,
            26 => Self::Bits26,
            27 => Self::Bits27,
            28 => Self::Bits28,
            29 => Self::Bits29,
            30 => Self::Bits30,
            31 => Self::Bits31,
            _ => panic!("invalid ControlFlow bits {bits:#x}"),
        }
    }
}
