diff --git a/libopenfpga/libopenfpgashell/src/shell.h b/libopenfpga/libopenfpgashell/src/shell.h index 67dd4356d..26695b819 100644 --- a/libopenfpga/libopenfpgashell/src/shell.h +++ b/libopenfpga/libopenfpgashell/src/shell.h @@ -143,7 +143,9 @@ class Shell { /* Start the interactive mode, where users will type-in command by command */ void run_interactive_mode(T& context, const bool& quiet_mode = false); /* Start the script mode, where users provide a file which includes all the commands to run */ - void run_script_mode(const char* script_file_name, T& context); + void run_script_mode(const char* script_file_name, + T& context, + const bool& batch_mode = false); /* Print all the commands by their classes. This is actually the help desk */ void print_commands() const; /* Quit the shell */ diff --git a/libopenfpga/libopenfpgashell/src/shell.tpp b/libopenfpga/libopenfpgashell/src/shell.tpp index 7c0ff7ce6..6e607f016 100644 --- a/libopenfpga/libopenfpgashell/src/shell.tpp +++ b/libopenfpga/libopenfpgashell/src/shell.tpp @@ -272,7 +272,9 @@ void Shell::run_interactive_mode(T& context, const bool& quiet_mode) { } template -void Shell::run_script_mode(const char* script_file_name, T& context) { +void Shell::run_script_mode(const char* script_file_name, + T& context, + const bool& batch_mode) { time_start_ = std::clock(); @@ -356,17 +358,24 @@ void Shell::run_script_mode(const char* script_file_name, T& context) { /* Empty the line ready to start a new line */ cmd_line.clear(); - /* Check the execution status of the command, if fatal error happened, we should abort immediately */ + /* Check the execution status of the command, + * if fatal error happened, we should abort immediately + */ if (CMD_EXEC_FATAL_ERROR == status) { - VTR_LOG("Fatal error occurred!\nAbort and enter interactive mode\n"); + VTR_LOG("Fatal error occurred!\n"); + /* If not in the batch mode, we will got to interactive mode */ + VTR_LOGV(batch_mode, "OpenFPGA Abort\n"); + VTR_LOGV(!batch_mode, "Enter interactive mode\n"); break; } } } fp.close(); - /* Return to interactive mode, stay tuned */ - run_interactive_mode(context, true); + /* If not in batch mode, switch to interactive mode, stay tuned */ + if (!batch_mode) { + run_interactive_mode(context, true); + } } template diff --git a/openfpga/src/main.cpp b/openfpga/src/main.cpp index d19b35944..083d5965d 100644 --- a/openfpga/src/main.cpp +++ b/openfpga/src/main.cpp @@ -29,9 +29,10 @@ int main(int argc, char** argv) { /* Create the command to launch shell in different modes */ openfpga::Command start_cmd("OpenFPGA"); - /* Add two options: + /* 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 */ openfpga::CommandOptionId opt_interactive = start_cmd.add_option("interactive", false, "Launch OpenFPGA in interactive mode"); start_cmd.set_option_short_name(opt_interactive, "i"); @@ -40,6 +41,9 @@ int main(int argc, char** argv) { start_cmd.set_option_require_value(opt_script_mode, openfpga::OPT_STRING); start_cmd.set_option_short_name(opt_script_mode, "f"); + 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"); + openfpga::CommandOptionId opt_help = start_cmd.add_option("help", false, "Help desk"); start_cmd.set_option_short_name(opt_help, "h"); @@ -100,7 +104,8 @@ int main(int argc, char** argv) { if (true == start_cmd_context.option_enable(start_cmd, opt_script_mode)) { shell.run_script_mode(start_cmd_context.option_value(start_cmd, opt_script_mode).c_str(), - openfpga_context); + openfpga_context, + start_cmd_context.option_enable(start_cmd, opt_batch_exec)); return 0; } /* Reach here there is something wrong, show the help desk */