Skip to content

Commit

Permalink
[core] code format
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxifan committed Sep 23, 2023
1 parent 11de896 commit edb0e68
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 40 deletions.
12 changes: 7 additions & 5 deletions openfpga/src/base/openfpga_build_fabric_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,25 @@ int rename_modules_template(T& openfpga_ctx, const Command& cmd,

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;
status = read_xml_module_name_map(file_name.c_str(), user_module_name_map);
if (status != CMD_EXEC_SUCCESS) {
return CMD_EXEC_FATAL_ERROR;
}

/* Apply renaming on the user version */
status = partial_rename_fabric_modules(openfpga_ctx.mutable_module_graph(),
user_module_name_map,
cmd_context.option_enable(cmd, opt_verbose));
status = partial_rename_fabric_modules(
openfpga_ctx.mutable_module_graph(), user_module_name_map,
cmd_context.option_enable(cmd, opt_verbose));
if (status != CMD_EXEC_SUCCESS) {
return CMD_EXEC_FATAL_ERROR;
}

/* 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));
}

/********************************************************************
Expand Down
70 changes: 40 additions & 30 deletions openfpga/src/fabric/rename_modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ int update_module_map_name_with_indexing_names(ModuleNameMap& module_name_map,
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,
const ModuleNameMap& module_name_map,
const bool& verbose) {
Expand All @@ -102,15 +103,15 @@ int rename_fabric_modules(ModuleManager& module_manager,
std::string curr_module_name = module_manager.module_name(curr_module);
/* Error out if the new name does not exist ! */
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;
}
std::string new_name =
module_name_map.name(curr_module_name);
std::string new_name = module_name_map.name(curr_module_name);
if (new_name != curr_module_name) {
VTR_LOGV(verbose, "Rename module '%s' to its new name '%s'\n",
curr_module_name.c_str(),
new_name.c_str());
curr_module_name.c_str(), new_name.c_str());
module_manager.set_module_name(curr_module, new_name);
}
cnt++;
Expand All @@ -119,24 +120,26 @@ int rename_fabric_modules(ModuleManager& module_manager,
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,
const ModuleNameMap& module_name_map,
const bool& verbose) {
const ModuleNameMap& module_name_map,
const bool& verbose) {
int status = CMD_EXEC_SUCCESS;
size_t cnt = 0;
for (std::string built_in_name : module_name_map.tags()) {
ModuleId curr_module = module_manager.find_module(built_in_name);
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;
}
std::string new_name =
module_name_map.name(built_in_name);
std::string new_name = module_name_map.name(built_in_name);
if (new_name != built_in_name) {
VTR_LOGV(verbose, "Rename module '%s' to its new name '%s'\n",
built_in_name.c_str(),
new_name.c_str());
built_in_name.c_str(), new_name.c_str());
module_manager.set_module_name(curr_module, new_name);
}
cnt++;
Expand All @@ -145,30 +148,37 @@ int partial_rename_fabric_modules(ModuleManager& module_manager,
return status;
}


/** @brief The module name map kept in openfpga context always has a built-in name with coordinates.
* 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.
* 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
* 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'
/** @brief The module name map kept in openfpga context always has a built-in
* name with coordinates. 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. 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 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,
const ModuleNameMap& user_module_name_map,
const bool& verbose) {
int update_module_name_map_with_user_version(
ModuleNameMap& curr_module_name_map,
const ModuleNameMap& user_module_name_map, const bool& verbose) {
int status = CMD_EXEC_SUCCESS;
size_t cnt = 0;
for (std::string user_tag : user_module_name_map.tags()) {
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;
}
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));
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.c_str(),
user_module_name_map.name(user_tag).c_str(),
curr_module_name_map.set_tag_to_name_pair(
built_in_tag, user_module_name_map.name(user_tag));
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.c_str(), user_module_name_map.name(user_tag).c_str(),
user_tag.c_str());
cnt++;
}
Expand Down
10 changes: 5 additions & 5 deletions openfpga/src/fabric/rename_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ int rename_fabric_modules(ModuleManager& module_manager,
const bool& verbose);

int partial_rename_fabric_modules(ModuleManager& module_manager,
const ModuleNameMap& module_name_map,
const bool& verbose);
const ModuleNameMap& module_name_map,
const bool& verbose);

int update_module_name_map_with_user_version(ModuleNameMap& curr_module_name_map,
const ModuleNameMap& user_module_name_map,
const bool& verbose);
int update_module_name_map_with_user_version(
ModuleNameMap& curr_module_name_map,
const ModuleNameMap& user_module_name_map, const bool& verbose);

} /* end namespace openfpga */

Expand Down

0 comments on commit edb0e68

Please sign in to comment.