1 /********************* */
2 /*! \file smt2toredlog.cpp
4 ** Original author: Dejan Jovanovic
5 ** Major contributors: none
6 ** Minor contributors (to current version): Morgan Deters
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief [[ Add one-line brief description here ]]
14 ** [[ Add lengthier description here ]]
15 ** \todo document this file
26 #include "options/options.h"
27 #include "expr/expr.h"
28 #include "expr/command.h"
29 #include "parser/parser.h"
30 #include "parser/parser_builder.h"
31 #include "smt/smt_engine.h"
35 using namespace CVC4::parser
;
36 using namespace CVC4::options
;
38 void translate_to_redlog(
41 const vector
<string
>& info_tags
,
42 const vector
<string
>& info_data
,
43 const map
<Expr
, unsigned>& variables
,
44 const vector
<Expr
>& assertions
);
46 int main(int argc
, char* argv
[])
50 string
input(argv
[1]);
51 // Get the redlog command
52 string
command(argv
[2]);
54 // Create the expression manager
56 options
.set(inputLanguage
, language::input::LANG_SMTLIB_V2
);
57 ExprManager
exprManager(options
);
60 ParserBuilder
parserBuilder(&exprManager
, input
, options
);
61 Parser
* parser
= parserBuilder
.build();
63 // Smt manager for simplifications
64 SmtEngine
engine(&exprManager
);
66 // Variables and assertions
67 std::map
<Expr
, unsigned> variables
;
68 vector
<string
> info_tags
;
69 vector
<string
> info_data
;
70 vector
<Expr
> assertions
;
73 while ((cmd
= parser
->nextCommand())) {
75 SetInfoCommand
* setinfo
= dynamic_cast<SetInfoCommand
*>(cmd
);
77 info_tags
.push_back(setinfo
->getFlag());
78 info_data
.push_back(setinfo
->getSExpr().getValue());
83 DeclareFunctionCommand
* declare
= dynamic_cast<DeclareFunctionCommand
*>(cmd
);
85 string name
= declare
->getSymbol();
86 Expr var
= parser
->getVariable(name
);
87 unsigned n
= variables
.size();
93 AssertCommand
* assert = dynamic_cast<AssertCommand
*>(cmd
);
95 assertions
.push_back(engine
.simplify(assert->getExpr()));
103 // Do the translation
104 translate_to_redlog(input
, command
, info_tags
, info_data
, variables
, assertions
);
106 // Get rid of the parser
110 void translate_to_redlog_term(const map
<Expr
, unsigned>& variables
, const Expr
& term
) {
113 unsigned n
= term
.getNumChildren();
116 if (term
.getKind() == kind::CONST_RATIONAL
) {
117 cout
<< term
.getConst
<Rational
>();
119 assert(variables
.find(term
) != variables
.end());
120 cout
<< "x" << variables
.find(term
)->second
;
124 switch (term
.getKind()) {
128 for (unsigned i
= 0; i
< n
; ++ i
) {
133 translate_to_redlog_term(variables
, term
[i
]);
140 for (unsigned i
= 0; i
< n
; ++ i
) {
145 translate_to_redlog_term(variables
, term
[i
]);
151 translate_to_redlog_term(variables
, term
[0]);
153 translate_to_redlog_term(variables
, term
[1]);
158 translate_to_redlog_term(variables
, term
[0]);
160 translate_to_redlog_term(variables
, term
[1]);
165 translate_to_redlog_term(variables
, term
[0]);
175 void translate_to_redlog(const map
<Expr
, unsigned>& variables
, const Expr
& assertion
) {
178 unsigned n
= assertion
.getNumChildren();
181 if (assertion
.isConst()) {
182 if (assertion
.getConst
<bool>()) {
196 switch (assertion
.getKind()) {
199 translate_to_redlog(variables
, assertion
[0]);
205 for (unsigned i
= 0; i
< n
; ++ i
) {
210 translate_to_redlog(variables
, assertion
[i
]);
217 for (unsigned i
= 0; i
< n
; ++ i
) {
222 translate_to_redlog(variables
, assertion
[i
]);
228 translate_to_redlog(variables
, assertion
[0]);
230 translate_to_redlog(variables
, assertion
[1]);
235 translate_to_redlog(variables
, assertion
[0]);
237 translate_to_redlog(variables
, assertion
[1]);
267 translate_to_redlog(variables
, assertion
[0]);
268 cout
<< " " << op
<< " ";
269 translate_to_redlog(variables
, assertion
[1]);
275 translate_to_redlog_term(variables
, assertion
[0]);
276 cout
<< " " << op
<< " ";
277 translate_to_redlog_term(variables
, assertion
[1]);
283 void translate_to_redlog(
286 const vector
<string
>& info_tags
,
287 const vector
<string
>& info_data
,
288 const std::map
<Expr
, unsigned>& variables
,
289 const vector
<Expr
>& assertions
)
293 // Dump out the information
294 cout
<< "load redlog;" << endl
;
295 cout
<< "rlset ofsf;" << endl
;
297 // Dump the variables
299 cout
<< "phi := ex({";
301 for (unsigned i
= 0; i
< variables
.size(); ++ i
) {
314 for (unsigned i
= 0; i
< assertions
.size(); ++ i
) {
315 if (first
== false) {
319 translate_to_redlog(variables
, assertions
[i
]);
322 cout
<< ");" << endl
;
324 cout
<< "result := " << command
<< " phi;" << endl
;
325 cout
<< "result;" << endl
;
326 cout
<< "quit;" << endl
;