summaryrefslogtreecommitdiff
path: root/src/printer/cvc
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2012-06-09 00:35:38 +0000
committerMorgan Deters <mdeters@gmail.com>2012-06-09 00:35:38 +0000
commit700689a4e4ed42b5198816611eac5bcc1278284d (patch)
tree0d6029f9bc4f46a721930a27a47ac487771c452e /src/printer/cvc
parenta0411d4baad389ce88d4bd26edc8ed811625887c (diff)
Dagification of output expressions.
By default, common subexpressions are dagified if they appear > 1 time and are not constants or variables. This can be changed with --default-expr-dag=N --- N is a threshold such that if the subexpression occurs > N times, it is dagified; a setting of 0 turns off dagification entirely. If you notice strange dumping behavior (taking too long to print anything, e.g.), revert to the old behavior with --default-expr-dag=0 and let me know of the problem.
Diffstat (limited to 'src/printer/cvc')
-rw-r--r--src/printer/cvc/cvc_printer.cpp36
-rw-r--r--src/printer/cvc/cvc_printer.h9
2 files changed, 38 insertions, 7 deletions
diff --git a/src/printer/cvc/cvc_printer.cpp b/src/printer/cvc/cvc_printer.cpp
index f779a1bdc..cc95d72b0 100644
--- a/src/printer/cvc/cvc_printer.cpp
+++ b/src/printer/cvc/cvc_printer.cpp
@@ -36,8 +36,37 @@ namespace CVC4 {
namespace printer {
namespace cvc {
-void CvcPrinter::toStream(std::ostream& out, TNode n, int depth, bool types, bool bracket) const throw()
-{
+void CvcPrinter::toStream(std::ostream& out, TNode n, int toDepth, bool types, size_t dag) const throw() {
+ if(dag != 0) {
+ DagificationVisitor dv(dag);
+ NodeVisitor<DagificationVisitor> visitor;
+ visitor.run(dv, n);
+ const theory::SubstitutionMap& lets = dv.getLets();
+ if(!lets.empty()) {
+ out << "LET ";
+ bool first = true;
+ for(theory::SubstitutionMap::const_iterator i = lets.begin();
+ i != lets.end();
+ ++i) {
+ if(! first) {
+ out << ", ";
+ } else {
+ first = false;
+ }
+ toStream(out, (*i).second, toDepth, types, false);
+ out << " = ";
+ toStream(out, (*i).first, toDepth, types, false);
+ }
+ out << " IN ";
+ }
+ Node body = dv.getDagifiedBody();
+ toStream(out, body, toDepth, types, false);
+ } else {
+ toStream(out, n, toDepth, types, false);
+ }
+}
+
+void CvcPrinter::toStream(std::ostream& out, TNode n, int depth, bool types, bool bracket) const throw() {
if (depth == 0) {
out << "(...)";
} else {
@@ -568,9 +597,10 @@ template <class T>
static bool tryToStream(std::ostream& out, const Command* c) throw();
void CvcPrinter::toStream(std::ostream& out, const Command* c,
- int toDepth, bool types) const throw() {
+ int toDepth, bool types, size_t dag) const throw() {
expr::ExprSetDepth::Scope sdScope(out, toDepth);
expr::ExprPrintTypes::Scope ptScope(out, types);
+ expr::ExprDag::Scope dagScope(out, dag);
if(tryToStream<AssertCommand>(out, c) ||
tryToStream<PushCommand>(out, c) ||
diff --git a/src/printer/cvc/cvc_printer.h b/src/printer/cvc/cvc_printer.h
index 3db3f2c66..7fb611a79 100644
--- a/src/printer/cvc/cvc_printer.h
+++ b/src/printer/cvc/cvc_printer.h
@@ -24,6 +24,9 @@
#include <iostream>
#include "printer/printer.h"
+#include "printer/dagification_visitor.h"
+#include "theory/substitutions.h"
+#include "util/node_visitor.h"
namespace CVC4 {
namespace printer {
@@ -32,10 +35,8 @@ namespace cvc {
class CvcPrinter : public CVC4::Printer {
void toStream(std::ostream& out, TNode n, int toDepth, bool types, bool bracket) const throw();
public:
- void toStream(std::ostream& out, TNode n, int toDepth, bool types) const throw() {
- toStream(out, n, toDepth, types, false);
- }
- void toStream(std::ostream& out, const Command* c, int toDepth, bool types) const throw();
+ void toStream(std::ostream& out, TNode n, int toDepth, bool types, size_t dag) const throw();
+ void toStream(std::ostream& out, const Command* c, int toDepth, bool types, size_t dag) const throw();
void toStream(std::ostream& out, const CommandStatus* s) const throw();
};/* class CvcPrinter */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback