add alias name support for fabric key
This commit is contained in:
parent
ebf5636e7b
commit
9d32a5b81f
|
@ -37,6 +37,13 @@ size_t FabricKey::key_value(const FabricKeyId& key_id) const {
|
|||
return key_values_[key_id];
|
||||
}
|
||||
|
||||
/* Access the alias of a key */
|
||||
std::string FabricKey::key_alias(const FabricKeyId& key_id) const {
|
||||
/* validate the key_id */
|
||||
VTR_ASSERT(valid_key_id(key_id));
|
||||
return key_alias_[key_id];
|
||||
}
|
||||
|
||||
bool FabricKey::empty() const {
|
||||
return 0 == key_ids_.size();
|
||||
}
|
||||
|
@ -48,6 +55,7 @@ void FabricKey::reserve_keys(const size_t& num_keys) {
|
|||
key_ids_.reserve(num_keys);
|
||||
key_names_.reserve(num_keys);
|
||||
key_values_.reserve(num_keys);
|
||||
key_alias_.reserve(num_keys);
|
||||
}
|
||||
|
||||
/* Create a new key and add it to the library, return an id */
|
||||
|
@ -57,6 +65,7 @@ FabricKeyId FabricKey::create_key() {
|
|||
key_ids_.push_back(key);
|
||||
key_names_.emplace_back();
|
||||
key_values_.emplace_back();
|
||||
key_alias_.emplace_back();
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -77,6 +86,14 @@ void FabricKey::set_key_value(const FabricKeyId& key_id,
|
|||
key_values_[key_id] = value;
|
||||
}
|
||||
|
||||
void FabricKey::set_key_alias(const FabricKeyId& key_id,
|
||||
const std::string& alias) {
|
||||
/* validate the key_id */
|
||||
VTR_ASSERT(valid_key_id(key_id));
|
||||
|
||||
key_alias_[key_id] = alias;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Internal invalidators/validators
|
||||
***********************************************************************/
|
||||
|
|
|
@ -36,6 +36,7 @@ class FabricKey {
|
|||
public: /* Public Accessors: Basic data query */
|
||||
std::string key_name(const FabricKeyId& key_id) const;
|
||||
size_t key_value(const FabricKeyId& key_id) const;
|
||||
std::string key_alias(const FabricKeyId& key_id) const;
|
||||
bool empty() const;
|
||||
public: /* Public Mutators: model-related */
|
||||
void reserve_keys(const size_t& num_keys);
|
||||
|
@ -44,6 +45,8 @@ class FabricKey {
|
|||
const std::string& name);
|
||||
void set_key_value(const FabricKeyId& key_id,
|
||||
const size_t& value);
|
||||
void set_key_alias(const FabricKeyId& key_id,
|
||||
const std::string& alias);
|
||||
public: /* Public invalidators/validators */
|
||||
bool valid_key_id(const FabricKeyId& key_id) const;
|
||||
private: /* Internal data */
|
||||
|
@ -55,6 +58,9 @@ class FabricKey {
|
|||
|
||||
/* Values for each key */
|
||||
vtr::vector<FabricKeyId, size_t> key_values_;
|
||||
|
||||
/* Optional alias for each key, with which a key can also be represented */
|
||||
vtr::vector<FabricKeyId, std::string> key_alias_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,12 @@ void read_xml_component_key(pugi::xml_node& xml_component_key,
|
|||
|
||||
fabric_key.set_key_name(FabricKeyId(id), name);
|
||||
fabric_key.set_key_value(FabricKeyId(id), value);
|
||||
|
||||
/* If we have an alias, set the value as well */
|
||||
const std::string& alias = get_attribute(xml_component_key, "alias", loc_data, pugiutil::ReqOpt::OPTIONAL).as_string();
|
||||
if (!alias.empty()) {
|
||||
fabric_key.set_key_alias(FabricKeyId(id), alias);
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
|
|
|
@ -43,6 +43,10 @@ int write_xml_fabric_component_key(std::fstream& fp,
|
|||
write_xml_attribute(fp, "name", fabric_key.key_name(component_key).c_str());
|
||||
write_xml_attribute(fp, "value", fabric_key.key_value(component_key));
|
||||
|
||||
if (!fabric_key.key_alias(component_key).empty()) {
|
||||
write_xml_attribute(fp, "alias", fabric_key.key_alias(component_key).c_str());
|
||||
}
|
||||
|
||||
fp << "/>" << "\n";
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -429,6 +429,11 @@ int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager
|
|||
|
||||
/* Find if instance id is valid */
|
||||
size_t child_instance = fabric_key.key_value(key);
|
||||
/* If we have alias, we try to find a instance in this name */
|
||||
if (!fabric_key.key_alias(key).empty()) {
|
||||
child_instance = module_manager.instance_id(top_module, child_module, fabric_key.key_alias(key));
|
||||
}
|
||||
|
||||
if (child_instance >= module_manager.num_instance(top_module, child_module)) {
|
||||
VTR_LOGF_ERROR(__FILE__, __LINE__,
|
||||
"Invalid key value '%ld'!\n",
|
||||
|
|
|
@ -65,6 +65,10 @@ int write_fabric_key_to_xml_file(const ModuleManager& module_manager,
|
|||
FabricKeyId key = fabric_key.create_key();
|
||||
fabric_key.set_key_name(key, module_manager.module_name(child_module));
|
||||
fabric_key.set_key_value(key, child_instance);
|
||||
|
||||
if (false == module_manager.instance_name(top_module, child_module, child_instance).empty()) {
|
||||
fabric_key.set_key_alias(key, module_manager.instance_name(top_module, child_module, child_instance));
|
||||
}
|
||||
}
|
||||
|
||||
VTR_LOGV(verbose,
|
||||
|
|
Loading…
Reference in New Issue