[core] code format
This commit is contained in:
parent
a2fb84dfa9
commit
bf24382f19
|
@ -270,7 +270,8 @@ template <class T>
|
|||
int write_fabric_hierarchy_template(const T& openfpga_ctx, const Command& cmd,
|
||||
const CommandContext& cmd_context) {
|
||||
CommandOptionId opt_verbose = cmd.option("verbose");
|
||||
CommandOptionId opt_exclude_empty_modules = cmd.option("exclude_empty_modules");
|
||||
CommandOptionId opt_exclude_empty_modules =
|
||||
cmd.option("exclude_empty_modules");
|
||||
|
||||
/* Check the option '--file' is enabled or not
|
||||
* Actually, it must be enabled as the shell interface will check
|
||||
|
@ -281,7 +282,8 @@ int write_fabric_hierarchy_template(const T& openfpga_ctx, const Command& cmd,
|
|||
VTR_ASSERT(false == cmd_context.option_value(cmd, opt_file).empty());
|
||||
|
||||
CommandOptionId opt_module = cmd.option("module");
|
||||
std::string root_module = openfpga_ctx.module_name_map().name(generate_fpga_top_module_name());
|
||||
std::string root_module =
|
||||
openfpga_ctx.module_name_map().name(generate_fpga_top_module_name());
|
||||
if (true == cmd_context.option_enable(cmd, opt_module)) {
|
||||
root_module = cmd_context.option_value(cmd, opt_module);
|
||||
}
|
||||
|
@ -309,12 +311,8 @@ int write_fabric_hierarchy_template(const T& openfpga_ctx, const Command& cmd,
|
|||
|
||||
/* Write hierarchy to a file */
|
||||
return write_fabric_hierarchy_to_text_file(
|
||||
openfpga_ctx.module_graph(),
|
||||
openfpga_ctx.module_name_map(),
|
||||
hie_file_name,
|
||||
root_module,
|
||||
filter,
|
||||
size_t(depth),
|
||||
openfpga_ctx.module_graph(), openfpga_ctx.module_name_map(), hie_file_name,
|
||||
root_module, filter, size_t(depth),
|
||||
cmd_context.option_enable(cmd, opt_exclude_empty_modules),
|
||||
cmd_context.option_enable(cmd, opt_verbose));
|
||||
}
|
||||
|
|
|
@ -463,10 +463,15 @@ ShellCommandId add_write_fabric_hierarchy_command_template(
|
|||
|
||||
/* Add an option '--module' */
|
||||
CommandOptionId opt_module = shell_cmd.add_option(
|
||||
"module", false, "Specify the root module name(s) which should be considered. By default, it is fpga_top. Regular expression is supported");
|
||||
"module", false,
|
||||
"Specify the root module name(s) which should be considered. By default, "
|
||||
"it is fpga_top. Regular expression is supported");
|
||||
shell_cmd.set_option_require_value(opt_module, openfpga::OPT_STRING);
|
||||
CommandOptionId opt_filter = shell_cmd.add_option(
|
||||
"filter", false, "Specify the filter which allows user to select modules to appear under each root module tree. By default, it is *. Regular expression is supported");
|
||||
CommandOptionId opt_filter =
|
||||
shell_cmd.add_option("filter", false,
|
||||
"Specify the filter which allows user to select "
|
||||
"modules to appear under each root module tree. By "
|
||||
"default, it is *. Regular expression is supported");
|
||||
shell_cmd.set_option_require_value(opt_filter, openfpga::OPT_STRING);
|
||||
|
||||
/* Add an option '--depth' */
|
||||
|
@ -475,7 +480,9 @@ ShellCommandId add_write_fabric_hierarchy_command_template(
|
|||
"Specify the depth of hierarchy to which the writer should stop");
|
||||
shell_cmd.set_option_require_value(opt_depth, openfpga::OPT_INT);
|
||||
|
||||
shell_cmd.add_option("exclude_empty_modules", false, "Exclude modules with no qualified children (match the names defined through filter) from the output file");
|
||||
shell_cmd.add_option("exclude_empty_modules", false,
|
||||
"Exclude modules with no qualified children (match the "
|
||||
"names defined through filter) from the output file");
|
||||
|
||||
/* Add an option '--verbose' */
|
||||
shell_cmd.add_option("verbose", false, "Show verbose outputs");
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
#include "vtr_time.h"
|
||||
|
||||
/* Headers from openfpgautil library */
|
||||
#include "command_exit_codes.h"
|
||||
#include "fabric_hierarchy_writer.h"
|
||||
#include "openfpga_digest.h"
|
||||
#include "openfpga_naming.h"
|
||||
#include "command_exit_codes.h"
|
||||
|
||||
/* begin namespace openfpga */
|
||||
namespace openfpga {
|
||||
|
@ -24,7 +24,8 @@ static bool module_filter_all_children(const ModuleManager& module_manager,
|
|||
for (const ModuleId& child_module :
|
||||
module_manager.child_modules(curr_module)) {
|
||||
/* Filter out the names which do not match the pattern */
|
||||
std::string child_module_name = module_name_map.name(module_manager.module_name(child_module));
|
||||
std::string child_module_name =
|
||||
module_name_map.name(module_manager.module_name(child_module));
|
||||
std::string pattern = module_name_filter;
|
||||
std::regex star_replace("\\*");
|
||||
std::regex questionmark_replace("\\?");
|
||||
|
@ -48,10 +49,8 @@ static bool module_filter_all_children(const ModuleManager& module_manager,
|
|||
static int rec_output_module_hierarchy_to_text_file(
|
||||
std::fstream& fp, const size_t& hie_depth_to_stop,
|
||||
const size_t& current_hie_depth, const ModuleManager& module_manager,
|
||||
const ModuleId& parent_module,
|
||||
const ModuleNameMap& module_name_map,
|
||||
const std::string& module_name_filter,
|
||||
const bool& verbose) {
|
||||
const ModuleId& parent_module, const ModuleNameMap& module_name_map,
|
||||
const std::string& module_name_filter, const bool& verbose) {
|
||||
/* Stop if hierarchy depth is beyond the stop line */
|
||||
if (hie_depth_to_stop < current_hie_depth) {
|
||||
return CMD_EXEC_SUCCESS;
|
||||
|
@ -61,11 +60,13 @@ static int rec_output_module_hierarchy_to_text_file(
|
|||
return CMD_EXEC_FATAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check if all the child module has not qualified grand-child, use leaf for this level */
|
||||
/* Check if all the child module has not qualified grand-child, use leaf for
|
||||
* this level */
|
||||
bool use_list = true;
|
||||
for (const ModuleId& child_module :
|
||||
module_manager.child_modules(parent_module)) {
|
||||
if (!module_filter_all_children(module_manager, child_module, module_name_map, module_name_filter)) {
|
||||
if (!module_filter_all_children(module_manager, child_module,
|
||||
module_name_map, module_name_filter)) {
|
||||
use_list = false;
|
||||
break;
|
||||
}
|
||||
|
@ -79,14 +80,17 @@ static int rec_output_module_hierarchy_to_text_file(
|
|||
}
|
||||
|
||||
if (true != module_manager.valid_module_id(child_module)) {
|
||||
VTR_LOGV_ERROR(verbose, "Unable to find the child module '%s' under its parent '%s'!\n",
|
||||
module_manager.module_name(child_module).c_str(),
|
||||
module_manager.module_name(parent_module).c_str());
|
||||
VTR_LOGV_ERROR(
|
||||
verbose,
|
||||
"Unable to find the child module '%s' under its parent '%s'!\n",
|
||||
module_manager.module_name(child_module).c_str(),
|
||||
module_manager.module_name(parent_module).c_str());
|
||||
return CMD_EXEC_FATAL_ERROR;
|
||||
}
|
||||
|
||||
/* Filter out the names which do not match the pattern */
|
||||
std::string child_module_name = module_name_map.name(module_manager.module_name(child_module));
|
||||
std::string child_module_name =
|
||||
module_name_map.name(module_manager.module_name(child_module));
|
||||
std::string pattern = module_name_filter;
|
||||
std::regex star_replace("\\*");
|
||||
std::regex questionmark_replace("\\?");
|
||||
|
@ -116,7 +120,8 @@ static int rec_output_module_hierarchy_to_text_file(
|
|||
int status = rec_output_module_hierarchy_to_text_file(
|
||||
fp, hie_depth_to_stop,
|
||||
current_hie_depth + 1, /* Increment the depth for the next level */
|
||||
module_manager, child_module, module_name_map, module_name_filter, verbose);
|
||||
module_manager, child_module, module_name_map, module_name_filter,
|
||||
verbose);
|
||||
if (status != CMD_EXEC_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
@ -137,14 +142,11 @@ static int rec_output_module_hierarchy_to_text_file(
|
|||
* Return 1 if there are more serious bugs in the architecture
|
||||
* Return 2 if fail when creating files
|
||||
***************************************************************************************/
|
||||
int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
|
||||
const ModuleNameMap& module_name_map,
|
||||
const std::string& fname,
|
||||
const std::string& root_module_names,
|
||||
const std::string& module_name_filter,
|
||||
const size_t& hie_depth_to_stop,
|
||||
const bool& exclude_empty_modules,
|
||||
const bool& verbose) {
|
||||
int write_fabric_hierarchy_to_text_file(
|
||||
const ModuleManager& module_manager, const ModuleNameMap& module_name_map,
|
||||
const std::string& fname, const std::string& root_module_names,
|
||||
const std::string& module_name_filter, const size_t& hie_depth_to_stop,
|
||||
const bool& exclude_empty_modules, const bool& verbose) {
|
||||
std::string timer_message =
|
||||
std::string("Write fabric hierarchy to plain-text file '") + fname +
|
||||
std::string("'");
|
||||
|
@ -172,7 +174,8 @@ int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
|
|||
/* Use regular expression to capture the module whose name matches the pattern
|
||||
*/
|
||||
for (ModuleId curr_module : module_manager.modules()) {
|
||||
std::string curr_module_name = module_name_map.name(module_manager.module_name(curr_module));
|
||||
std::string curr_module_name =
|
||||
module_name_map.name(module_manager.module_name(curr_module));
|
||||
std::string pattern = root_module_names;
|
||||
std::regex star_replace("\\*");
|
||||
std::regex questionmark_replace("\\?");
|
||||
|
@ -184,7 +187,9 @@ int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
|
|||
continue;
|
||||
}
|
||||
/* Filter out module without children if required */
|
||||
if (exclude_empty_modules && module_filter_all_children(module_manager, curr_module, module_name_map, module_name_filter)) {
|
||||
if (exclude_empty_modules &&
|
||||
module_filter_all_children(module_manager, curr_module, module_name_map,
|
||||
module_name_filter)) {
|
||||
continue;
|
||||
}
|
||||
/* Record current depth of module: top module is the root with 0 depth */
|
||||
|
@ -196,8 +201,9 @@ int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
|
|||
/* Visit child module recursively and output the hierarchy */
|
||||
int err_code = rec_output_module_hierarchy_to_text_file(
|
||||
fp, hie_depth_to_stop, hie_depth + 1, /* Start with level 1 */
|
||||
module_manager, curr_module, module_name_map, module_name_filter, verbose);
|
||||
/* Catch error code and exit if required */
|
||||
module_manager, curr_module, module_name_map, module_name_filter,
|
||||
verbose);
|
||||
/* Catch error code and exit if required */
|
||||
if (err_code == CMD_EXEC_FATAL_ERROR) {
|
||||
return err_code;
|
||||
}
|
||||
|
@ -205,8 +211,10 @@ int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
|
|||
}
|
||||
|
||||
if (cnt == 0) {
|
||||
VTR_LOGV_ERROR(verbose, "Unable to find any module matching the root module name pattern '%s'!\n",
|
||||
root_module_names.c_str());
|
||||
VTR_LOGV_ERROR(
|
||||
verbose,
|
||||
"Unable to find any module matching the root module name pattern '%s'!\n",
|
||||
root_module_names.c_str());
|
||||
return CMD_EXEC_FATAL_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
/* begin namespace openfpga */
|
||||
namespace openfpga {
|
||||
|
||||
int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
|
||||
const ModuleNameMap& module_name_map,
|
||||
const std::string& fname,
|
||||
const std::string& root_module_names,
|
||||
const std::string& module_name_filter,
|
||||
const size_t& hie_depth_to_stop,
|
||||
const bool& exclude_empty_modules,
|
||||
const bool& verbose);
|
||||
int write_fabric_hierarchy_to_text_file(
|
||||
const ModuleManager& module_manager, const ModuleNameMap& module_name_map,
|
||||
const std::string& fname, const std::string& root_module_names,
|
||||
const std::string& module_name_filter, const size_t& hie_depth_to_stop,
|
||||
const bool& exclude_empty_modules, const bool& verbose);
|
||||
|
||||
} /* end namespace openfpga */
|
||||
|
||||
|
|
Loading…
Reference in New Issue