33// author: Kevin Laeufer <laeufer@cornell.edu>
44
55use baa:: { BitVecOps , BitVecValue , BitVecValueRef } ;
6- use patronus:: expr:: {
7- Context , DenseExprMetaData , Expr , ExprRef , ForEachChild , SerializableIrNode , Simplifier ,
8- TypeCheck , WidthInt , count_expr_uses, traversal,
9- } ;
6+ use patronus:: expr:: * ;
107use polysub:: { Coef , Term , VarIndex } ;
11- use std:: collections:: VecDeque ;
128use std:: fmt:: { Display , Formatter } ;
139
1410/// Returns a new expressions reference if simplification was possible
@@ -50,6 +46,8 @@ pub fn simplify_word_level_equality(ctx: &mut Context, p: ScaEqualityProblem) ->
5046 }
5147}
5248
49+ /// Extracts a bit from a concatenation. We use this to avoid having to call the full blown
50+ /// simplifier.
5351fn extract_bit ( ctx : & mut Context , e : ExprRef , bit : WidthInt ) -> ExprRef {
5452 match ctx[ e] . clone ( ) {
5553 Expr :: BVConcat ( a, b, _) => {
@@ -90,7 +88,7 @@ fn is_gate(expr: &Expr) -> bool {
9088 )
9189}
9290
93- fn backwards_sub ( ctx : & Context , mut todo : VecDeque < ( VarIndex , ExprRef ) > , mut spec : Poly ) -> Poly {
91+ fn backwards_sub ( ctx : & Context , mut todo : Vec < ( VarIndex , ExprRef ) > , mut spec : Poly ) -> Poly {
9492 let mut var_roots: Vec < _ > = todo. iter ( ) . map ( |( v, _) | * v) . collect ( ) ;
9593 var_roots. sort ( ) ;
9694
@@ -103,7 +101,7 @@ fn backwards_sub(ctx: &Context, mut todo: VecDeque<(VarIndex, ExprRef)>, mut spe
103101 let mut uses = count_expr_uses ( ctx, roots) ;
104102 let mut replaced = vec ! [ ] ;
105103
106- while let Some ( ( output_var, gate) ) = todo. pop_back ( ) {
104+ while let Some ( ( output_var, gate) ) = todo. pop ( ) {
107105 replaced. push ( output_var) ;
108106
109107 let add_children = match ctx[ gate] . clone ( ) {
@@ -168,7 +166,7 @@ fn backwards_sub(ctx: &Context, mut todo: VecDeque<(VarIndex, ExprRef)>, mut spe
168166 uses[ e] = prev_uses - 1 ;
169167 // did the use count just go down to zero?
170168 if prev_uses == 1 && is_gate ( & ctx[ e] ) {
171- todo. push_front ( ( expr_to_var ( e) , e) ) ;
169+ todo. push ( ( expr_to_var ( e) , e) ) ;
172170 }
173171 } ) ;
174172 }
0 commit comments