当前位置: 首页>>代码示例>>C++>>正文


C++ ASTNode::GetValueWidth方法代码示例

本文整理汇总了C++中ASTNode::GetValueWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::GetValueWidth方法的具体用法?C++ ASTNode::GetValueWidth怎么用?C++ ASTNode::GetValueWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ASTNode的用法示例。


在下文中一共展示了ASTNode::GetValueWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BVConstEvaluator

  ASTNode BeevMgr::BVConstEvaluator(const ASTNode& t) {
    ASTNode OutputNode;
    Kind k = t.GetKind();

    if(CheckSolverMap(t,OutputNode))
      return OutputNode;
    OutputNode = t;

    unsigned int inputwidth = t.GetValueWidth();
    unsigned int outputwidth = inputwidth;
    CBV output = NULL;

    CBV tmp0 = NULL;
    CBV tmp1 = NULL;

    //saving some typing. BVPLUS does not use these variables. if the
    //input BVPLUS has two nodes, then we want to avoid setting these
    //variables.
    if(1 == t.Degree() ){
      tmp0 = BVConstEvaluator(t[0]).GetBVConst();
    }else if(2 == t.Degree() && k != BVPLUS ) {
      tmp0 = BVConstEvaluator(t[0]).GetBVConst();
      tmp1 = BVConstEvaluator(t[1]).GetBVConst();
    }

    switch(k) {
    case UNDEFINED:
    case READ:
    case WRITE:
    case SYMBOL:
      FatalError("BVConstEvaluator: term is not a constant-term",t);
      break;
    case BVCONST:
      //FIXME Handle this special case better
      OutputNode = t;
      break;
    case BVNEG:{
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      CONSTANTBV::Set_Complement(output,tmp0);
      OutputNode = CreateBVConst(output,outputwidth);
      break;
    }
    case BVSX: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      //unsigned * out0 = BVConstEvaluator(t[0]).GetBVConst();
      unsigned t0_width = t[0].GetValueWidth();
      if(inputwidth == t0_width) {
        CONSTANTBV::BitVector_Copy(output, tmp0);
        OutputNode = CreateBVConst(output, outputwidth);    
      }
      else {
        bool topbit_sign = (CONSTANTBV::BitVector_Sign(tmp0) < 0 );

        if(topbit_sign){
          CONSTANTBV::BitVector_Fill(output);
        }
        CONSTANTBV::BitVector_Interval_Copy(output, tmp0, 0, 0, t0_width);
        OutputNode = CreateBVConst(output, outputwidth);    
      }
      break;
    }
    case BVAND: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      CONSTANTBV::Set_Intersection(output,tmp0,tmp1);
      OutputNode = CreateBVConst(output, outputwidth);
      break;
    }
    case BVOR: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      CONSTANTBV::Set_Union(output,tmp0,tmp1);
      OutputNode = CreateBVConst(output, outputwidth);
      break;
    }
    case BVXOR: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      CONSTANTBV::Set_ExclusiveOr(output,tmp0,tmp1);
      OutputNode = CreateBVConst(output, outputwidth);
      break;
    }
    case BVSUB: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      bool carry = false;
      CONSTANTBV::BitVector_sub(output,tmp0,tmp1,&carry);
      OutputNode = CreateBVConst(output, outputwidth);    
      break;
    }
    case BVUMINUS: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      CONSTANTBV::BitVector_Negate(output, tmp0);
      OutputNode = CreateBVConst(output, outputwidth);    
      break;
    }
    case BVEXTRACT: {
      output = CONSTANTBV::BitVector_Create(inputwidth,true);
      tmp0 = BVConstEvaluator(t[0]).GetBVConst();
      unsigned int hi = GetUnsignedConst(BVConstEvaluator(t[1]));
      unsigned int low = GetUnsignedConst(BVConstEvaluator(t[2]));
      unsigned int len = hi-low+1;

      CONSTANTBV::BitVector_Destroy(output);
//.........这里部分代码省略.........
开发者ID:columbia,项目名称:woodpecker,代码行数:101,代码来源:consteval.cpp

示例2: replace

ASTNode SubstitutionMap::replace(const ASTNode& n, ASTNodeMap& fromTo,
                                 ASTNodeMap& cache, NodeFactory* nf,
                                 bool stopAtArrays, bool preventInfinite)
{
  const Kind k = n.GetKind();
  if (k == BVCONST || k == TRUE || k == FALSE)
    return n;

  ASTNodeMap::const_iterator it;

  if ((it = cache.find(n)) != cache.end())
    return it->second;

  if ((it = fromTo.find(n)) != fromTo.end())
  {
    const ASTNode& r = it->second;
    assert(r.GetIndexWidth() == n.GetIndexWidth());

    if (preventInfinite)
      cache.insert(make_pair(n, r));

    ASTNode replaced =
        replace(r, fromTo, cache, nf, stopAtArrays, preventInfinite);
    if (replaced != r)
    {
      fromTo.erase(n);
      fromTo[n] = replaced;
    }

    if (preventInfinite)
      cache.erase(n);

    cache.insert(make_pair(n, replaced));
    return replaced;
  }

  // These can't be created like regular nodes are
  if (k == SYMBOL)
    return n;

  const unsigned int indexWidth = n.GetIndexWidth();
  if (stopAtArrays && indexWidth > 0) // is an array.
  {
    return n;
  }

  const ASTVec& children = n.GetChildren();
  assert(children.size() > 0);
  // Should have no leaves left here.

  ASTVec new_children;
  new_children.reserve(children.size());

  for (ASTVec::const_iterator it = children.begin(); it != children.end(); it++)
  {
    new_children.push_back(
        replace(*it, fromTo, cache, nf, stopAtArrays, preventInfinite));
  }

  assert(new_children.size() == children.size());

  // This code short-cuts if the children are the same. Nodes with the same
  // children,
  // won't have necessarily given the same node if the simplifyingNodeFactory is
  // enabled
  // now, but wasn't enabled when the node was created. Shortcutting saves lots
  // of time.
  if (new_children == children)
  {
    cache.insert(make_pair(n, n));
    return n;
  }

  ASTNode result;
  const unsigned int valueWidth = n.GetValueWidth();

  if (valueWidth == 0) // n.GetType() == BOOLEAN_TYPE
  {
    result = nf->CreateNode(k, new_children);
  }
  else
  {
    // If the index and value width aren't saved, they are reset sometimes (??)
    result = nf->CreateArrayTerm(k, indexWidth, valueWidth, new_children);
  }

  // We may have created something that should be mapped. For instance,
  // if n is READ(A, x), and the fromTo is: {x==0, READ(A,0) == 1}, then
  // by here the result will be READ(A,0). Which needs to be mapped again..
  // I hope that this makes it idempotent.

  if (fromTo.find(result) != fromTo.end())
  {
    // map n->result, if running replace() on result gives us 'n', it will not
    // infinite loop.
    // This is only currently required for the bitblast equivalence stuff.
    if (preventInfinite)
      cache.insert(make_pair(n, result));

    result = replace(result, fromTo, cache, nf, stopAtArrays, preventInfinite);
//.........这里部分代码省略.........
开发者ID:delcypher,项目名称:stp,代码行数:101,代码来源:SubstitutionMap.cpp


注:本文中的ASTNode::GetValueWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。