cloud9_root/src/third_party/stp/src/AST/NodeFactory/SimplifyingNodeFactory.cpp
// This gets called with the arguments swapped as well. So the rules don't need to know about commutivity.
This gets called with the arguments swapped as well. So the rules don't need to know about commutivity.
This gets called with the arguments swapped as well . So the rules don ' t need to know about commutivity .
ASTNode SimplifyingNodeFactory::plusRules(const ASTNode& n0, const ASTNode& n1)
{
  ASTNode result;
  const int width = n0.GetValueWidth();
  if (n0.isConstant() && CONSTANTBV::BitVector_is_empty(n0.GetBVConst()))
    result = n1;
  else if (width == 1 && n0 == n1)
    result = bm.CreateZeroConst(1);
  else if (n0 == n1)
    result = NodeFactory::CreateTerm(BEEV::BVMULT, width, bm.CreateBVConst(string("2"), 10, width), n0);
  else if (n0.GetKind() == BEEV::BVUMINUS  && n1 == n0[0])
    result = bm.CreateZeroConst(width);
  else if (n1.GetKind() == BEEV::BVPLUS && n1[1].GetKind() == BEEV::BVUMINUS && n0 == n1[1][0] && n1.Degree() ==2 )
    result = n1[0];
  else if (n1.GetKind() == BEEV::BVPLUS && n1[0].GetKind() == BEEV::BVUMINUS && n0 == n1[0][0] && n1.Degree() ==2 )
    result = n1[1];
  else if (n1.GetKind() == BEEV::BVUMINUS && n0.GetKind() == BEEV::BVPLUS && n0.Degree() ==2 && n1[0] == n0[1])
    result = n0[0];
  else if (n1.GetKind() == BEEV::BVUMINUS && n0.GetKind() == BEEV::BVPLUS && n0.Degree() ==2 && n1[0] == n0[0])
    result = n0[1];
  else if (n1.GetKind() == BEEV::BVNEG && n1[0] == n0)
    result = bm.CreateMaxConst(width);
  else if (n0.GetKind() == BEEV::BVCONST && n1.GetKind() == BEEV::BVPLUS && n1.Degree() ==2 && n1[0].GetKind() == BEEV::BVCONST)
    {
      ASTVec ch;
      ch.push_back(n0);
      ch.push_back(n1[0]);
      ASTNode constant = NonMemberBVConstEvaluator(&bm , BEEV::BVPLUS, ch, width);
      result = NodeFactory::CreateTerm(BEEV::BVPLUS, width, constant, n1[1]);
    }
    else if (n1.GetKind() == BEEV::BVUMINUS &&  (n0.isConstant() && CONSTANTBV::BitVector_is_full(n0.GetBVConst())))
    {
      result = NodeFactory::CreateTerm(BEEV::BVNEG, width, n1[0]);
    }
    else if (n1.GetKind() == BEEV::BVUMINUS && n0.GetKind() == BEEV::BVUMINUS )
      {
        ASTNode r = NodeFactory::CreateTerm(BEEV::BVPLUS, width, n0[0],n1[0]);
        result = NodeFactory::CreateTerm(BEEV::BVUMINUS, width, r);
      }
  return result;
}
ASTNode SimplifyingNodeFactory :: plusRules ( const ASTNode & n0 , const ASTNode & n1 ) { ASTNode result ; const int width = n0 . GetValueWidth ( ) ; if ( n0 . isConstant ( ) && CONSTANTBV :: BitVector_is_empty ( n0 . GetBVConst ( ) ) ) result = n1 ; else if ( width == 1 && n0 == n1 ) result = bm . CreateZeroConst ( 1 ) ; else if ( n0 == n1 ) result = NodeFactory :: CreateTerm ( BEEV :: BVMULT , width , bm . CreateBVConst ( string ( " " ) , 10 , width ) , n0 ) ; else if ( n0 . GetKind ( ) == BEEV :: BVUMINUS && n1 == n0 [ 0 ] ) result = bm . CreateZeroConst ( width ) ; else if ( n1 . GetKind ( ) == BEEV :: BVPLUS && n1 [ 1 ] . GetKind ( ) == BEEV :: BVUMINUS && n0 == n1 [ 1 ] [ 0 ] && n1 . Degree ( ) == 2 ) result = n1 [ 0 ] ; else if ( n1 . GetKind ( ) == BEEV :: BVPLUS && n1 [ 0 ] . GetKind ( ) == BEEV :: BVUMINUS && n0 == n1 [ 0 ] [ 0 ] && n1 . Degree ( ) == 2 ) result = n1 [ 1 ] ; else if ( n1 . GetKind ( ) == BEEV :: BVUMINUS && n0 . GetKind ( ) == BEEV :: BVPLUS && n0 . Degree ( ) == 2 && n1 [ 0 ] == n0 [ 1 ] ) result = n0 [ 0 ] ; else if ( n1 . GetKind ( ) == BEEV :: BVUMINUS && n0 . GetKind ( ) == BEEV :: BVPLUS && n0 . Degree ( ) == 2 && n1 [ 0 ] == n0 [ 0 ] ) result = n0 [ 1 ] ; else if ( n1 . GetKind ( ) == BEEV :: BVNEG && n1 [ 0 ] == n0 ) result = bm . CreateMaxConst ( width ) ; else if ( n0 . GetKind ( ) == BEEV :: BVCONST && n1 . GetKind ( ) == BEEV :: BVPLUS && n1 . Degree ( ) == 2 && n1 [ 0 ] . GetKind ( ) == BEEV :: BVCONST ) { ASTVec ch ; ch . push_back ( n0 ) ; ch . push_back ( n1 [ 0 ] ) ; ASTNode constant = NonMemberBVConstEvaluator ( & bm , BEEV :: BVPLUS , ch , width ) ; result = NodeFactory :: CreateTerm ( BEEV :: BVPLUS , width , constant , n1 [ 1 ] ) ; } else if ( n1 . GetKind ( ) == BEEV :: BVUMINUS && ( n0 . isConstant ( ) && CONSTANTBV :: BitVector_is_full ( n0 . GetBVConst ( ) ) ) ) { result = NodeFactory :: CreateTerm ( BEEV :: BVNEG , width , n1 [ 0 ] ) ; } else if ( n1 . GetKind ( ) == BEEV :: BVUMINUS && n0 . GetKind ( ) == BEEV :: BVUMINUS ) { ASTNode r = NodeFactory :: CreateTerm ( BEEV :: BVPLUS , width , n0 [ 0 ] , n1 [ 0 ] ) ; result = NodeFactory :: CreateTerm ( BEEV :: BVUMINUS , width , r ) ; } return result ; }
This gets called with the arguments swapped as well.
This gets called with the arguments swapped as well .