2020-01-22 21:20:10 -06:00
|
|
|
/********************************************************************
|
|
|
|
* Build the OpenFPGA shell interface
|
|
|
|
*******************************************************************/
|
2020-01-23 14:24:35 -06:00
|
|
|
/* Header file from vtrutil library */
|
2020-01-22 21:20:10 -06:00
|
|
|
#include "vtr_log.h"
|
2020-01-23 14:24:35 -06:00
|
|
|
|
|
|
|
/* Header file from libopenfpgashell library */
|
2020-01-22 21:20:10 -06:00
|
|
|
#include "command_parser.h"
|
|
|
|
#include "command_echo.h"
|
|
|
|
#include "shell.h"
|
|
|
|
|
2020-01-23 14:24:35 -06:00
|
|
|
/* Header file from openfpga */
|
2020-01-23 20:10:53 -06:00
|
|
|
#include "vpr_command.h"
|
|
|
|
#include "openfpga_setup_command.h"
|
|
|
|
#include "basic_command.h"
|
2020-01-22 21:20:10 -06:00
|
|
|
|
2020-01-23 14:24:35 -06:00
|
|
|
#include "openfpga_title.h"
|
|
|
|
#include "openfpga_context.h"
|
2020-01-22 21:20:10 -06:00
|
|
|
|
2020-01-23 14:24:35 -06:00
|
|
|
/********************************************************************
|
|
|
|
* Main function to start OpenFPGA shell interface
|
|
|
|
*******************************************************************/
|
2020-01-22 21:20:10 -06:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
/* Create the command to launch shell in different modes */
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::Command start_cmd("OpenFPGA");
|
2020-01-22 21:20:10 -06:00
|
|
|
/* Add two options:
|
|
|
|
* '--interactive', -i': launch the interactive mode
|
|
|
|
* '--file', -f': launch the script mode
|
|
|
|
*/
|
2020-01-23 15:42:49 -06:00
|
|
|
openfpga::CommandOptionId opt_interactive = start_cmd.add_option("interactive", false, "Launch OpenFPGA in interactive mode");
|
2020-01-22 21:20:10 -06:00
|
|
|
start_cmd.set_option_short_name(opt_interactive, "i");
|
|
|
|
|
2020-01-23 15:42:49 -06:00
|
|
|
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);
|
2020-01-22 21:20:10 -06:00
|
|
|
start_cmd.set_option_short_name(opt_script_mode, "f");
|
|
|
|
|
2020-01-23 15:42:49 -06:00
|
|
|
openfpga::CommandOptionId opt_help = start_cmd.add_option("help", false, "Help desk");
|
2020-01-22 21:20:10 -06:00
|
|
|
start_cmd.set_option_short_name(opt_help, "h");
|
|
|
|
|
|
|
|
/* Create a shell object
|
|
|
|
* Add two commands, which are
|
2020-01-23 14:24:35 -06:00
|
|
|
* 1. exit
|
|
|
|
* 2. help. This must the last to add
|
2020-01-22 21:20:10 -06:00
|
|
|
*/
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::Shell<OpenfpgaContext> shell("OpenFPGA");
|
2020-01-22 21:20:10 -06:00
|
|
|
|
2020-01-23 14:24:35 -06:00
|
|
|
shell.add_title(create_openfpga_title());
|
2020-01-22 21:20:10 -06:00
|
|
|
|
2020-01-23 15:42:49 -06:00
|
|
|
/* Add vpr commands */
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::add_vpr_commands(shell);
|
|
|
|
|
|
|
|
/* Add openfpga setup commands */
|
|
|
|
openfpga::add_openfpga_setup_commands(shell);
|
2020-01-22 21:20:10 -06:00
|
|
|
|
2020-01-23 15:42:49 -06:00
|
|
|
/* Add basic commands: exit, help, etc.
|
|
|
|
* Note:
|
|
|
|
* This MUST be the last command group to be added!
|
2020-01-22 21:20:10 -06:00
|
|
|
*/
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::add_basic_commands(shell);
|
2020-01-22 21:20:10 -06:00
|
|
|
|
|
|
|
/* Create the data base for the shell */
|
2020-01-23 14:24:35 -06:00
|
|
|
OpenfpgaContext openfpga_context;
|
2020-01-22 21:20:10 -06:00
|
|
|
|
|
|
|
/* Parse the option, to avoid issues, we use the command name to replace the argv[0] */
|
|
|
|
std::vector<std::string> cmd_opts;
|
|
|
|
cmd_opts.push_back(start_cmd.name());
|
|
|
|
for (int iarg = 1; iarg < argc; ++iarg) {
|
|
|
|
cmd_opts.push_back(std::string(argv[iarg]));
|
|
|
|
}
|
|
|
|
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::CommandContext start_cmd_context(start_cmd);
|
2020-01-22 21:20:10 -06:00
|
|
|
if (false == parse_command(cmd_opts, start_cmd, start_cmd_context)) {
|
|
|
|
/* Parse fail: Echo the command */
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::print_command_options(start_cmd);
|
2020-01-22 21:20:10 -06:00
|
|
|
} else {
|
|
|
|
/* Parse succeed. Start a shell */
|
|
|
|
if (true == start_cmd_context.option_enable(start_cmd, opt_interactive)) {
|
2020-01-23 14:24:35 -06:00
|
|
|
shell.run_interactive_mode(openfpga_context);
|
2020-01-22 21:20:10 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
2020-01-23 14:24:35 -06:00
|
|
|
openfpga_context);
|
2020-01-22 21:20:10 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Reach here there is something wrong, show the help desk */
|
2020-01-23 20:10:53 -06:00
|
|
|
openfpga::print_command_options(start_cmd);
|
2020-01-22 21:20:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|