/*******************************************************************\

Module:

Author: Daniel Kroening, kroening@cs.cmu.edu

\*******************************************************************/

#include "boolbv.h"

/*******************************************************************\

Function: boolbvt::convert_shift

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

bool boolbvt::convert_shift(const exprt &expr, bvt &bv)
{
  if(expr.type().id()!="unsignedbv" &&
     expr.type().id()!="signedbv")
    return true;

  unsigned width;

  get_width(expr.type(), width);

  if(width==0)
    throw "zero length bit vector type: "+expr.type().to_string();

  if(expr.operands().size()!=2)
    throw "shifting takes two operands";

  bvt dist;

  if(convert_bv(expr.op0(), bv)) return true;
  if(convert_bv(expr.op1(), dist)) return true;

  if(bv.size()!=width)
    throw "convert_shift: unexpected operand width";

  bv_utilst::shiftt shift;

  if(expr.id()=="shl")
    shift=bv_utilst::LEFT;
  else if(expr.id()=="ashr")
    shift=bv_utilst::ARIGHT;
  else if(expr.id()=="lshr")
    shift=bv_utilst::LRIGHT;
  else
    throw "unexpected operand";

  bv_utils.shifter(shift, bv, dist);

  return false;
}
