[core] code format

This commit is contained in:
tangxifan 2023-09-23 12:15:53 -07:00
parent 11de8965a8
commit edb0e687f1
3 changed files with 52 additions and 40 deletions

View File

@ -361,7 +361,7 @@ int rename_modules_template(T& openfpga_ctx, const Command& cmd,
std::string file_name = cmd_context.option_value(cmd, opt_file); std::string file_name = cmd_context.option_value(cmd, opt_file);
int status = CMD_EXEC_SUCCESS; int status = CMD_EXEC_SUCCESS;
ModuleNameMap user_module_name_map; ModuleNameMap user_module_name_map;
status = read_xml_module_name_map(file_name.c_str(), user_module_name_map); status = read_xml_module_name_map(file_name.c_str(), user_module_name_map);
if (status != CMD_EXEC_SUCCESS) { if (status != CMD_EXEC_SUCCESS) {
@ -369,15 +369,17 @@ int rename_modules_template(T& openfpga_ctx, const Command& cmd,
} }
/* Apply renaming on the user version */ /* Apply renaming on the user version */
status = partial_rename_fabric_modules(openfpga_ctx.mutable_module_graph(), status = partial_rename_fabric_modules(
user_module_name_map, openfpga_ctx.mutable_module_graph(), user_module_name_map,
cmd_context.option_enable(cmd, opt_verbose)); cmd_context.option_enable(cmd, opt_verbose));
if (status != CMD_EXEC_SUCCESS) { if (status != CMD_EXEC_SUCCESS) {
return CMD_EXEC_FATAL_ERROR; return CMD_EXEC_FATAL_ERROR;
} }
/* Update the internal version of module name map based on users' version */ /* Update the internal version of module name map based on users' version */
return update_module_name_map_with_user_version(openfpga_ctx.mutable_module_name_map(), user_module_name_map, cmd_context.option_enable(cmd, opt_verbose)); return update_module_name_map_with_user_version(
openfpga_ctx.mutable_module_name_map(), user_module_name_map,
cmd_context.option_enable(cmd, opt_verbose));
} }
/******************************************************************** /********************************************************************

View File

@ -92,7 +92,8 @@ int update_module_map_name_with_indexing_names(ModuleNameMap& module_name_map,
return CMD_EXEC_SUCCESS; return CMD_EXEC_SUCCESS;
} }
/** @brief Apply module renaming for all the modules. Require the module name map cover all the modules */ /** @brief Apply module renaming for all the modules. Require the module name
* map cover all the modules */
int rename_fabric_modules(ModuleManager& module_manager, int rename_fabric_modules(ModuleManager& module_manager,
const ModuleNameMap& module_name_map, const ModuleNameMap& module_name_map,
const bool& verbose) { const bool& verbose) {
@ -102,15 +103,15 @@ int rename_fabric_modules(ModuleManager& module_manager,
std::string curr_module_name = module_manager.module_name(curr_module); std::string curr_module_name = module_manager.module_name(curr_module);
/* Error out if the new name does not exist ! */ /* Error out if the new name does not exist ! */
if (!module_name_map.name_exist(curr_module_name)) { if (!module_name_map.name_exist(curr_module_name)) {
VTR_LOG_ERROR("The built-in module name '%s' does not exist! Abort renaming...\n", curr_module_name.c_str()); VTR_LOG_ERROR(
"The built-in module name '%s' does not exist! Abort renaming...\n",
curr_module_name.c_str());
return CMD_EXEC_FATAL_ERROR; return CMD_EXEC_FATAL_ERROR;
} }
std::string new_name = std::string new_name = module_name_map.name(curr_module_name);
module_name_map.name(curr_module_name);
if (new_name != curr_module_name) { if (new_name != curr_module_name) {
VTR_LOGV(verbose, "Rename module '%s' to its new name '%s'\n", VTR_LOGV(verbose, "Rename module '%s' to its new name '%s'\n",
curr_module_name.c_str(), curr_module_name.c_str(), new_name.c_str());
new_name.c_str());
module_manager.set_module_name(curr_module, new_name); module_manager.set_module_name(curr_module, new_name);
} }
cnt++; cnt++;
@ -119,24 +120,26 @@ int rename_fabric_modules(ModuleManager& module_manager,
return status; return status;
} }
/** @brief Apply module renaming based on the pairs given by module name map only. So not all the modules are renamed. So the module name map just cover a subset of modules */ /** @brief Apply module renaming based on the pairs given by module name map
* only. So not all the modules are renamed. So the module name map just cover a
* subset of modules */
int partial_rename_fabric_modules(ModuleManager& module_manager, int partial_rename_fabric_modules(ModuleManager& module_manager,
const ModuleNameMap& module_name_map, const ModuleNameMap& module_name_map,
const bool& verbose) { const bool& verbose) {
int status = CMD_EXEC_SUCCESS; int status = CMD_EXEC_SUCCESS;
size_t cnt = 0; size_t cnt = 0;
for (std::string built_in_name : module_name_map.tags()) { for (std::string built_in_name : module_name_map.tags()) {
ModuleId curr_module = module_manager.find_module(built_in_name); ModuleId curr_module = module_manager.find_module(built_in_name);
if (!module_manager.valid_module_id(curr_module)) { if (!module_manager.valid_module_id(curr_module)) {
VTR_LOG_ERROR("The built-in module name '%s' does not exist! Abort renaming...\n", built_in_name.c_str()); VTR_LOG_ERROR(
"The built-in module name '%s' does not exist! Abort renaming...\n",
built_in_name.c_str());
return CMD_EXEC_FATAL_ERROR; return CMD_EXEC_FATAL_ERROR;
} }
std::string new_name = std::string new_name = module_name_map.name(built_in_name);
module_name_map.name(built_in_name);
if (new_name != built_in_name) { if (new_name != built_in_name) {
VTR_LOGV(verbose, "Rename module '%s' to its new name '%s'\n", VTR_LOGV(verbose, "Rename module '%s' to its new name '%s'\n",
built_in_name.c_str(), built_in_name.c_str(), new_name.c_str());
new_name.c_str());
module_manager.set_module_name(curr_module, new_name); module_manager.set_module_name(curr_module, new_name);
} }
cnt++; cnt++;
@ -145,30 +148,37 @@ int partial_rename_fabric_modules(ModuleManager& module_manager,
return status; return status;
} }
/** @brief The module name map kept in openfpga context always has a built-in
/** @brief The module name map kept in openfpga context always has a built-in name with coordinates. * name with coordinates. while users apply renaming or other internal renaming
* while users apply renaming or other internal renaming is applied, e.g., through option '--name_module_using_index', the module name in the module graph can be changed. So in the user's version, the built-in name may become index or anything else. * is applied, e.g., through option '--name_module_using_index', the module name
* We have to keep the built-in name consistent (use coordinates, otherwise other engines may not work, which rely on this convention) while the given name should follow the users' definition. So we need an update here * in the module graph can be changed. So in the user's version, the built-in
* For example: * name may become index or anything else. We have to keep the built-in name
* the current module name map is 'tile_1__1_' -> 'tile_4_' * consistent (use coordinates, otherwise other engines may not work, which rely
* the user's module name map is 'tile_4_' -> 'tile_big' * on this convention) while the given name should follow the users' definition.
* The resulting module name map is 'tile_1__1_' -> 'tile_big' * So we need an update here For example: the current module name map is
* 'tile_1__1_' -> 'tile_4_' the user's module name map is 'tile_4_' ->
* 'tile_big' The resulting module name map is 'tile_1__1_' -> 'tile_big'
*/ */
int update_module_name_map_with_user_version(ModuleNameMap& curr_module_name_map, int update_module_name_map_with_user_version(
const ModuleNameMap& user_module_name_map, ModuleNameMap& curr_module_name_map,
const bool& verbose) { const ModuleNameMap& user_module_name_map, const bool& verbose) {
int status = CMD_EXEC_SUCCESS; int status = CMD_EXEC_SUCCESS;
size_t cnt = 0; size_t cnt = 0;
for (std::string user_tag : user_module_name_map.tags()) { for (std::string user_tag : user_module_name_map.tags()) {
if (!curr_module_name_map.tag_exist(user_tag)) { if (!curr_module_name_map.tag_exist(user_tag)) {
VTR_LOG_ERROR("The built-in module name '%s' given by user does not exist in current module name map! Abort updating...\n", user_tag.c_str()); VTR_LOG_ERROR(
"The built-in module name '%s' given by user does not exist in current "
"module name map! Abort updating...\n",
user_tag.c_str());
return CMD_EXEC_FATAL_ERROR; return CMD_EXEC_FATAL_ERROR;
} }
std::string built_in_tag = curr_module_name_map.tag(user_tag); std::string built_in_tag = curr_module_name_map.tag(user_tag);
curr_module_name_map.set_tag_to_name_pair(built_in_tag, user_module_name_map.name(user_tag)); curr_module_name_map.set_tag_to_name_pair(
VTR_LOGV(verbose, "Now module built-in name '%s' is pointed to its new name '%s' (old name '%s' is deleted)\n", built_in_tag, user_module_name_map.name(user_tag));
built_in_tag.c_str(), VTR_LOGV(verbose,
user_module_name_map.name(user_tag).c_str(), "Now module built-in name '%s' is pointed to its new name '%s' "
"(old name '%s' is deleted)\n",
built_in_tag.c_str(), user_module_name_map.name(user_tag).c_str(),
user_tag.c_str()); user_tag.c_str());
cnt++; cnt++;
} }

View File

@ -30,12 +30,12 @@ int rename_fabric_modules(ModuleManager& module_manager,
const bool& verbose); const bool& verbose);
int partial_rename_fabric_modules(ModuleManager& module_manager, int partial_rename_fabric_modules(ModuleManager& module_manager,
const ModuleNameMap& module_name_map, const ModuleNameMap& module_name_map,
const bool& verbose); const bool& verbose);
int update_module_name_map_with_user_version(ModuleNameMap& curr_module_name_map, int update_module_name_map_with_user_version(
const ModuleNameMap& user_module_name_map, ModuleNameMap& curr_module_name_map,
const bool& verbose); const ModuleNameMap& user_module_name_map, const bool& verbose);
} /* end namespace openfpga */ } /* end namespace openfpga */