From b9dab2baaf760d7ba5bb440e8467758349f4b2b1 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Wed, 8 Apr 2020 16:18:05 -0600 Subject: [PATCH] add exit codes to command execution in shell context --- .../libopenfpgashell/src/command_exit_codes.h | 27 +++++ libopenfpga/libopenfpgashell/src/shell.h | 55 ++++++++--- libopenfpga/libopenfpgashell/src/shell.tpp | 98 ++++++++++++++----- .../libopenfpgashell/test/test_shell.cpp | 10 +- .../check_netlist_naming_conflict.cpp | 20 +++- .../check_netlist_naming_conflict.h | 4 +- openfpga/src/base/openfpga_bitstream.cpp | 17 +++- openfpga/src/base/openfpga_bitstream.h | 8 +- openfpga/src/base/openfpga_build_fabric.cpp | 10 +- openfpga/src/base/openfpga_build_fabric.h | 4 +- openfpga/src/base/openfpga_link_arch.cpp | 12 ++- openfpga/src/base/openfpga_link_arch.h | 4 +- .../base/openfpga_lut_truth_table_fixup.cpp | 11 ++- .../src/base/openfpga_lut_truth_table_fixup.h | 4 +- openfpga/src/base/openfpga_pb_pin_fixup.cpp | 10 +- openfpga/src/base/openfpga_pb_pin_fixup.h | 4 +- openfpga/src/base/openfpga_read_arch.cpp | 17 +++- openfpga/src/base/openfpga_read_arch.h | 8 +- openfpga/src/base/openfpga_repack.cpp | 10 +- openfpga/src/base/openfpga_repack.h | 4 +- openfpga/src/base/openfpga_sdc.cpp | 17 +++- openfpga/src/base/openfpga_sdc.h | 8 +- openfpga/src/base/openfpga_verilog.cpp | 17 +++- openfpga/src/base/openfpga_verilog.h | 8 +- openfpga/src/base/openfpga_write_gsb.cpp | 10 +- openfpga/src/base/openfpga_write_gsb.h | 4 +- 26 files changed, 293 insertions(+), 108 deletions(-) create mode 100644 libopenfpga/libopenfpgashell/src/command_exit_codes.h diff --git a/libopenfpga/libopenfpgashell/src/command_exit_codes.h b/libopenfpga/libopenfpgashell/src/command_exit_codes.h new file mode 100644 index 000000000..f1490e533 --- /dev/null +++ b/libopenfpga/libopenfpgashell/src/command_exit_codes.h @@ -0,0 +1,27 @@ +#ifndef COMMAND_EXIT_CODES_H +#define COMMAND_EXIT_CODES_H + +/* Begin namespace openfpga */ +namespace openfpga { + +/********************************************************************* + * Exit codes to signal success/failure status of command execution + * Depend on the exit code, OpenFPGA shell will decide to continue or abort + ********************************************************************/ + +/* Never been executed */ +constexpr int CMD_EXEC_NONE = -1; + +/* Everything OK */ +constexpr int CMD_EXEC_SUCCESS = 0; + +/* Fatal error occurred, we have to abort and do not execute the rest of commands */ +constexpr int CMD_EXEC_FATAL_ERROR = 1; + +/* See minor errors but it will not impact the downsteam. We can continue to execute the rest of commands */ +constexpr int CMD_EXEC_MINOR_ERROR = 2; + + +} /* End namespace openfpga */ + +#endif diff --git a/libopenfpga/libopenfpgashell/src/shell.h b/libopenfpga/libopenfpgashell/src/shell.h index 427580010..1a49b313c 100644 --- a/libopenfpga/libopenfpgashell/src/shell.h +++ b/libopenfpga/libopenfpgashell/src/shell.h @@ -10,6 +10,7 @@ #include "vtr_range.h" #include "command.h" #include "command_context.h" +#include "command_exit_codes.h" #include "shell_fwd.h" /* Begin namespace openfpga */ @@ -88,25 +89,49 @@ class Shell { ShellCommandId add_command(const Command& cmd, const char* descr); void set_command_class(const ShellCommandId& cmd_id, const ShellCommandClassId& cmd_class_id); /* Link the execute function to a command - * We support here three types of functions to be executed in the shell - * 1. Standard function, including the data exchange and commands - * 2. Short function, including only the data exchange - * 3. Built-in function, including only the shell envoriment variables - * 4. Marco function, which directly call a macro function without command parsing + * We support here different types of functions to be executed in the shell * Users just need to specify the function object and its type will be automatically inferred + * + * Note that all the function should return exit codes complying to the shell_exit_code.h + * execept the internal functions + */ + + /* Standard function, including the data exchange and commands + * This function requires the data exchange to be constant + * This is designed for outputting functions requiring external data than the */ void set_command_const_execute_function(const ShellCommandId& cmd_id, - std::function exec_func); + std::function exec_func); + + /* Standard function, including the data exchange and commands + * This function allows modification to the data exchange + * This is designed for implementing functions requiring external data than the + */ void set_command_execute_function(const ShellCommandId& cmd_id, - std::function exec_func); + std::function exec_func); + + /* Short function, including only the data exchange + * This function requires the data exchange to be constant + * This is designed for outputting functions without external data than the + */ void set_command_const_execute_function(const ShellCommandId& cmd_id, - std::function exec_func); + std::function exec_func); + + /* Short function, including only the data exchange + * This function allows modification to the data exchange + * This is designed for internal implementing functions without external data than the + */ void set_command_execute_function(const ShellCommandId& cmd_id, - std::function exec_func); + std::function exec_func); + + /* Built-in function, including only the shell envoriment variables */ void set_command_execute_function(const ShellCommandId& cmd_id, std::function exec_func); + + /* Marco function, which directly call a macro function without command parsing */ void set_command_execute_function(const ShellCommandId& cmd_id, std::function exec_func); + void set_command_dependency(const ShellCommandId& cmd_id, const std::vector& cmd_dependency); ShellCommandClassId add_command_class(const char* name); @@ -126,7 +151,7 @@ class Shell { /* Execute a command, the command line is the user's input to launch a command * The common_context is the data structure to exchange data between commands */ - void execute_command(const char* cmd_line, T& common_context); + int execute_command(const char* cmd_line, T& common_context); private: /* Internal data */ /* Name of the shell, this will appear in the interactive mode */ std::string name_; @@ -162,10 +187,10 @@ class Shell { * 3. Built-in function, including only the shell envoriment variables * 4. Marco function, which directly call a macro function without command parsing */ - vtr::vector> command_const_execute_functions_; - vtr::vector> command_standard_execute_functions_; - vtr::vector> command_short_const_execute_functions_; - vtr::vector> command_short_execute_functions_; + vtr::vector> command_const_execute_functions_; + vtr::vector> command_standard_execute_functions_; + vtr::vector> command_short_const_execute_functions_; + vtr::vector> command_short_execute_functions_; vtr::vector> command_builtin_execute_functions_; vtr::vector> command_macro_execute_functions_; @@ -175,7 +200,7 @@ class Shell { vtr::vector command_execute_function_types_; /* A flag to indicate if the command has been executed */ - vtr::vector command_status_; + vtr::vector command_status_; /* Dependency graph for different commands, * This helps the shell interface to check if a command need other commands to be run before its execution diff --git a/libopenfpga/libopenfpgashell/src/shell.tpp b/libopenfpga/libopenfpgashell/src/shell.tpp index 5fe043f8e..69ec89ab9 100644 --- a/libopenfpga/libopenfpgashell/src/shell.tpp +++ b/libopenfpga/libopenfpgashell/src/shell.tpp @@ -131,7 +131,7 @@ ShellCommandId Shell::add_command(const Command& cmd, const char* descr) { command_short_execute_functions_.emplace_back(); command_builtin_execute_functions_.emplace_back(); command_macro_execute_functions_.emplace_back(); - command_status_.push_back(false); /* By default, the command should be marked as never executed */ + command_status_.push_back(CMD_EXEC_NONE); /* By default, the command should be marked as fatal error as it has been never executed */ command_dependencies_.emplace_back(); /* Register the name in the name2id map */ @@ -155,7 +155,7 @@ void Shell::set_command_class(const ShellCommandId& cmd_id, const ShellComman template void Shell::set_command_const_execute_function(const ShellCommandId& cmd_id, - std::function exec_func) { + std::function exec_func) { VTR_ASSERT(true == valid_command_id(cmd_id)); command_execute_function_types_[cmd_id] = CONST_STANDARD; command_const_execute_functions_[cmd_id] = exec_func; @@ -163,7 +163,7 @@ void Shell::set_command_const_execute_function(const ShellCommandId& cmd_id, template void Shell::set_command_execute_function(const ShellCommandId& cmd_id, - std::function exec_func) { + std::function exec_func) { VTR_ASSERT(true == valid_command_id(cmd_id)); command_execute_function_types_[cmd_id] = STANDARD; command_standard_execute_functions_[cmd_id] = exec_func; @@ -171,7 +171,7 @@ void Shell::set_command_execute_function(const ShellCommandId& cmd_id, template void Shell::set_command_const_execute_function(const ShellCommandId& cmd_id, - std::function exec_func) { + std::function exec_func) { VTR_ASSERT(true == valid_command_id(cmd_id)); command_execute_function_types_[cmd_id] = CONST_SHORT; command_short_const_execute_functions_[cmd_id] = exec_func; @@ -179,7 +179,7 @@ void Shell::set_command_const_execute_function(const ShellCommandId& cmd_id, template void Shell::set_command_execute_function(const ShellCommandId& cmd_id, - std::function exec_func) { + std::function exec_func) { VTR_ASSERT(true == valid_command_id(cmd_id)); command_execute_function_types_[cmd_id] = SHORT; command_short_execute_functions_[cmd_id] = exec_func; @@ -341,9 +341,15 @@ void Shell::run_script_mode(const char* script_file_name, T& context) { /* Process the command only when the full command line in ended */ if (!cmd_line.empty()) { VTR_LOG("\nCommand line to execute: %s\n", cmd_line.c_str()); - execute_command(cmd_line.c_str(), context); + int status = execute_command(cmd_line.c_str(), 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 */ + if (CMD_EXEC_FATAL_ERROR == status) { + VTR_LOG("Fatal error occurred!\nAbort and enter interactive mode\n"); + break; + } } } fp.close(); @@ -376,16 +382,49 @@ void Shell::print_commands() const { template void Shell::exit() const { + /* Check all the command status, if we see fatal errors or minor errors, we drop an error code */ + int exit_code = 0; + for (const int& status : command_status_) { + if ( (status == CMD_EXEC_FATAL_ERROR) + || (status == CMD_EXEC_MINOR_ERROR) ) { + exit_code = 1; + break; + } + } + + /* Show error message if we detect any errors */ + int num_err = 0; + if (0 != exit_code) { + VTR_LOG("\n"); + for (const ShellCommandId& cmd : commands()) { + if (command_status_[cmd] == CMD_EXEC_FATAL_ERROR) { + VTR_LOG_ERROR("Command '%s' execution has fatal errors\n", + commands_[cmd].name().c_str()); + num_err++; + } + + if (command_status_[cmd] == CMD_EXEC_MINOR_ERROR) { + VTR_LOG_ERROR("Command '%s' execution has minor errors\n", + commands_[cmd].name().c_str()); + num_err++; + } + } + } + + VTR_LOG("\nFinish execution with %d errors\n", + num_err); + VTR_LOG("\nThank you for using %s!\n", name().c_str()); - std::exit(0); + + std::exit(exit_code); } /************************************************************************ * Private executors ***********************************************************************/ template -void Shell::execute_command(const char* cmd_line, +int Shell::execute_command(const char* cmd_line, T& common_context) { /* Tokenize the line */ openfpga::StringToken tokenizer(cmd_line); @@ -396,17 +435,18 @@ void Shell::execute_command(const char* cmd_line, if (ShellCommandId::INVALID() == cmd_id) { VTR_LOG("Try to call a command '%s' which is not defined!\n", tokens[0].c_str()); - return; + return CMD_EXEC_FATAL_ERROR; } /* Check the dependency graph to see if all the prequistics have been met */ for (const ShellCommandId& dep_cmd : command_dependencies_[cmd_id]) { - if (false == command_status_[dep_cmd]) { + if ( (CMD_EXEC_NONE == command_status_[dep_cmd]) + || (CMD_EXEC_FATAL_ERROR == command_status_[dep_cmd]) ) { VTR_LOG("Command '%s' is required to be executed before command '%s'!\n", commands_[dep_cmd].name().c_str(), commands_[cmd_id].name().c_str()); /* Echo the command help desk */ print_command_options(commands_[cmd_id]); - return; + return CMD_EXEC_FATAL_ERROR; } } @@ -421,25 +461,22 @@ void Shell::execute_command(const char* cmd_line, argv[itok] = (char*)malloc((tokens[itok].length() + 1) * sizeof(char)); strcpy(argv[itok], tokens[itok].c_str()); } - /* Execute the marco function */ - command_macro_execute_functions_[cmd_id](tokens.size(), argv); + /* Execute the marco function and record the execution status */ + command_status_[cmd_id] = command_macro_execute_functions_[cmd_id](tokens.size(), argv); /* Free the argv */ for (size_t itok = 0; itok < tokens.size(); ++itok) { free(argv[itok]); } free(argv); - /* Change the status of the command */ - command_status_[cmd_id] = true; - /* Finish for macro command, return */ - return; + return command_status_[cmd_id]; } if (false == parse_command(tokens, commands_[cmd_id], command_contexts_[cmd_id])) { /* Echo the command */ print_command_options(commands_[cmd_id]); - return; + return CMD_EXEC_FATAL_ERROR; } /* Parse succeed. Let user to confirm selected options */ @@ -448,31 +485,38 @@ void Shell::execute_command(const char* cmd_line, /* Execute the command depending on the type of function ! */ switch (command_execute_function_types_[cmd_id]) { case CONST_STANDARD: - command_const_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]); + command_status_[cmd_id] = command_const_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]); break; case STANDARD: - command_standard_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]); + command_status_[cmd_id] = command_standard_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]); break; case CONST_SHORT: - command_short_const_execute_functions_[cmd_id](common_context); + command_status_[cmd_id] = command_short_const_execute_functions_[cmd_id](common_context); break; case SHORT: - command_short_execute_functions_[cmd_id](common_context); + command_status_[cmd_id] = command_short_execute_functions_[cmd_id](common_context); break; case BUILTIN: command_builtin_execute_functions_[cmd_id](); + /* Built-in execution is always correct */ + command_status_[cmd_id] = CMD_EXEC_SUCCESS; break; /* MACRO should be executed eariler in this function. It should not appear here */ default: /* This is not allowed! Error out */ - VTR_LOG("Invalid type of execute function for command '%s'!\n", - commands_[cmd_id].name().c_str()); + VTR_LOG_ERROR("Invalid type of execute function for command '%s'!\n", + commands_[cmd_id].name().c_str()); /* Exit the shell using the exit() function inside this class! */ - exit(); + return CMD_EXEC_FATAL_ERROR; } - /* Change the status of the command */ - command_status_[cmd_id] = true; + /* Forbid users to return the status CMD_EXEC_NONE */ + if (CMD_EXEC_NONE == command_status_[cmd_id]) { + VTR_LOG_ERROR("It is illegal to return never-executed status for an executed command!\n"); + return CMD_EXEC_FATAL_ERROR; + } + + return command_status_[cmd_id]; } /************************************************************************ diff --git a/libopenfpga/libopenfpgashell/test/test_shell.cpp b/libopenfpga/libopenfpgashell/test/test_shell.cpp index 649859d85..0edc257dd 100644 --- a/libopenfpga/libopenfpgashell/test/test_shell.cpp +++ b/libopenfpga/libopenfpgashell/test/test_shell.cpp @@ -15,16 +15,20 @@ class ShellContext { }; static -void shell_execute_set(ShellContext& context, +int shell_execute_set(ShellContext& context, const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_id = cmd.option("value"); /* Get the value of a in the command context */ context.a = std::atoi(cmd_context.option_value(cmd, opt_id).c_str()); + + return CMD_EXEC_SUCCESS; } static -void shell_execute_print(ShellContext& context) { +int shell_execute_print(ShellContext& context) { VTR_LOG("a=%d\n", context.a); + + return CMD_EXEC_SUCCESS; } static @@ -35,7 +39,7 @@ int shell_execute_print_macro(int argc, char** argv) { VTR_LOG("\t[%d]: %s\n", iarg, argv[iarg]); } - return 0; + return CMD_EXEC_SUCCESS; } int main(int argc, char** argv) { diff --git a/openfpga/src/annotation/check_netlist_naming_conflict.cpp b/openfpga/src/annotation/check_netlist_naming_conflict.cpp index 3470c9f0a..a8ab94384 100644 --- a/openfpga/src/annotation/check_netlist_naming_conflict.cpp +++ b/openfpga/src/annotation/check_netlist_naming_conflict.cpp @@ -11,6 +11,9 @@ #include "vtr_assert.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from archopenfpga library */ #include "write_xml_utils.h" @@ -213,8 +216,8 @@ void print_netlist_naming_fix_report(const std::string& fname, * in the users' BLIF netlist that violates the syntax of OpenFPGA * fabric generator, i.e., Verilog generator and SPICE generator *******************************************************************/ -void check_netlist_naming_conflict(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context) { +int check_netlist_naming_conflict(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { vtr::ScopedStartFinishTimer timer("Check naming violations of netlist blocks and nets"); /* By default, we replace all the illegal characters with '_' */ @@ -231,7 +234,15 @@ void check_netlist_naming_conflict(OpenfpgaContext& openfpga_context, num_conflicts); VTR_LOGV(0 == num_conflicts, "Check naming conflicts in the netlist passed.\n"); - return; + + /* If we see conflicts, report minor error */ + if (0 < num_conflicts) { + return CMD_EXEC_MINOR_ERROR; + } + + /* Otherwise, we should see zero conflicts */ + VTR_ASSERT(0 == num_conflicts); + return CMD_EXEC_SUCCESS; } /* If the auto correction is enabled, we apply a fix */ @@ -248,6 +259,9 @@ void check_netlist_naming_conflict(OpenfpgaContext& openfpga_context, cmd_context.option_value(cmd, opt_report).c_str()); } } + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/annotation/check_netlist_naming_conflict.h b/openfpga/src/annotation/check_netlist_naming_conflict.h index 54d86bca4..cad6c3963 100644 --- a/openfpga/src/annotation/check_netlist_naming_conflict.h +++ b/openfpga/src/annotation/check_netlist_naming_conflict.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void check_netlist_naming_conflict(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context); +int check_netlist_naming_conflict(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_bitstream.cpp b/openfpga/src/base/openfpga_bitstream.cpp index e472e7618..7e2a19fc4 100644 --- a/openfpga/src/base/openfpga_bitstream.cpp +++ b/openfpga/src/base/openfpga_bitstream.cpp @@ -5,6 +5,9 @@ #include "vtr_time.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from openfpgautil library */ #include "openfpga_digest.h" @@ -22,8 +25,8 @@ namespace openfpga { /******************************************************************** * A wrapper function to call the build_device_bitstream() in FPGA bitstream *******************************************************************/ -void fpga_bitstream(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int fpga_bitstream(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_verbose = cmd.option("verbose"); CommandOptionId opt_file = cmd.option("file"); @@ -41,19 +44,25 @@ void fpga_bitstream(OpenfpgaContext& openfpga_ctx, write_arch_independent_bitstream_to_xml_file(openfpga_ctx.bitstream_manager(), cmd_context.option_value(cmd, opt_file)); } + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } /******************************************************************** * A wrapper function to call the build_fabric_bitstream() in FPGA bitstream *******************************************************************/ -void build_fabric_bitstream(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int build_fabric_bitstream(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_verbose = cmd.option("verbose"); openfpga_ctx.mutable_fabric_bitstream() = build_fabric_dependent_bitstream(openfpga_ctx.bitstream_manager(), openfpga_ctx.module_graph(), cmd_context.option_enable(cmd, opt_verbose)); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_bitstream.h b/openfpga/src/base/openfpga_bitstream.h index 9dc2ad471..58f1c7e86 100644 --- a/openfpga/src/base/openfpga_bitstream.h +++ b/openfpga/src/base/openfpga_bitstream.h @@ -15,11 +15,11 @@ /* begin namespace openfpga */ namespace openfpga { -void fpga_bitstream(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int fpga_bitstream(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); -void build_fabric_bitstream(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int build_fabric_bitstream(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_build_fabric.cpp b/openfpga/src/base/openfpga_build_fabric.cpp index 4e8b44916..67203216a 100644 --- a/openfpga/src/base/openfpga_build_fabric.cpp +++ b/openfpga/src/base/openfpga_build_fabric.cpp @@ -5,6 +5,9 @@ #include "vtr_time.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + #include "device_rr_gsb.h" #include "device_rr_gsb_utils.h" #include "build_device_module.h" @@ -56,8 +59,8 @@ void compress_routing_hierarchy(OpenfpgaContext& openfpga_ctx, /******************************************************************** * Build the module graph for FPGA device *******************************************************************/ -void build_fabric(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int build_fabric(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_compress_routing = cmd.option("compress_routing"); CommandOptionId opt_duplicate_grid_pin = cmd.option("duplicate_grid_pin"); @@ -77,6 +80,9 @@ void build_fabric(OpenfpgaContext& openfpga_ctx, cmd_context.option_enable(cmd, opt_compress_routing), cmd_context.option_enable(cmd, opt_duplicate_grid_pin), cmd_context.option_enable(cmd, opt_verbose)); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_build_fabric.h b/openfpga/src/base/openfpga_build_fabric.h index 824ed63a1..3b63c7ab2 100644 --- a/openfpga/src/base/openfpga_build_fabric.h +++ b/openfpga/src/base/openfpga_build_fabric.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void build_fabric(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int build_fabric(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_link_arch.cpp b/openfpga/src/base/openfpga_link_arch.cpp index 34c98ee8d..65aef7cf8 100644 --- a/openfpga/src/base/openfpga_link_arch.cpp +++ b/openfpga/src/base/openfpga_link_arch.cpp @@ -8,6 +8,9 @@ #include "vtr_assert.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from vpr library */ #include "read_activity.h" @@ -59,8 +62,8 @@ bool is_vpr_rr_graph_supported(const RRGraph& rr_graph) { * - physical pb_graph nodes and pb_graph pins * - circuit models for global routing architecture *******************************************************************/ -void link_arch(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int link_arch(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { vtr::ScopedStartFinishTimer timer("Link OpenFPGA architecture to VPR architecture"); @@ -105,7 +108,7 @@ void link_arch(OpenfpgaContext& openfpga_ctx, * - DeviceRRGSB */ if (false == is_vpr_rr_graph_supported(g_vpr_ctx.device().rr_graph)) { - return; + return CMD_EXEC_FATAL_ERROR; } annotate_device_rr_gsb(g_vpr_ctx.device(), @@ -147,6 +150,9 @@ void link_arch(OpenfpgaContext& openfpga_ctx, annotate_simulation_setting(g_vpr_ctx.atom(), openfpga_ctx.net_activity(), openfpga_ctx.mutable_arch().sim_setting); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_link_arch.h b/openfpga/src/base/openfpga_link_arch.h index 742c29541..8eba64386 100644 --- a/openfpga/src/base/openfpga_link_arch.h +++ b/openfpga/src/base/openfpga_link_arch.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void link_arch(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context); +int link_arch(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_lut_truth_table_fixup.cpp b/openfpga/src/base/openfpga_lut_truth_table_fixup.cpp index 45ecbca31..396842dcd 100644 --- a/openfpga/src/base/openfpga_lut_truth_table_fixup.cpp +++ b/openfpga/src/base/openfpga_lut_truth_table_fixup.cpp @@ -7,6 +7,9 @@ #include "vtr_assert.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from vpr library */ #include "vpr_utils.h" @@ -182,7 +185,6 @@ void update_lut_tt_with_post_packing_results(const AtomContext& atom_ctx, } } - /******************************************************************** * Top-level function to fix up the lut truth table results after packing is done * The problem comes from a mismatch between the packing results and @@ -194,8 +196,8 @@ void update_lut_tt_with_post_packing_results(const AtomContext& atom_ctx, * This function aims to fix the mess after packing so that the truth table * can be synchronized *******************************************************************/ -void lut_truth_table_fixup(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context) { +int lut_truth_table_fixup(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { vtr::ScopedStartFinishTimer timer("Fix up LUT truth tables after packing optimization"); @@ -206,6 +208,9 @@ void lut_truth_table_fixup(OpenfpgaContext& openfpga_context, g_vpr_ctx.clustering(), openfpga_context.mutable_vpr_clustering_annotation(), cmd_context.option_enable(cmd, opt_verbose)); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_lut_truth_table_fixup.h b/openfpga/src/base/openfpga_lut_truth_table_fixup.h index f11abc7fb..d685a4b44 100644 --- a/openfpga/src/base/openfpga_lut_truth_table_fixup.h +++ b/openfpga/src/base/openfpga_lut_truth_table_fixup.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void lut_truth_table_fixup(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context); +int lut_truth_table_fixup(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_pb_pin_fixup.cpp b/openfpga/src/base/openfpga_pb_pin_fixup.cpp index cc91bdebe..2a8686190 100644 --- a/openfpga/src/base/openfpga_pb_pin_fixup.cpp +++ b/openfpga/src/base/openfpga_pb_pin_fixup.cpp @@ -7,6 +7,9 @@ #include "vtr_assert.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from vpr library */ #include "vpr_utils.h" @@ -254,8 +257,8 @@ void update_pb_pin_with_post_routing_results(const DeviceContext& device_ctx, * This function aims to fix the mess after routing so that the net mapping * can be synchronized *******************************************************************/ -void pb_pin_fixup(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context) { +int pb_pin_fixup(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { vtr::ScopedStartFinishTimer timer("Fix up pb pin mapping results after routing optimization"); @@ -268,6 +271,9 @@ void pb_pin_fixup(OpenfpgaContext& openfpga_context, openfpga_context.vpr_routing_annotation(), openfpga_context.mutable_vpr_clustering_annotation(), cmd_context.option_enable(cmd, opt_verbose)); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_pb_pin_fixup.h b/openfpga/src/base/openfpga_pb_pin_fixup.h index e924c6067..bab4e9565 100644 --- a/openfpga/src/base/openfpga_pb_pin_fixup.h +++ b/openfpga/src/base/openfpga_pb_pin_fixup.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void pb_pin_fixup(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context); +int pb_pin_fixup(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_read_arch.cpp b/openfpga/src/base/openfpga_read_arch.cpp index 1a36e85a3..214af1612 100644 --- a/openfpga/src/base/openfpga_read_arch.cpp +++ b/openfpga/src/base/openfpga_read_arch.cpp @@ -5,6 +5,9 @@ /* Headers from vtrutil library */ #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from archopenfpga library */ #include "read_xml_openfpga_arch.h" #include "check_circuit_library.h" @@ -22,8 +25,8 @@ namespace openfpga { * The command will accept an option '--file' which is the architecture * file provided by users *******************************************************************/ -void read_arch(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context) { +int read_arch(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { /* Check the option '--file' is enabled or not * Actually, it must be enabled as the shell interface will check * before reaching this fuction @@ -44,6 +47,9 @@ void read_arch(OpenfpgaContext& openfpga_context, * 3. Simulation settings (TODO) */ check_circuit_library(openfpga_context.arch().circuit_lib); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } /******************************************************************** @@ -53,8 +59,8 @@ void read_arch(OpenfpgaContext& openfpga_context, * The command will accept an option '--file' which is the architecture * file provided by users *******************************************************************/ -void write_arch(const OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context) { +int write_arch(const OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context) { /* Check the option '--file' is enabled or not * Actually, it must be enabled as the shell interface will check * before reaching this fuction @@ -68,6 +74,9 @@ void write_arch(const OpenfpgaContext& openfpga_context, VTR_LOG("Writing XML architecture to '%s'...\n", arch_file_name.c_str()); write_xml_openfpga_arch(arch_file_name.c_str(), openfpga_context.arch()); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_read_arch.h b/openfpga/src/base/openfpga_read_arch.h index dcc04d77a..b664a7b3e 100644 --- a/openfpga/src/base/openfpga_read_arch.h +++ b/openfpga/src/base/openfpga_read_arch.h @@ -15,11 +15,11 @@ /* begin namespace openfpga */ namespace openfpga { -void read_arch(OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context); +int read_arch(OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); -void write_arch(const OpenfpgaContext& openfpga_context, - const Command& cmd, const CommandContext& cmd_context); +int write_arch(const OpenfpgaContext& openfpga_context, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_repack.cpp b/openfpga/src/base/openfpga_repack.cpp index 91c6b4798..fe0529d04 100644 --- a/openfpga/src/base/openfpga_repack.cpp +++ b/openfpga/src/base/openfpga_repack.cpp @@ -5,6 +5,9 @@ #include "vtr_time.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + #include "build_physical_truth_table.h" #include "repack.h" #include "openfpga_repack.h" @@ -18,8 +21,8 @@ namespace openfpga { /******************************************************************** * A wrapper function to call the fabric_verilog function of FPGA-Verilog *******************************************************************/ -void repack(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int repack(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_verbose = cmd.option("verbose"); @@ -35,6 +38,9 @@ void repack(OpenfpgaContext& openfpga_ctx, g_vpr_ctx.clustering(), openfpga_ctx.vpr_device_annotation(), openfpga_ctx.arch().circuit_lib); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_repack.h b/openfpga/src/base/openfpga_repack.h index 0fce62f78..83e4bce63 100644 --- a/openfpga/src/base/openfpga_repack.h +++ b/openfpga/src/base/openfpga_repack.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void repack(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int repack(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_sdc.cpp b/openfpga/src/base/openfpga_sdc.cpp index 06b594e73..21a3ab8fb 100644 --- a/openfpga/src/base/openfpga_sdc.cpp +++ b/openfpga/src/base/openfpga_sdc.cpp @@ -5,6 +5,9 @@ #include "vtr_time.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + /* Headers from openfpgautil library */ #include "openfpga_digest.h" @@ -22,8 +25,8 @@ namespace openfpga { /******************************************************************** * A wrapper function to call the PnR SDC generator of FPGA-SDC *******************************************************************/ -void write_pnr_sdc(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int write_pnr_sdc(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_output_dir = cmd.option("file"); CommandOptionId opt_constrain_global_port = cmd.option("constrain_global_port"); @@ -80,13 +83,16 @@ void write_pnr_sdc(OpenfpgaContext& openfpga_ctx, global_ports, openfpga_ctx.flow_manager().compress_routing()); } + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } /******************************************************************** * A wrapper function to call the analysis SDC generator of FPGA-SDC *******************************************************************/ -void write_analysis_sdc(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int write_analysis_sdc(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_output_dir = cmd.option("file"); @@ -114,6 +120,9 @@ void write_analysis_sdc(OpenfpgaContext& openfpga_ctx, global_ports, openfpga_ctx.flow_manager().compress_routing()); } + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_sdc.h b/openfpga/src/base/openfpga_sdc.h index 110a8cd72..99a87f899 100644 --- a/openfpga/src/base/openfpga_sdc.h +++ b/openfpga/src/base/openfpga_sdc.h @@ -15,11 +15,11 @@ /* begin namespace openfpga */ namespace openfpga { -void write_pnr_sdc(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int write_pnr_sdc(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); -void write_analysis_sdc(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int write_analysis_sdc(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_verilog.cpp b/openfpga/src/base/openfpga_verilog.cpp index 1ce23a1d4..c79b68fc2 100644 --- a/openfpga/src/base/openfpga_verilog.cpp +++ b/openfpga/src/base/openfpga_verilog.cpp @@ -5,6 +5,9 @@ #include "vtr_time.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + #include "verilog_api.h" #include "openfpga_verilog.h" @@ -17,8 +20,8 @@ namespace openfpga { /******************************************************************** * A wrapper function to call the fabric Verilog generator of FPGA-Verilog *******************************************************************/ -void write_fabric_verilog(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int write_fabric_verilog(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_output_dir = cmd.option("file"); CommandOptionId opt_explicit_port_mapping = cmd.option("explicit_port_mapping"); @@ -48,13 +51,16 @@ void write_fabric_verilog(OpenfpgaContext& openfpga_ctx, openfpga_ctx.vpr_device_annotation(), openfpga_ctx.device_rr_gsb(), options); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } /******************************************************************** * A wrapper function to call the Verilog testbench generator of FPGA-Verilog *******************************************************************/ -void write_verilog_testbench(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int write_verilog_testbench(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { CommandOptionId opt_output_dir = cmd.option("file"); CommandOptionId opt_reference_benchmark = cmd.option("reference_benchmark_file_path"); @@ -87,6 +93,9 @@ void write_verilog_testbench(OpenfpgaContext& openfpga_ctx, openfpga_ctx.arch().sim_setting, openfpga_ctx.arch().config_protocol.type(), options); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_verilog.h b/openfpga/src/base/openfpga_verilog.h index faf8cf6b0..096039aab 100644 --- a/openfpga/src/base/openfpga_verilog.h +++ b/openfpga/src/base/openfpga_verilog.h @@ -15,11 +15,11 @@ /* begin namespace openfpga */ namespace openfpga { -void write_fabric_verilog(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int write_fabric_verilog(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); -void write_verilog_testbench(OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int write_verilog_testbench(OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_write_gsb.cpp b/openfpga/src/base/openfpga_write_gsb.cpp index 9c367ebfb..cdb833c75 100644 --- a/openfpga/src/base/openfpga_write_gsb.cpp +++ b/openfpga/src/base/openfpga_write_gsb.cpp @@ -5,6 +5,9 @@ #include "vtr_time.h" #include "vtr_log.h" +/* Headers from openfpgashell library */ +#include "command_exit_codes.h" + #include "write_xml_device_rr_gsb.h" #include "openfpga_write_gsb.h" @@ -19,8 +22,8 @@ namespace openfpga { * Write internal structrure of all the General Switch Blocks (GSBs) * to an XML file *******************************************************************/ -void write_gsb(const OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context) { +int write_gsb(const OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context) { /* Check the option '--file' is enabled or not * Actually, it must be enabled as the shell interface will check @@ -38,6 +41,9 @@ void write_gsb(const OpenfpgaContext& openfpga_ctx, g_vpr_ctx.device().rr_graph, openfpga_ctx.device_rr_gsb(), cmd_context.option_enable(cmd, opt_verbose)); + + /* TODO: should identify the error code from internal function execution */ + return CMD_EXEC_SUCCESS; } } /* end namespace openfpga */ diff --git a/openfpga/src/base/openfpga_write_gsb.h b/openfpga/src/base/openfpga_write_gsb.h index 4f7110717..206e6cd5a 100644 --- a/openfpga/src/base/openfpga_write_gsb.h +++ b/openfpga/src/base/openfpga_write_gsb.h @@ -15,8 +15,8 @@ /* begin namespace openfpga */ namespace openfpga { -void write_gsb(const OpenfpgaContext& openfpga_ctx, - const Command& cmd, const CommandContext& cmd_context); +int write_gsb(const OpenfpgaContext& openfpga_ctx, + const Command& cmd, const CommandContext& cmd_context); } /* end namespace openfpga */