zk_evm/
flags.rs

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
48
49
50
51
52
53
54
55
56
use std::fmt::{Debug, Formatter};

#[derive(Clone, Copy, PartialEq)]
pub struct Flags {
    pub overflow_or_less_than_flag: bool,
    pub equality_flag: bool,
    pub greater_than_flag: bool,
}

impl Flags {
    pub const fn empty() -> Self {
        Self {
            overflow_or_less_than_flag: false,
            equality_flag: false,
            greater_than_flag: false,
        }
    }
    pub fn reset(&mut self) {
        self.overflow_or_less_than_flag = false;
        self.equality_flag = false;
        self.greater_than_flag = false;
    }

    pub fn get_set_flags_captions(&self) -> Vec<String> {
        let mut res: Vec<String> = vec![];
        if self.overflow_or_less_than_flag {
            res.push(String::from("lt"))
        }
        if self.equality_flag {
            res.push(String::from("eq"))
        }
        if self.greater_than_flag {
            res.push(String::from("gt"))
        }
        res
    }
}

impl Debug for Flags {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        fn bool_to_sym(b: bool) -> &'static str {
            if b {
                "+"
            } else {
                "-"
            }
        }
        write!(
            f,
            "lt{} eq{} gt{}",
            bool_to_sym(self.overflow_or_less_than_flag),
            bool_to_sym(self.equality_flag),
            bool_to_sym(self.greater_than_flag)
        )
    }
}