diff --git a/openfpga/src/base/basic_command.cpp b/openfpga/src/base/basic_command.cpp index 397c9272c..7b0d8efc2 100644 --- a/openfpga/src/base/basic_command.cpp +++ b/openfpga/src/base/basic_command.cpp @@ -1,8 +1,10 @@ /******************************************************************** * Add basic commands to the OpenFPGA shell interface, including: * - exit + * - version * - help *******************************************************************/ +#include "openfpga_title.h" #include "basic_command.h" /* begin namespace openfpga */ @@ -17,7 +19,15 @@ void add_basic_commands(openfpga::Shell& shell) { shell.set_command_class(shell_cmd_exit_id, basic_cmd_class); shell.set_command_execute_function(shell_cmd_exit_id, [shell](){shell.exit();}); - /* Note: help must be the last to add because the linking to execute function will do a snapshot on the shell */ + /* Version */ + Command shell_cmd_version("version"); + ShellCommandId shell_cmd_version_id = shell.add_command(shell_cmd_version, "Show version information"); + shell.set_command_class(shell_cmd_version_id, basic_cmd_class); + shell.set_command_execute_function(shell_cmd_version_id, print_openfpga_version_info); + + /* Note: + * help MUST be the last to add because the linking to execute function will do a snapshot on the shell + */ Command shell_cmd_help("help"); ShellCommandId shell_cmd_help_id = shell.add_command(shell_cmd_help, "Launch help desk"); shell.set_command_class(shell_cmd_help_id, basic_cmd_class); diff --git a/openfpga/src/base/openfpga_title.cpp b/openfpga/src/base/openfpga_title.cpp index 7d05694cf..5635b4502 100644 --- a/openfpga/src/base/openfpga_title.cpp +++ b/openfpga/src/base/openfpga_title.cpp @@ -2,6 +2,8 @@ * This file includes the functions to create the title page * which introduces generality of OpenFPGA framework *******************************************************************/ +#include "vtr_log.h" + #include "openfpga_title.h" #include "openfpga_version.h" @@ -50,13 +52,19 @@ std::string create_openfpga_title() { title += std::string("THE SOFTWARE.\n"); title += std::string("\n"); - /* Display version */ - title += std::string("Version: " + std::string(openfpga::VERSION) + "\n"); - title += std::string("Revision: " + std::string(openfpga::VCS_REVISION) + "\n"); - title += std::string("Compiled: " + std::string(openfpga::BUILD_TIMESTAMP) + "\n"); - title += std::string("Compiler: " + std::string(openfpga::COMPILER) + "\n"); - title += std::string("Build Info: " + std::string(openfpga::BUILD_INFO) + "\n"); - title += std::string("\n"); - return title; } + +/******************************************************************** + * Generate a string of openfpga title introduction + * This is mainly used when launching OpenFPGA shell + *******************************************************************/ +void print_openfpga_version_info() { + /* Display version */ + VTR_LOG("Version: %s\n", openfpga::VERSION); + VTR_LOG("Revision: %s\n", openfpga::VCS_REVISION); + VTR_LOG("Compiled: %s\n", openfpga::BUILD_TIMESTAMP); + VTR_LOG("Compiler: %s\n", openfpga::COMPILER); + VTR_LOG("Build Info: %s\n", openfpga::BUILD_INFO); + VTR_LOG("\n"); +} diff --git a/openfpga/src/base/openfpga_title.h b/openfpga/src/base/openfpga_title.h index 8f4ab1e90..52be7e4e2 100644 --- a/openfpga/src/base/openfpga_title.h +++ b/openfpga/src/base/openfpga_title.h @@ -11,4 +11,6 @@ *******************************************************************/ std::string create_openfpga_title(); +void print_openfpga_version_info(); + #endif diff --git a/openfpga/src/main.cpp b/openfpga/src/main.cpp index 3c2372c2a..8b4404c84 100644 --- a/openfpga/src/main.cpp +++ b/openfpga/src/main.cpp @@ -29,21 +29,27 @@ int main(int argc, char** argv) { /* Create the command to launch shell in different modes */ openfpga::Command start_cmd("OpenFPGA"); - /* Add options: - * '--interactive', -i': launch the interactive mode - * '--file', -f': launch the script mode - * '--batch_execution': execute the script in batch mode. Will exit immediately when fatal errors occurred - */ + /* Add options to openfpga shell interface */ + /* '--interactive', -i': launch the interactive mode */ openfpga::CommandOptionId opt_interactive = start_cmd.add_option("interactive", false, "Launch OpenFPGA in interactive mode"); start_cmd.set_option_short_name(opt_interactive, "i"); + /* '--file', -f': launch the script mode */ openfpga::CommandOptionId opt_script_mode = start_cmd.add_option("file", false, "Launch OpenFPGA in script mode"); start_cmd.set_option_require_value(opt_script_mode, openfpga::OPT_STRING); start_cmd.set_option_short_name(opt_script_mode, "f"); + /* '--batch_execution': execute the script in batch mode. + * Will exit immediately when fatal errors occurred + */ openfpga::CommandOptionId opt_batch_exec = start_cmd.add_option("batch_execution", false, "Launch OpenFPGA in batch mode when running scripts"); start_cmd.set_option_short_name(opt_batch_exec, "batch"); + /* '--version', -v': print version information */ + openfpga::CommandOptionId opt_version = start_cmd.add_option("version", false, "Show OpenFPGA version"); + start_cmd.set_option_short_name(opt_version, "v"); + + /* '--help', -h': print help desk */ openfpga::CommandOptionId opt_help = start_cmd.add_option("help", false, "Help desk"); start_cmd.set_option_short_name(opt_help, "h"); @@ -95,7 +101,13 @@ int main(int argc, char** argv) { /* Parse fail: Echo the command */ openfpga::print_command_options(start_cmd); } else { - /* Parse succeed. Start a shell */ + /* Parse succeed. Branch on options */ + /* Show version */ + if (true == start_cmd_context.option_enable(start_cmd, opt_version)) { + print_openfpga_version_info(); + return 0; + } + /* Start a shell */ if (true == start_cmd_context.option_enable(start_cmd, opt_interactive)) { shell.run_interactive_mode(openfpga_context);