From 5cdc743d491a04ee0446bd757cedb4c7b6bc585f Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 9 Jul 2012 17:09:49 +1000 Subject: Cleaning up a bit of code around the place. - Especially making logging a bit nicer. --- impl/main.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'impl/main.cpp') diff --git a/impl/main.cpp b/impl/main.cpp index 664fb6f..9e34071 100644 --- a/impl/main.cpp +++ b/impl/main.cpp @@ -1,7 +1,7 @@ +#include "Log.hpp" #include #include #include -#include "Log.hpp" #include "Complete.hpp" #include "Expression.hpp" #include "Operator.hpp" @@ -98,21 +98,27 @@ void treeToSystem(pANTLR3_BASE_TREE node, EquationSystem& system) { typedef Complete ZBar; int main (int argc, char* argv[]) { if (argc <= 3) { - cout << "Usage: " << argv[0] << " filename [fixpoint strategy log]" << endl + cout << "Usage: " << argv[0] << " filename fixpoint strategy [log]" << endl << " fixpoint: naive | smart" << endl << " strategy: naive | repeat | smart" << endl - << " log: [section[,section[,section[...]]]]" << endl; + << " log: section[,section[,section[...]]]" << endl; exit(1); } - 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); - } + map loggers; + loggers["info"] = &log::info; + loggers["trace"] = &log::trace; + loggers["strategy"] = &log::strategy; + loggers["fixpoint"] = &log::fixpoint; + loggers["debug"] = &log::debug; + + if (argc > 3) { + char* arg = argv[4]; + char* str = strtok(arg, ","); + do { + if (loggers[str]) + loggers[str]->enabled(true); + } while ((str = strtok(NULL, ",")) != NULL); } auto input = antlr3FileStreamNew((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT); @@ -156,7 +162,7 @@ int main (int argc, char* argv[]) { exit(1); } - log::debug << system; + log::debug << system << std::endl; system.indexMaxExpressions(); // make reverse-lookup O(1) instead of O(n) StableVariableAssignment result(system.variableCount(), infinity()); ConcreteMaxStrategy strategy(system); @@ -169,11 +175,11 @@ int main (int argc, char* argv[]) { s1.clear(); algorithm->maxFixpoint(system, strategy, result, s2, s1); - log::debug << result; + log::debug << result << std::endl; s2.clear(); changed = improvement->improve(system, strategy, result, s1, s2); - log::debug << (changed ? "true" : "false"); + log::debug << "Changed: " << (changed ? "true" : "false") << std::endl; } while(changed); cout << endl; @@ -194,3 +200,4 @@ int main (int argc, char* argv[]) { return 0; } + -- cgit v1.2.3