ostringstream oss;
oss << "let_k_" << sz;
- ASTNode CurrentSymbol = bm->CreateSymbol(oss.str().c_str());
- CurrentSymbol.SetValueWidth(this->GetValueWidth());
- CurrentSymbol.SetIndexWidth(this->GetIndexWidth());
+ ASTNode CurrentSymbol = bm->CreateSymbol(oss.str().c_str(),this->GetIndexWidth(),this->GetValueWidth());
/* If for some reason the variable being created here is
* already declared by the user then the printed output will
* not be a legal input to the system. too bad. I refuse to
els = TransformTerm(els);
result = simp->CreateSimplifiedTermITE(cond, thn, els);
}
- result.SetIndexWidth(term.GetIndexWidth());
+ assert(result.GetIndexWidth() ==term.GetIndexWidth());
break;
}
default:
if (c!=o)
{
- result = nf->CreateTerm(k, width, o);
- result.SetIndexWidth(indexwidth);
+ result = nf->CreateArrayTerm(k,indexwidth, width, o);
}
else
result = term;
class HashingNodeFactory : public NodeFactory
{
- BEEV::STPMgr& bm;
public:
HashingNodeFactory(BEEV::STPMgr& bm_)
- : bm(bm_)
+ :NodeFactory(bm_)
{
}
#include "ASTKind.h"
#include "AST.h"
+#include "../../STPManager/STPManager.h"
NodeFactory::~NodeFactory()
{
return result;
}
+
+ASTNode NodeFactory::CreateSymbol(const char * const name, unsigned indexWidth, unsigned valueWidth)
+{
+ ASTNode n = bm.LookupOrCreateSymbol(name);
+ n.SetIndexWidth(indexWidth);
+ n.SetValueWidth(valueWidth);
+ return n;
+}
class ASTNode;
typedef std::vector<ASTNode> ASTVec;
extern ASTVec _empty_ASTVec;
+class STPMgr;
}
using BEEV::ASTNode;
class NodeFactory
{
+protected:
+ BEEV::STPMgr& bm;
+
public:
+ NodeFactory(BEEV::STPMgr& bm_) : bm(bm_){}
+
virtual ~NodeFactory();
virtual BEEV::ASTNode CreateTerm(Kind kind, unsigned int width,
virtual BEEV::ASTNode CreateNode(Kind kind,
const BEEV::ASTVec& children) =0;
+ ASTNode CreateSymbol(const char * const name, unsigned indexWidth, unsigned valueWidth);
ASTNode CreateTerm(Kind kind, unsigned int width, const ASTNode& child0,
const ASTVec &children = _empty_ASTVec);
private:
NodeFactory& hashing;
- BEEV::STPMgr& bm; // Only here until the const evaluator is pulled out.
const ASTNode& ASTTrue;
const ASTNode& ASTFalse;
SimplifyingNodeFactory(NodeFactory& raw_, BEEV::STPMgr& bm_)
- :hashing(raw_), bm(bm_), ASTTrue(bm.ASTTrue), ASTFalse(bm.ASTFalse), ASTUndefined(bm.ASTUndefined)
+ :hashing(raw_), NodeFactory(bm_), ASTTrue(bm_.ASTTrue), ASTFalse(bm_.ASTFalse), ASTUndefined(bm_.ASTUndefined)
{
}
;
class TypeChecker : public NodeFactory
{
NodeFactory& f;
-STPMgr& bm;
public:
- TypeChecker(NodeFactory& f_, STPMgr& bm_) : f(f_), bm(bm_)
+ TypeChecker(NodeFactory& f_, STPMgr& bm_) : f(f_), NodeFactory(bm)
{}
BEEV::ASTNode CreateTerm(BEEV::Kind kind, unsigned int width, const BEEV::ASTVec &children);
////////////////////////////////////////////////////////////////
// STPMgr member functions to create ASTSymbol and ASTBVConst
////////////////////////////////////////////////////////////////
- ASTNode STPMgr::CreateSymbol(const char * const name)
+ ASTNode STPMgr::LookupOrCreateSymbol(const char * const name)
{
- ASTSymbol temp_sym(name);
+ ASTSymbol temp_sym(name);
ASTNode n(LookupOrCreateSymbol(temp_sym));
- return n;
+ return n;
}
// FIXME: _name is now a constant field, and this assigns to it
std::string ccc(d);
c += "_solver_" + ccc;
- ASTNode CurrentSymbol = CreateSymbol(c.c_str());
+ ASTNode CurrentSymbol = CreateSymbol(c.c_str(),0,n);
assert(0 !=n);
- CurrentSymbol.SetValueWidth(n);
- CurrentSymbol.SetIndexWidth(0);
return CurrentSymbol;
} //end of NewVar()
str += "(";
str += outNum.str();
str += ")";
- ASTNode CurrentSymbol = CreateSymbol(str.c_str());
- CurrentSymbol.SetValueWidth(0);
- CurrentSymbol.SetIndexWidth(0);
+ ASTNode CurrentSymbol = CreateSymbol(str.c_str(),0,0);
return CurrentSymbol;
} // End of NewParameterized_BooleanVar()
****************************************************************/
// Create and return an ASTNode for a symbol
- ASTNode CreateSymbol(const char * const name);
+ ASTNode LookupOrCreateSymbol(const char * const name);
// Create and return an ASTNode for a symbol Width is number of
// bits.
* Create Node functions *
****************************************************************/
+ inline ASTNode CreateSymbol(const char * const name, unsigned indexWidth, unsigned valueWidth)
+ {
+ return defaultNodeFactory->CreateSymbol(name,indexWidth,valueWidth);
+ }
+
+
// Create and return an interior ASTNode
inline BEEV::ASTNode CreateNode(BEEV::Kind kind, const BEEV::ASTVec& children = _empty_ASTVec)
{
return defaultNodeFactory->CreateTerm(kind,width,children);
}
+ inline BEEV::ASTNode CreateArrayTerm(BEEV::Kind kind, unsigned int indexWidth, unsigned int width, const BEEV::ASTVec &children =_empty_ASTVec)
+ {
+ return defaultNodeFactory->CreateArrayTerm(kind,indexWidth, width,children);
+ }
+
inline ASTNode CreateTerm(Kind kind, unsigned int width,
const ASTNode& child0, const ASTVec &children = _empty_ASTVec) {
return defaultNodeFactory->CreateTerm(kind, width, child0, children);
char d[32 + prefix.length()];
sprintf(d, "%s_%d", prefix.c_str(), _symbol_count++);
- BEEV::ASTNode CurrentSymbol = CreateSymbol(d);
- CurrentSymbol.SetValueWidth(valueWidth);
- CurrentSymbol.SetIndexWidth(indexWidth);
-
+ BEEV::ASTNode CurrentSymbol = CreateSymbol(d,indexWidth,valueWidth);
return CurrentSymbol;
}
int indexwidth, int valuewidth) {
bmstar b = (bmstar)(((stpstar)vc)->bm);
- node o = b->CreateSymbol(name);
- o.SetIndexWidth(indexwidth);
- o.SetValueWidth(valuewidth);
+ node o = b->CreateSymbol(name,indexwidth,valuewidth);
nodestar output = new node(o);
////if(cinterface_exprdelete_on) created_exprs.push_back(output);
bmstar b = (bmstar)(((stpstar)vc)->bm);
nodestar a = (nodestar)type;
- node o = b->CreateSymbol(name);
+ unsigned indexWidth;
+ unsigned valueWidth;
+
switch(a->GetKind()) {
case BEEV::BITVECTOR:
- o.SetIndexWidth(0);
- o.SetValueWidth((*a)[0].GetUnsignedConst());
+ indexWidth = 0;
+ valueWidth = (*a)[0].GetUnsignedConst();
break;
case BEEV::ARRAY:
- o.SetIndexWidth((*a)[0].GetUnsignedConst());
- o.SetValueWidth((*a)[1].GetUnsignedConst());
+ indexWidth = (*a)[0].GetUnsignedConst();
+ valueWidth = (*a)[1].GetUnsignedConst();
break;
case BEEV::BOOLEAN:
- o.SetIndexWidth(0);
- o.SetValueWidth(0);
+ indexWidth = 0;
+ valueWidth = 0;
break;
default:
BEEV::FatalError("CInterface: vc_varExpr: Unsupported type",*a);
break;
+
}
+ node o = b->CreateSymbol(name,indexWidth,valueWidth);
+
nodestar output = new node(o);
////if(cinterface_exprdelete_on) created_exprs.push_back(output);
BVTypeCheck(*output);
"POP" { return POP_TOK;}
(({LETTER})|(_)({ANYTHING}))({ANYTHING})* {
- BEEV::ASTNode nptr = (BEEV::ParserBM)->CreateSymbol(yytext);
+ BEEV::ASTNode nptr = parserInterface->LookupOrCreateSymbol(yytext);
// Check valuesize to see if it's a prop var. I don't like doing
// type determination in the lexer, but it's easier than rewriting
| TRUELIT_TOK
{
$$ = new ASTNode(parserInterface->CreateNode(TRUE));
- $$->SetIndexWidth(0);
- $$->SetValueWidth(0);
+ assert($$->GetIndexWidth() == 0);
+ assert($$->GetValueWidth() == 0);
}
| FALSELIT_TOK
{
$$ = new ASTNode(parserInterface->CreateNode(FALSE));
- $$->SetIndexWidth(0);
- $$->SetValueWidth(0);
+ assert($$->GetIndexWidth() == 0);
+ assert($$->GetValueWidth() == 0);
}
| LET_TOK LetDecls IN_TOK Formula
return bm.CreateBVConst(width, bvconst);
}
- ASTNode CreateSymbol(const char * const name)
+ ASTNode LookupOrCreateSymbol(const char * const name)
{
- return bm.CreateSymbol(name);
+ return bm.LookupOrCreateSymbol(name);
}
};
}
"boolbv" { return BOOL_TO_BV_TOK;}
(({LETTER})|(_)({ANYTHING}))({ANYTHING})* {
- BEEV::ASTNode nptr = parserInterface->CreateSymbol(smttext);
+ BEEV::ASTNode nptr = parserInterface->LookupOrCreateSymbol(smttext);
// Check valuesize to see if it's a prop var. I don't like doing
// type determination in the lexer, but it's easier than rewriting
if (s[0] == '|' && s[str.size()-1] == '|')
str = str.substr(1,str.length()-2);
- BEEV::ASTNode nptr = BEEV::parserInterface->CreateSymbol(str.c_str());
+ BEEV::ASTNode nptr = BEEV::parserInterface->LookupOrCreateSymbol(str.c_str());
// Check valuesize to see if it's a prop var. I don't like doing
// type determination in the lexer, but it's easier than rewriting
oss << "?let_k_" << sz;
ASTNode CurrentSymbol = n.GetSTPMgr()->CreateSymbol(
- oss.str().c_str());
- CurrentSymbol.SetValueWidth(n.GetValueWidth());
- CurrentSymbol.SetIndexWidth(n.GetIndexWidth());
+ oss.str().c_str(),n.GetIndexWidth(), n.GetValueWidth());
/* If for some reason the variable being created here is
* already declared by the user then the printed output will
* not be a legal input to the system. too bad. I refuse to
if (n.GetIndexWidth() != 0)
{
const ASTNode& r = it->second;
- r.SetIndexWidth(n.GetIndexWidth());
+ assert(r.GetIndexWidth() == n.GetIndexWidth());
assert(BVTypeCheck(r));
ASTNode replaced = replace(r, fromTo, cache,nf);
if (replaced != r)
// If the index and value width aren't saved, they are reset sometimes (??)
const unsigned int indexWidth = n.GetIndexWidth();
const unsigned int valueWidth = n.GetValueWidth();
- result = nf->CreateTerm(n.GetKind(), n.GetValueWidth(),
+ result = nf->CreateArrayTerm(n.GetKind(),indexWidth, n.GetValueWidth(),
children);
- result.SetValueWidth(valueWidth);
- result.SetIndexWidth(indexWidth);
+ assert(result.GetValueWidth() == valueWidth);
+
}
else
result = n;
return nf->CreateNode(EQ, in1, in2);
}
+ // nb. this is sometimes used to build array terms.
//accepts cond == t1, then part is t2, and else part is t3
ASTNode Simplifier::CreateSimplifiedTermITE(const ASTNode& in0,
const ASTNode& in1,
FatalError("CreateSimplifiedTermITE: "\
"the lengths of the two branches don't match", t1);
}
- return nf->CreateTerm(ITE, t1.GetValueWidth(), t0, t1, t2);
+ return nf->CreateArrayTerm(ITE, t1.GetIndexWidth(),t1.GetValueWidth(), t0, t1, t2);
}
if (t0 == ASTTrue)
return t2;
}
- return nf->CreateTerm(ITE, t1.GetValueWidth(), t0, t1, t2);
+ return nf->CreateArrayTerm(ITE, t1.GetIndexWidth(),t1.GetValueWidth(), t0, t1, t2);
}
ASTNode
assert(v.size() > 0);
if (v != actualInputterm.GetChildren()) // short-cut.
{
- output = nf->CreateTerm(k, inputValueWidth, v);
- output.SetIndexWidth(actualInputterm.GetIndexWidth());
+ output = nf->CreateArrayTerm(k,actualInputterm.GetIndexWidth(), inputValueWidth, v);
}
else
output = actualInputterm;
SimplifyFormula(term[0],VarConstMap),
SimplifyArrayTerm(term[1], VarConstMap),
SimplifyArrayTerm(term[2], VarConstMap));
- output.SetIndexWidth(iw);
+ assert(output.GetIndexWidth() == iw);
}
break;
case WRITE: {
ASTNode idx = SimplifyTerm(term[1]);
ASTNode val = SimplifyTerm(term[2]);
- output = nf->CreateTerm(WRITE, term.GetValueWidth(), array, idx, val);
- output.SetIndexWidth(iw); // save the value and set, otherwise it sometimes fails.
+ output = nf->CreateArrayTerm(WRITE,iw, term.GetValueWidth(), array, idx, val);
}
break;
ostringstream oss;
oss << "cnf" << "{" << varphi.GetNodeNum() << "}";
- psi = bm->CreateSymbol(oss.str().c_str());
-
- //########################################
- // step 2, set widths appropriately
- //########################################
-
- psi.SetValueWidth(varphi.GetValueWidth());
- psi.SetIndexWidth(varphi.GetIndexWidth());
+ psi = bm->CreateSymbol(oss.str().c_str(),varphi.GetIndexWidth(),varphi.GetValueWidth());
+
//########################################
// step 3, recurse over children
//########################################
ostringstream oss;
oss << "cnf" << "{" << varphi.GetNodeNum() << "}";
- ASTNode psi = bm->CreateSymbol(oss.str().c_str());
+ ASTNode psi = bm->CreateSymbol(oss.str().c_str(),0,0);
//########################################
// step 2, add defs
ostringstream oss;
oss << "cnf" << "{" << varphi.GetNodeNum() << "}";
- ASTNode psi = bm->CreateSymbol(oss.str().c_str());
+ ASTNode psi = bm->CreateSymbol(oss.str().c_str(),0,0);
//########################################
// step 2, add defs
ostringstream oss;
oss << "cnf" << "{" << varphi.GetNodeNum() << "}";
- ASTNode psi = bm->CreateSymbol(oss.str().c_str());
+ ASTNode psi = bm->CreateSymbol(oss.str().c_str(),0,0);
//########################################
// step 3, add defs
ClauseList* defs)
{
ASTNode dummy_false_var =
- bm->CreateNode(NOT, bm->CreateSymbol("*TrueDummy*"));
+ bm->CreateNode(NOT, bm->CreateSymbol("*TrueDummy*",0,0));
info[varphi]->clausespos = SINGLETON(dummy_false_var);
} //End of convertFormulaToCNFPosFALSE()
void CNFMgr::convertFormulaToCNFPosTRUE(const ASTNode& varphi,
ClauseList* defs)
{
- ASTNode dummy_true_var = bm->CreateSymbol("*TrueDummy*");
+ ASTNode dummy_true_var = bm->CreateSymbol("*TrueDummy*",0,0);
info[varphi]->clausespos = SINGLETON(dummy_true_var);
} //End of convertFormulaToCNFPosTRUE
void CNFMgr::convertFormulaToCNFNegFALSE(const ASTNode& varphi,
ClauseList* defs)
{
- ASTNode dummy_true_var = bm->CreateSymbol("*TrueDummy*");
+ ASTNode dummy_true_var = bm->CreateSymbol("*TrueDummy*",0,0);
info[varphi]->clausesneg = SINGLETON(dummy_true_var);
} //End of convertFormulaToCNFNegFALSE()
ClauseList* defs)
{
ASTNode dummy_false_var =
- bm->CreateNode(NOT, bm->CreateSymbol("*TrueDummy*"));
+ bm->CreateNode(NOT, bm->CreateSymbol("*TrueDummy*",0,0));
info[varphi]->clausesneg = SINGLETON(dummy_false_var);
} //End of convertFormulaToCNFNegTRUE()
{
bm->GetRunTimes()->start(RunTimes::CNFConversion);
scanFormula(varphi, true, false);
- ASTNode dummy_true_var = bm->CreateSymbol("*TrueDummy*");
+ ASTNode dummy_true_var = bm->CreateSymbol("*TrueDummy*",0,0);
ClauseList* defs = SINGLETON(dummy_true_var);
convertFormulaToCNF(varphi, defs);
ClauseList* top = info[varphi]->clausespos;