[Tool] Add batch mode to openfpga shell execution

This commit is contained in:
tangxifan 2021-01-24 14:33:58 -07:00
parent d502410b40
commit 8cac3291cb
3 changed files with 24 additions and 8 deletions

View File

@ -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 */

View File

@ -272,7 +272,9 @@ void Shell<T>::run_interactive_mode(T& context, const bool& quiet_mode) {
}
template <class T>
void Shell<T>::run_script_mode(const char* script_file_name, T& context) {
void Shell<T>::run_script_mode(const char* script_file_name,
T& context,
const bool& batch_mode) {
time_start_ = std::clock();
@ -356,17 +358,24 @@ void Shell<T>::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 */
/* If not in batch mode, switch to interactive mode, stay tuned */
if (!batch_mode) {
run_interactive_mode(context, true);
}
}
template <class T>

View File

@ -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 */