Skip to main content

luaur_code_gen/records/
ir_inst_eq.rs

1use crate::enums::ir_op_kind::IrOpKind;
2use crate::records::ir_inst::IrInst;
3
4#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
5#[repr(C)]
6pub struct IrInstEq;
7
8impl IrInstEq {
9    #[inline]
10    pub fn ir_inst_eq_operator_call(&self, a: &IrInst, b: &IrInst) -> bool {
11        if a.cmd != b.cmd {
12            return false;
13        }
14
15        let a_size = a.ops.size() as usize;
16        let b_size = b.ops.size() as usize;
17
18        if a_size == b_size {
19            for i in 0..a_size {
20                if !a.ops[i].ir_op_operator_eq(b.ops[i]) {
21                    return false;
22                }
23            }
24        } else if a_size < b_size {
25            let mut i: usize = 0;
26            while i < a_size {
27                if !a.ops[i].ir_op_operator_eq(b.ops[i]) {
28                    return false;
29                }
30                i += 1;
31            }
32            while i < b_size {
33                if b.ops[i].kind() != IrOpKind::None {
34                    return false;
35                }
36                i += 1;
37            }
38        } else {
39            let mut i: usize = 0;
40            while i < b_size {
41                if !a.ops[i].ir_op_operator_eq(b.ops[i]) {
42                    return false;
43                }
44                i += 1;
45            }
46            while i < a_size {
47                if a.ops[i].kind() != IrOpKind::None {
48                    return false;
49                }
50                i += 1;
51            }
52        }
53
54        true
55    }
56}
57
58impl luaur_common::records::dense_hash_table::DenseEq<crate::records::ir_inst::IrInst>
59    for IrInstEq
60{
61    fn eq(&self, a: &crate::records::ir_inst::IrInst, b: &crate::records::ir_inst::IrInst) -> bool {
62        self.ir_inst_eq_operator_call(a, b)
63    }
64}