From 927e20fb6ef52077a2248d0c6829042b7ab8b8fe Mon Sep 17 00:00:00 2001 From: Dani Messerman Date: Mon, 27 Apr 2015 19:19:37 +0300 Subject: [PATCH] Better command line handling --- src/binary_translation/main.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/binary_translation/main.cpp b/src/binary_translation/main.cpp index 1cd5f720e..556fab3c9 100644 --- a/src/binary_translation/main.cpp +++ b/src/binary_translation/main.cpp @@ -5,9 +5,28 @@ #include "core/mem_map.h" #include "core/loader/loader.h" #include "codegen.h" +#include + +namespace cl = llvm::cl; + +cl::opt InputFilename(cl::Positional, cl::Required, cl::desc("")); +cl::opt OutputFilename(cl::Positional, cl::Required, cl::desc("")); +cl::opt DebugFilename(cl::Positional, cl::Optional, cl::desc("")); int main(int argc, const char *const *argv) { + // Remove all llvm options + llvm::StringMap options; + cl::getRegisteredOptions(options); + for (auto i = options.begin(); i != options.end(); ++i) + { + if (i->getValue() != &InputFilename && i->getValue() != &OutputFilename && i->getValue() != &DebugFilename) + { + i->getValue()->setHiddenFlag(cl::Hidden); + } + } + cl::ParseCommandLineOptions(argc, argv); + std::shared_ptr logger = Log::InitGlobalLogger(); Log::Filter log_filter(Log::Level::Debug); Log::SetFilter(&log_filter); @@ -17,15 +36,9 @@ int main(int argc, const char *const *argv) logging_thread.join(); }); - if (argc < 3) - { - LOG_CRITICAL(BinaryTranslator, "Usage: binary_translate []"); - return -1; - } - - auto input_rom = argv[1]; - auto output_object = argv[2]; - auto output_debug = argc > 3 ? argv[3] : nullptr; + auto input_rom = InputFilename.c_str(); + auto output_object = OutputFilename.c_str(); + auto output_debug = DebugFilename.getNumOccurrences() ? DebugFilename.c_str() : nullptr; Core::Init(); Memory::Init();