cloud9_root/src/third_party/stp/src/simplifier/simplifier.cpp
//accepts lhs and rhs, and returns lhs - rhs = 0. The function
//assumes that lhs and rhs have already been simplified. although
//this assumption is not needed for correctness, it is essential for
//performance. The function also assumes that lhs is a BVPLUS
accepts lhs and rhs, and returns lhs - rhs = 0. The function
assumes that lhs and rhs have already been simplified. although
this assumption is not needed for correctness, it is essential for
performance. The function also assumes that lhs is a BVPLUS
accepts lhs and rhs and returns lhs - rhs = 0 . The function assumes that lhs and rhs have already been simplified . although this assumption is not needed for correctness it is essential for performance . The function also assumes that lhs is a BVPLUS
ASTNode
  Simplifier::LhsMinusRhs(const ASTNode& eq)
  {
    if (EQ != eq.GetKind())
      return eq;
    ASTNode lhs = eq[0];
    ASTNode rhs = eq[1];
    const Kind k_lhs = lhs.GetKind();
    const Kind k_rhs = rhs.GetKind();
    if (!(BVPLUS == k_lhs || BVPLUS == k_rhs || (BVMULT == k_lhs && BVMULT == k_rhs)))
      {
        return eq;
      }
    ASTNode output;
    if (CheckSimplifyMap(eq, output, false))
      {
        return output;
      }
    if (BVPLUS != k_lhs && BVPLUS == k_rhs)
      {
        ASTNode swap = lhs;
        lhs = rhs;
        rhs = swap;
      }
    unsigned int len = lhs.GetValueWidth();
    ASTNode zero = _bm->CreateZeroConst(len);
    rhs = SimplifyTerm(nf->CreateTerm(BVUMINUS, len, rhs));
    ASTVec lvec = lhs.GetChildren();
    ASTVec rvec = rhs.GetChildren();
    ASTNode lhsplusrhs;
    if (BVPLUS != lhs.GetKind() && BVPLUS != rhs.GetKind())
      {
        lhsplusrhs = nf->CreateTerm(BVPLUS, len, lhs, rhs);
      }
    else if (BVPLUS == lhs.GetKind() && BVPLUS == rhs.GetKind())
      {
        lvec.insert(lvec.end(), rvec.begin(), rvec.end());
        lhsplusrhs = nf->CreateTerm(BVPLUS, len, lvec);
      }
    else if (BVPLUS == lhs.GetKind() && BVPLUS != rhs.GetKind())
      {
        lvec.push_back(rhs);
        lhsplusrhs = nf->CreateTerm(BVPLUS, len, lvec);
      }
    else
      {
        lhsplusrhs = nf->CreateTerm(BVPLUS, len, lhs, rhs);
      }
    output = CombineLikeTerms(lhsplusrhs);
    output = SimplifyTerm(output);
    Now make output into: lhs-rhs = 0
    output = CreateSimplifiedEQ(output, zero);
    sort if BVPLUS
    if (BVPLUS == output.GetKind())
      {
        ASTVec outv = output.GetChildren();
        SortByArith(outv);
        output = nf->CreateTerm(BVPLUS, len, outv);
      }
    memoize
    UpdateSimplifyMap(eq,output,false);
    return output;
  }
ASTNode Simplifier :: LhsMinusRhs ( const ASTNode & eq ) { if ( EQ != eq . GetKind ( ) ) return eq ; ASTNode lhs = eq [ 0 ] ; ASTNode rhs = eq [ 1 ] ; const Kind k_lhs = lhs . GetKind ( ) ; const Kind k_rhs = rhs . GetKind ( ) ; if ( ! ( BVPLUS == k_lhs || BVPLUS == k_rhs || ( BVMULT == k_lhs && BVMULT == k_rhs ) ) ) { return eq ; } ASTNode output ; if ( CheckSimplifyMap ( eq , output , false ) ) { return output ; } if ( BVPLUS != k_lhs && BVPLUS == k_rhs ) { ASTNode swap = lhs ; lhs = rhs ; rhs = swap ; } unsigned int len = lhs . GetValueWidth ( ) ; ASTNode zero = _bm -> CreateZeroConst ( len ) ; rhs = SimplifyTerm ( nf -> CreateTerm ( BVUMINUS , len , rhs ) ) ; ASTVec lvec = lhs . GetChildren ( ) ; ASTVec rvec = rhs . GetChildren ( ) ; ASTNode lhsplusrhs ; if ( BVPLUS != lhs . GetKind ( ) && BVPLUS != rhs . GetKind ( ) ) { lhsplusrhs = nf -> CreateTerm ( BVPLUS , len , lhs , rhs ) ; } else if ( BVPLUS == lhs . GetKind ( ) && BVPLUS == rhs . GetKind ( ) ) { lvec . insert ( lvec . end ( ) , rvec . begin ( ) , rvec . end ( ) ) ; lhsplusrhs = nf -> CreateTerm ( BVPLUS , len , lvec ) ; } else if ( BVPLUS == lhs . GetKind ( ) && BVPLUS != rhs . GetKind ( ) ) { lvec . push_back ( rhs ) ; lhsplusrhs = nf -> CreateTerm ( BVPLUS , len , lvec ) ; } else { lhsplusrhs = nf -> CreateTerm ( BVPLUS , len , lhs , rhs ) ; } output = CombineLikeTerms ( lhsplusrhs ) ; output = SimplifyTerm ( output ) ; output = CreateSimplifiedEQ ( output , zero ) ; if ( BVPLUS == output . GetKind ( ) ) { ASTVec outv = output . GetChildren ( ) ; SortByArith ( outv ) ; output = nf -> CreateTerm ( BVPLUS , len , outv ) ; } return output ; }
accepts lhs and rhs, and returns lhs - rhs = 0.
accepts lhs and rhs and returns lhs - rhs = 0 .
//if input is not an equality, simply return it //either the lhs has to be a BVPLUS or the rhs has to be a //BVPLUS //check memo table //cerr << "output of SimplifyTerm Cache: " << output << endl; //if the lhs is not a BVPLUS, but the rhs is a BVPLUS, then swap //the lhs and rhs //bool swap_flag = false; // swap_flag = true; //right is -1*(rhs): Simplify(-1*rhs) //combine the childnodes of the left and the right //combine like terms // //Now make output into: lhs-rhs = 0 //sort if BVPLUS //memoize //UpdateSimplifyMap(eq,output,false);