[lib] code format

This commit is contained in:
tangxifan 2023-07-06 11:16:36 -07:00
parent 82a60d64e3
commit 6c623d60f9
3 changed files with 32 additions and 30 deletions

View File

@ -277,7 +277,8 @@ void FabricKey::add_data_port_to_wl_shift_register_bank(
wl_bank_data_ports_[region_id][bank_id].push_back(data_port); wl_bank_data_ports_[region_id][bank_id].push_back(data_port);
} }
void FabricKey::reserve_module_keys(const FabricKeyModuleId& module_id, const size_t& num_keys) { void FabricKey::reserve_module_keys(const FabricKeyModuleId& module_id,
const size_t& num_keys) {
VTR_ASSERT(valid_module_id(module_id)); VTR_ASSERT(valid_module_id(module_id));
module_sub_keys_[module_id].reserve(num_keys); module_sub_keys_[module_id].reserve(num_keys);
sub_key_ids_.reserve(sub_key_ids_.size() + num_keys); sub_key_ids_.reserve(sub_key_ids_.size() + num_keys);
@ -301,7 +302,8 @@ FabricKeyModuleId FabricKey::create_module(const std::string& name) {
return module_id; return module_id;
} }
FabricSubKeyId FabricKey::create_module_key(const FabricKeyModuleId& module_id) { FabricSubKeyId FabricKey::create_module_key(
const FabricKeyModuleId& module_id) {
VTR_ASSERT(valid_module_id(module_id)); VTR_ASSERT(valid_module_id(module_id));
/* Create a new id */ /* Create a new id */
FabricSubKeyId key_id = FabricSubKeyId(sub_key_ids_.size()); FabricSubKeyId key_id = FabricSubKeyId(sub_key_ids_.size());
@ -313,17 +315,20 @@ FabricSubKeyId FabricKey::create_module_key(const FabricKeyModuleId& module_id)
return key_id; return key_id;
} }
void FabricKey::set_sub_key_name(const FabricSubKeyId& key_id, const std::string& name) { void FabricKey::set_sub_key_name(const FabricSubKeyId& key_id,
const std::string& name) {
VTR_ASSERT(valid_sub_key_id(key_id)); VTR_ASSERT(valid_sub_key_id(key_id));
sub_key_names_[key_id] = name; sub_key_names_[key_id] = name;
} }
void FabricKey::set_sub_key_value(const FabricSubKeyId& key_id, const size_t& value) { void FabricKey::set_sub_key_value(const FabricSubKeyId& key_id,
const size_t& value) {
VTR_ASSERT(valid_sub_key_id(key_id)); VTR_ASSERT(valid_sub_key_id(key_id));
sub_key_values_[key_id] = value; sub_key_values_[key_id] = value;
} }
void FabricKey::set_sub_key_alias(const FabricSubKeyId& key_id, const std::string& alias) { void FabricKey::set_sub_key_alias(const FabricSubKeyId& key_id,
const std::string& alias) {
VTR_ASSERT(valid_sub_key_id(key_id)); VTR_ASSERT(valid_sub_key_id(key_id));
sub_key_alias_[key_id] = alias; sub_key_alias_[key_id] = alias;
} }

View File

@ -153,14 +153,16 @@ class FabricKey {
const openfpga::BasicPort& data_port); const openfpga::BasicPort& data_port);
/* Reserve a number of keys to be memory efficent */ /* Reserve a number of keys to be memory efficent */
void reserve_module_keys(const FabricKeyModuleId& module_id, const size_t& num_keys); void reserve_module_keys(const FabricKeyModuleId& module_id,
const size_t& num_keys);
/* Create a new key and add it to the library, return an id */ /* Create a new key and add it to the library, return an id */
FabricModuleId create_module(const std::string& name); FabricModuleId create_module(const std::string& name);
FabricSubKeyId create_module_key(const FabricKeyModuleId& module_id); FabricSubKeyId create_module_key(const FabricKeyModuleId& module_id);
/* Configure attributes of a sub key */ /* Configure attributes of a sub key */
void set_sub_key_name(const FabricSubKeyId& key_id, const std::string& name); void set_sub_key_name(const FabricSubKeyId& key_id, const std::string& name);
void set_sub_key_value(const FabricSubKeyId& key_id, const size_t& value); void set_sub_key_value(const FabricSubKeyId& key_id, const size_t& value);
void set_sub_key_alias(const FabricSubKeyId& key_id, const std::string& alias); void set_sub_key_alias(const FabricSubKeyId& key_id,
const std::string& alias);
public: /* Public invalidators/validators */ public: /* Public invalidators/validators */
bool valid_region_id(const FabricRegionId& region_id) const; bool valid_region_id(const FabricRegionId& region_id) const;
@ -178,25 +180,19 @@ class FabricKey {
/* ---- Top-level keys and regions ---- */ /* ---- Top-level keys and regions ---- */
/* Unique ids for each region */ /* Unique ids for each region */
vtr::vector<FabricRegionId, FabricRegionId> region_ids_; vtr::vector<FabricRegionId, FabricRegionId> region_ids_;
/* Key ids for each region */ /* Key ids for each region */
vtr::vector<FabricRegionId, std::vector<FabricKeyId>> region_key_ids_; vtr::vector<FabricRegionId, std::vector<FabricKeyId>> region_key_ids_;
/* Unique ids for each key */ /* Unique ids for each key */
vtr::vector<FabricKeyId, FabricKeyId> key_ids_; vtr::vector<FabricKeyId, FabricKeyId> key_ids_;
/* Names for each key */ /* Names for each key */
vtr::vector<FabricKeyId, std::string> key_names_; vtr::vector<FabricKeyId, std::string> key_names_;
/* Values for each key */ /* Values for each key */
vtr::vector<FabricKeyId, size_t> key_values_; vtr::vector<FabricKeyId, size_t> key_values_;
/* Values for each key */ /* Values for each key */
vtr::vector<FabricKeyId, vtr::Point<int>> key_coordinates_; vtr::vector<FabricKeyId, vtr::Point<int>> key_coordinates_;
/* Region for each key */ /* Region for each key */
vtr::vector<FabricKeyId, FabricRegionId> key_regions_; vtr::vector<FabricKeyId, FabricRegionId> key_regions_;
/* Optional alias for each key, with which a key can also be represented */ /* Optional alias for each key, with which a key can also be represented */
vtr::vector<FabricKeyId, std::string> key_alias_; vtr::vector<FabricKeyId, std::string> key_alias_;

View File

@ -15,8 +15,8 @@
/* Headers from openfpga util library */ /* Headers from openfpga util library */
#include "openfpga_port_parser.h" #include "openfpga_port_parser.h"
#include "openfpga_tokenizer.h"
#include "openfpga_reserved_words.h" #include "openfpga_reserved_words.h"
#include "openfpga_tokenizer.h"
/* Headers from libarchfpga */ /* Headers from libarchfpga */
#include "arch_error.h" #include "arch_error.h"
@ -341,8 +341,8 @@ static void read_xml_fabric_key_top_module(pugi::xml_node& xml_module,
bad_tag(xml_region, loc_data, xml_root, bad_tag(xml_region, loc_data, xml_root,
{XML_FABRIC_KEY_REGION_NODE_NAME}); {XML_FABRIC_KEY_REGION_NODE_NAME});
} }
num_keys += std::distance(xml_region.children().begin(), num_keys +=
xml_region.children().end()); std::distance(xml_region.children().begin(), xml_region.children().end());
} }
fabric_key.reserve_keys(num_keys); fabric_key.reserve_keys(num_keys);
@ -369,14 +369,15 @@ static void read_xml_fabric_key_top_module(pugi::xml_node& xml_module,
static void read_xml_fabric_key_module(pugi::xml_node& xml_module, static void read_xml_fabric_key_module(pugi::xml_node& xml_module,
const pugiutil::loc_data& loc_data, const pugiutil::loc_data& loc_data,
FabricKey& fabric_key) { FabricKey& fabric_key) {
std::string name = std::string name =
get_attribute(xml_module, get_attribute(xml_module, XML_FABRIC_KEY_MODULE_ATTRIBUTE_NAME_NAME,
XML_FABRIC_KEY_MODULE_ATTRIBUTE_NAME_NAME, loc_data)
loc_data).as_string(); .as_string();
FabricKeyModuleId module_id = fabric_key.create_module(name); FabricKeyModuleId module_id = fabric_key.create_module(name);
/* Parse all the sub keys */ /* Parse all the sub keys */
size_t num_keys = std::distance(xml_module.children().begin(), xml_module.children().end()); size_t num_keys =
std::distance(xml_module.children().begin(), xml_module.children().end());
/* Reserve for better memory efficiency */ /* Reserve for better memory efficiency */
fabric_key.reserve_module_keys(module_id, num_keys); fabric_key.reserve_module_keys(module_id, num_keys);
@ -387,8 +388,7 @@ static void read_xml_fabric_key_module(pugi::xml_node& xml_module,
for (pugi::xml_node xml_key : xml_module.children()) { for (pugi::xml_node xml_key : xml_module.children()) {
/* Error out if the XML child has an invalid name! */ /* Error out if the XML child has an invalid name! */
if (xml_key.name() != std::string(XML_FABRIC_KEY_KEY_NODE_NAME)) { if (xml_key.name() != std::string(XML_FABRIC_KEY_KEY_NODE_NAME)) {
bad_tag(xml_key, loc_data, xml_module, bad_tag(xml_key, loc_data, xml_module, {XML_FABRIC_KEY_KEY_NODE_NAME});
{XML_FABRIC_KEY_KEY_NODE_NAME});
} }
read_xml_module_key(xml_key, loc_data, fabric_key, module_id); read_xml_module_key(xml_key, loc_data, fabric_key, module_id);
} }
@ -396,16 +396,17 @@ static void read_xml_fabric_key_module(pugi::xml_node& xml_module,
/******************************************************************** /********************************************************************
* Parse XML codes of a <module> to an object of FabricKey * Parse XML codes of a <module> to an object of FabricKey
* - For top-level module, we expect a fixed name. If so, we use a special parser * - For top-level module, we expect a fixed name. If so, we use a special
*parser
* - For regular module, we follow regular parser * - For regular module, we follow regular parser
*******************************************************************/ *******************************************************************/
static void read_xml_fabric_key_by_modules(pugi::xml_node& xml_module, static void read_xml_fabric_key_by_modules(pugi::xml_node& xml_module,
const pugiutil::loc_data& loc_data, const pugiutil::loc_data& loc_data,
FabricKey& fabric_key) { FabricKey& fabric_key) {
std::string name = std::string name =
get_attribute(xml_module, get_attribute(xml_module, XML_FABRIC_KEY_MODULE_ATTRIBUTE_NAME_NAME,
XML_FABRIC_KEY_MODULE_ATTRIBUTE_NAME_NAME, loc_data)
loc_data).as_string(); .as_string();
if (name == std::string(FPGA_TOP_MODULE_NAME)) { if (name == std::string(FPGA_TOP_MODULE_NAME)) {
read_xml_fabric_key_top_module(xml_module, loc_data, fabric_key); read_xml_fabric_key_top_module(xml_module, loc_data, fabric_key);
} else { } else {
@ -432,7 +433,7 @@ FabricKey read_xml_fabric_key(const char* key_fname) {
get_single_child(doc, XML_FABRIC_KEY_ROOT_NAME, loc_data); get_single_child(doc, XML_FABRIC_KEY_ROOT_NAME, loc_data);
/* Under the root node, we expect only modules */ /* Under the root node, we expect only modules */
size_t num_modules = size_t num_modules =
std::distance(xml_root.children().begin(), xml_root.children().end()); std::distance(xml_root.children().begin(), xml_root.children().end());
/* Reserve for memory efficiency */ /* Reserve for memory efficiency */