cprover
qdimacs_core.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: CM Wintersteiger
6 
7 \*******************************************************************/
8 
9 #include "qdimacs_core.h"
10 
11 #include <util/arith_tools.h>
12 #include <util/std_expr.h>
13 
15 {
16  if(expr.id()==ID_and)
17  {
18  typedef std::map<exprt, std::set<exprt> > used_bits_mapt;
19  used_bits_mapt used_bits_map;
20 
21  forall_operands(it, expr)
22  {
23  if(it->id()==ID_extractbit && it->op1().is_constant())
24  {
25  used_bits_map[it->op0()].insert(it->op1());
26  }
27  else if(it->id()==ID_not &&
28  it->op0().id()==ID_extractbit && it->op0().op1().is_constant())
29  {
30  used_bits_map[it->op0().op0()].insert(it->op0().op1());
31  }
32  }
33 
34  for(used_bits_mapt::const_iterator it=used_bits_map.begin();
35  it!=used_bits_map.end();
36  it++)
37  {
38  #if 0
39  unsigned width;
40  boolbv_get_width(it->first.type(), width);
41 
42  std::string value_string;
43  value_string.resize(width, '0');
44 
45  if(it->second.size()==width) // all bits extracted from this one!
46  {
47  const irep_idt &ident=it->first.get(ID_identifier);
48  const exprt::operandst &old_operands=expr.operands();
49  exprt::operandst new_operands;
50 
51  for(exprt::operandst::const_iterator oit=old_operands.begin();
52  oit!=old_operands.end();
53  oit++)
54  {
55  if(oit->id()==ID_extractbit &&
56  oit->op1().is_constant())
57  {
58  if(oit->op0().get(ID_identifier)==ident)
59  {
60  const exprt &val_expr=oit->op1();
61  mp_integer value;
62  to_integer(val_expr, value);
63  value_string[value.to_ulong()]='1';
64 
65  #if 0
66  std::cout << "[" << value << "]=1\n";
67  #endif
68 
69  continue;
70  }
71  }
72  else if(oit->id()==ID_not &&
73  oit->op0().id()==ID_extractbit &&
74  oit->op0().op1().is_constant())
75  {
76  if(oit->op0().op0().get(ID_identifier)==ident)
77  {
78  // just kick it; the bit in value_string is 0 anyways
79  continue;
80  }
81  }
82 
83  new_operands.push_back(*oit);
84  }
85 
86  const constant_exprt new_value(value_string, it->first.type());
87  new_operands.push_back(equality_exprt(it->first, new_value));
88 
89  #if 0
90  std::cout << "FINAL: " << value_string << '\n';
91  #endif
92 
93  expr.operands()=new_operands;
94  }
95  #endif
96  }
97  }
98 }
BigInt mp_integer
Definition: mp_arith.h:22
void simplify_extractbits(exprt &expr) const
A constant literal expression.
Definition: std_expr.h:4422
const irep_idt & id() const
Definition: irep.h:259
API to expression classes.
exprt & op1()
Definition: expr.h:75
#define forall_operands(it, expr)
Definition: expr.h:17
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
std::vector< exprt > operandst
Definition: expr.h:45
Base class for all expressions.
Definition: expr.h:42
bool to_integer(const exprt &expr, mp_integer &int_value)
Definition: arith_tools.cpp:17
operandst & operands()
Definition: expr.h:66