diff options
Diffstat (limited to 'impl/main.cpp')
-rw-r--r-- | impl/main.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/impl/main.cpp b/impl/main.cpp index 26aedbe..0317390 100644 --- a/impl/main.cpp +++ b/impl/main.cpp @@ -1,6 +1,7 @@ #include <iostream> #include <vector> #include <sstream> +#include "Log.hpp" #include "Complete.hpp" #include "Expression.hpp" #include "Operator.hpp" @@ -17,7 +18,7 @@ extern "C" { using namespace std; template<typename T> -Expression<T>& treeToExpression(pANTLR3_BASE_TREE node, ConcreteEquationSystem<T>& system) { +Expression<T>& treeToExpression(pANTLR3_BASE_TREE node, EquationSystem<T>& system) { ANTLR3_UINT32 num = node->getChildCount(node); string name = (char*) node->getText(node)->chars; @@ -70,7 +71,7 @@ Expression<T>& treeToExpression(pANTLR3_BASE_TREE node, ConcreteEquationSystem<T } template<typename T> -void treeToSystem(pANTLR3_BASE_TREE node, ConcreteEquationSystem<T>& system) { +void treeToSystem(pANTLR3_BASE_TREE node, EquationSystem<T>& system) { ANTLR3_UINT32 num = node->getChildCount(node); if (num % 2 == 1) @@ -95,23 +96,31 @@ void treeToSystem(pANTLR3_BASE_TREE node, ConcreteEquationSystem<T>& system) { typedef Complete<int> ZBar; int main (int argc, char* argv[]) { if (argc <= 3) { - cout << "Usage: " << argv[0] << " filename naive|smart naive|repeat" << endl; + cout << "Usage: " << argv[0] << " filename [fixpoint strategy log]" << endl + << " fixpoint: naive | smart" << endl + << " strategy: naive | repeat | smart" << endl + << " log: [section[,section[,section[...]]]]" << endl; exit(1); } - pANTLR3_INPUT_STREAM input; - pEquationSystemLexer lex; - pANTLR3_COMMON_TOKEN_STREAM tokens; - pEquationSystemParser parser; + for (int i = 4; i < argc; ++i) { + if (!strcmp(argv[i], "trace")) { + log::trace.enabled(true); + } else if (!strcmp(argv[i], "strategy")) { + log::strategy.enabled(true); + } else if (!strcmp(argv[i], "debug")) { + log::debug.enabled(true); + } + } - input = antlr3FileStreamNew((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT); - lex = EquationSystemLexerNew(input); - tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lex)); - parser = EquationSystemParserNew(tokens); + auto input = antlr3FileStreamNew((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT); + auto lex = EquationSystemLexerNew(input); + auto tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lex)); + auto parser = EquationSystemParserNew(tokens); - EquationSystemParser_equation_system_return ret = parser -> equation_system(parser); + auto ret = parser -> equation_system(parser); - ConcreteEquationSystem<ZBar> system; + EquationSystem<ZBar> system; treeToSystem<ZBar>(ret.tree, system); // PARSE ARGUMENTS - fixpoint @@ -145,27 +154,23 @@ int main (int argc, char* argv[]) { exit(1); } - cout << system << endl; + log::debug << system; StableVariableAssignment<ZBar> result(system.variableCount(), infinity<ZBar>()); ConcreteMaxStrategy<ZBar> strategy(system); - IdSet<Variable<ZBar> > s1(system.variableCount()); - IdSet<Variable<ZBar> > s2(system.variableCount()); + IdSet<Variable<ZBar>> s1(system.variableCount()); + IdSet<Variable<ZBar>> s2(system.variableCount()); bool changed = false; + s2.clear(); + s2.invert(); do { - s2.clear(); - s2.invert(); - algorithm->maxFixpoint(strategy, result, s2, s1); + s1.clear(); + algorithm->maxFixpoint(system, strategy, result, s2, s1); - /*for (unsigned int i = 0, size = system.variableCount(); i < size; ++i) { - Variable<ZBar>& var = system.variable(i); - cout << var.name() << " = " << result[var] << ", " << endl; - } - cout << endl; - exit(0);*/ + log::debug << result; s2.clear(); - changed = improvement->improve(strategy, result, s1, s2); - std::cout << (changed ? "true" : "false") << std::endl; + changed = improvement->improve(system, strategy, result, s1, s2); + log::debug << (changed ? "true" : "false"); } while(changed); cout << endl; |