nearly done writing code that generates fuzzing input for reg alloc
[bigint-presentation-code.git] / register_allocator / src / function.rs
index 28ff917cb4a17c9a16e3e9acd97b26270db70777..4577581931d7198f18140e0a91f7f4e8a02781c2 100644 (file)
@@ -5,6 +5,7 @@ use crate::{
     loc::{BaseTy, Loc, Ty},
     loc_set::LocSet,
 };
+use arbitrary::Arbitrary;
 use core::fmt;
 use hashbrown::HashSet;
 use petgraph::{
@@ -28,15 +29,15 @@ pub enum SSAValDef {
 
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Serialize, Deserialize)]
 pub struct BranchSuccParamUse {
-    branch_inst: InstIdx,
-    succ: BlockIdx,
-    param_idx: usize,
+    pub branch_inst: InstIdx,
+    pub succ: BlockIdx,
+    pub param_idx: usize,
 }
 
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Serialize, Deserialize)]
 pub struct OperandUse {
-    inst: InstIdx,
-    operand_idx: usize,
+    pub inst: InstIdx,
+    pub operand_idx: usize,
 }
 
 #[derive(Clone, PartialEq, Eq, Debug, Hash, Serialize, Deserialize)]
@@ -106,7 +107,9 @@ impl SSAVal {
     }
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Serialize, Deserialize)]
+#[derive(
+    Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Serialize, Deserialize, Arbitrary,
+)]
 #[repr(u8)]
 pub enum InstStage {
     Early = 0,
@@ -177,7 +180,9 @@ impl TryFrom<SerializedProgPoint> for ProgPoint {
     }
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Serialize, Deserialize)]
+#[derive(
+    Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Serialize, Deserialize, Arbitrary,
+)]
 #[repr(u8)]
 pub enum OperandKind {
     Use = 0,
@@ -353,6 +358,23 @@ impl Operand {
                 }
             }
         }
+        if let KindAndConstraint::Reuse {
+            kind: _,
+            reuse_operand_idx,
+        } = self.kind_and_constraint
+        {
+            let reuse_src = func.try_get_operand(inst, reuse_operand_idx)?;
+            let reuse_src_ssa_val = func.try_get_ssa_val(reuse_src.ssa_val)?;
+            if ssa_val.ty != reuse_src_ssa_val.ty {
+                return Err(Error::ReuseOperandTyMismatch {
+                    inst,
+                    tgt_operand_idx: operand_idx,
+                    src_operand_idx: reuse_operand_idx,
+                    src_ty: reuse_src_ssa_val.ty,
+                    tgt_ty: ssa_val.ty,
+                });
+            }
+        }
         let constraint = self.try_constraint(inst, func)?;
         match constraint {
             Constraint::Any | Constraint::Stack => {}