add --depth option to fabric hierarchy writer

This commit is contained in:
tangxifan 2020-05-05 16:40:41 -06:00
parent d9dc7160a7
commit 5a8c05378e
4 changed files with 35 additions and 3 deletions

View File

@ -102,11 +102,25 @@ int write_fabric_hierarchy(const OpenfpgaContext& openfpga_ctx,
VTR_ASSERT(true == cmd_context.option_enable(cmd, opt_file)); VTR_ASSERT(true == cmd_context.option_enable(cmd, opt_file));
VTR_ASSERT(false == cmd_context.option_value(cmd, opt_file).empty()); VTR_ASSERT(false == cmd_context.option_value(cmd, opt_file).empty());
/* Default depth requirement, will not stop until the leaf */
int depth = -1;
CommandOptionId opt_depth = cmd.option("depth");
if (true == cmd_context.option_enable(cmd, opt_depth)) {
depth = std::atoi(cmd_context.option_value(cmd, opt_depth).c_str());
/* Error out if we have negative depth */
if (0 > depth) {
VTR_LOG_ERROR("Invalid depth '%d' which should be 0 or a positive number!\n",
depth);
return CMD_EXEC_FATAL_ERROR;
}
}
std::string hie_file_name = cmd_context.option_value(cmd, opt_file); std::string hie_file_name = cmd_context.option_value(cmd, opt_file);
/* Write hierarchy to a file */ /* Write hierarchy to a file */
return write_fabric_hierarchy_to_text_file(openfpga_ctx.module_graph(), return write_fabric_hierarchy_to_text_file(openfpga_ctx.module_graph(),
hie_file_name, hie_file_name,
size_t(depth),
cmd_context.option_enable(cmd, opt_verbose)); cmd_context.option_enable(cmd, opt_verbose));
} }

View File

@ -255,6 +255,10 @@ ShellCommandId add_openfpga_write_fabric_hierarchy_command(openfpga::Shell<Openf
shell_cmd.set_option_short_name(opt_file, "f"); shell_cmd.set_option_short_name(opt_file, "f");
shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING); shell_cmd.set_option_require_value(opt_file, openfpga::OPT_STRING);
/* Add an option '--depth' */
CommandOptionId opt_depth = shell_cmd.add_option("depth", false, "Specify the depth of hierarchy to which the writer should stop");
shell_cmd.set_option_require_value(opt_depth, openfpga::OPT_INT);
/* Add an option '--verbose' */ /* Add an option '--verbose' */
shell_cmd.add_option("verbose", false, "Show verbose outputs"); shell_cmd.add_option("verbose", false, "Show verbose outputs");

View File

@ -24,17 +24,23 @@ namespace openfpga {
***************************************************************************************/ ***************************************************************************************/
static static
int rec_output_module_hierarchy_to_text_file(std::fstream& fp, int rec_output_module_hierarchy_to_text_file(std::fstream& fp,
const size_t& hie_depth, const size_t& hie_depth_to_stop,
const size_t& current_hie_depth,
const ModuleManager& module_manager, const ModuleManager& module_manager,
const ModuleId& parent_module, const ModuleId& parent_module,
const bool& verbose) { const bool& verbose) {
/* Stop if hierarchy depth is beyond the stop line */
if (hie_depth_to_stop < current_hie_depth) {
return 0;
}
if (false == valid_file_stream(fp)) { if (false == valid_file_stream(fp)) {
return 2; return 2;
} }
/* Iterate over all the child module */ /* Iterate over all the child module */
for (const ModuleId& child_module : module_manager.child_modules(parent_module)) { for (const ModuleId& child_module : module_manager.child_modules(parent_module)) {
if (false == write_space_to_file(fp, hie_depth)) { if (false == write_space_to_file(fp, current_hie_depth)) {
return 2; return 2;
} }
@ -50,7 +56,8 @@ int rec_output_module_hierarchy_to_text_file(std::fstream& fp,
/* Go to next level */ /* Go to next level */
int status = rec_output_module_hierarchy_to_text_file(fp, int status = rec_output_module_hierarchy_to_text_file(fp,
hie_depth + 1, /* Increment the depth for the next level */ hie_depth_to_stop,
current_hie_depth + 1, /* Increment the depth for the next level */
module_manager, module_manager,
child_module, child_module,
verbose); verbose);
@ -76,6 +83,7 @@ int rec_output_module_hierarchy_to_text_file(std::fstream& fp,
***************************************************************************************/ ***************************************************************************************/
int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager, int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
const std::string& fname, const std::string& fname,
const size_t& hie_depth_to_stop,
const bool& verbose) { const bool& verbose) {
std::string timer_message = std::string("Write fabric hierarchy to plain-text file '") + fname + std::string("'"); std::string timer_message = std::string("Write fabric hierarchy to plain-text file '") + fname + std::string("'");
@ -111,10 +119,15 @@ int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
/* Record current depth of module: top module is the root with 0 depth */ /* Record current depth of module: top module is the root with 0 depth */
size_t hie_depth = 0; size_t hie_depth = 0;
if (hie_depth_to_stop < hie_depth) {
return 0;
}
fp << top_module_name << "\n"; fp << top_module_name << "\n";
/* Visit child module recursively and output the hierarchy */ /* Visit child module recursively and output the hierarchy */
int err_code = rec_output_module_hierarchy_to_text_file(fp, int err_code = rec_output_module_hierarchy_to_text_file(fp,
hie_depth_to_stop,
hie_depth + 1, /* Start with level 1 */ hie_depth + 1, /* Start with level 1 */
module_manager, module_manager,
top_module, top_module,

View File

@ -16,6 +16,7 @@ namespace openfpga {
int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager, int write_fabric_hierarchy_to_text_file(const ModuleManager& module_manager,
const std::string& fname, const std::string& fname,
const size_t& hie_depth_to_stop,
const bool& verbose); const bool& verbose);
} /* end namespace openfpga */ } /* end namespace openfpga */