[core] enable options in xml writers

This commit is contained in:
tangxifan 2023-10-06 18:20:17 -07:00
parent ae63c9d441
commit b07111497c
3 changed files with 62 additions and 21 deletions

View File

@ -81,6 +81,28 @@ size_t find_bitstream_manager_config_bit_index_in_parent_block(
return curr_index;
}
/********************************************************************
* Find the index of a configuration bit in the children bits of its grandparent
*block. We count the index from the parent of current parent block
*******************************************************************/
size_t find_bitstream_manager_config_bit_index_in_grandparent_block(
const BitstreamManager& bitstream_manager, const ConfigBitId& bit_id) {
size_t curr_index = 0;
ConfigBlockId parent_blk = bitstream_manager.bit_parent_block(bit_id);
ConfigBlockId grandparent_blk = bitstream_manager.block_parent(parent_blk);
for (const ConfigBlockId& cand_blk : bitstream_manager.block_children(grandparent_blk)) {
if (cand_blk != parent_blk) {
curr_index += bitstream_manager.block_bits(cand_blk).size();
} else {
curr_index += find_bitstream_manager_config_bit_index_in_parent_block(bitstream_manager, bit_id);
break;
}
}
return curr_index;
}
/********************************************************************
* Find the total number of configuration bits under a block
* As configuration bits are stored only under the leaf blocks,

View File

@ -25,6 +25,9 @@ std::vector<ConfigBlockId> find_bitstream_manager_top_blocks(
size_t find_bitstream_manager_config_bit_index_in_parent_block(
const BitstreamManager& bitstream_manager, const ConfigBitId& bit_id);
size_t find_bitstream_manager_config_bit_index_in_grandparent_block(
const BitstreamManager& bitstream_manager, const ConfigBitId& bit_id);
size_t rec_find_bitstream_manager_block_sum_of_bits(
const BitstreamManager& bitstream_manager, const ConfigBlockId& block);

View File

@ -72,36 +72,51 @@ static int write_fabric_config_bit_to_xml_file(
std::fstream& fp, const BitstreamManager& bitstream_manager,
const FabricBitstream& fabric_bitstream, const FabricBitId& fabric_bit,
const e_config_protocol_type& config_type, bool fast_xml,
const int& xml_hierarchy_depth, std::string& bl_addr, std::string& wl_addr) {
const int& xml_hierarchy_depth, std::string& bl_addr, std::string& wl_addr,
const BitstreamWriterOption& options) {
if (false == valid_file_stream(fp)) {
return 1;
}
write_tab_to_file(fp, xml_hierarchy_depth);
fp << "<bit id=\"" << size_t(fabric_bit) << "\"";
fp << " value=\"";
fp << bitstream_manager.bit_value(fabric_bitstream.config_bit(fabric_bit));
fp << "\"";
if (options.output_value() && !options.value_to_skip(bitstream_manager.bit_value(fabric_bitstream.config_bit(fabric_bit)))) {
fp << " value=\"";
fp << bitstream_manager.bit_value(fabric_bitstream.config_bit(fabric_bit));
fp << "\"";
}
/* Output hierarchy of this parent*/
const ConfigBitId& config_bit = fabric_bitstream.config_bit(fabric_bit);
const ConfigBlockId& config_block =
bitstream_manager.bit_parent_block(config_bit);
std::vector<ConfigBlockId> block_hierarchy =
find_bitstream_manager_block_hierarchy(bitstream_manager, config_block);
std::string hie_path;
for (const ConfigBlockId& temp_block : block_hierarchy) {
hie_path += bitstream_manager.block_name(temp_block);
hie_path += std::string(".");
}
hie_path += generate_configurable_memory_data_out_name();
hie_path += std::string("[");
hie_path +=
std::to_string(find_bitstream_manager_config_bit_index_in_parent_block(
bitstream_manager, config_bit));
hie_path += std::string("]");
fp << " path=\"" << hie_path << "\">\n";
if (options.output_path()) {
std::vector<ConfigBlockId> block_hierarchy =
find_bitstream_manager_block_hierarchy(bitstream_manager, config_block);
std::string hie_path;
for (size_t iblk = 0; iblk < block_hierarchy.size(); ++iblk) {
/* If enabled, pop the last block name */
if (options.trim_path() && iblk == block_hierarchy.size() - 1) {
break;
}
hie_path += bitstream_manager.block_name(block_hierarchy[iblk]);
hie_path += std::string(".");
}
hie_path += generate_configurable_memory_data_out_name();
hie_path += std::string("[");
size_t bit_idx_in_parent_block = find_bitstream_manager_config_bit_index_in_parent_block(
bitstream_manager, config_bit);
if (options.trim_path()) {
bit_idx_in_parent_block = find_bitstream_manager_config_bit_index_in_grandparent_block(
bitstream_manager, config_bit);
}
hie_path +=
std::to_string(bit_idx_in_parent_block);
hie_path += std::string("]");
fp << " path=\"" << hie_path << "\">\n";
}
switch (config_type) {
case CONFIG_MEM_STANDALONE:
@ -196,7 +211,8 @@ static int write_fabric_regional_config_bit_to_xml_file(
const FabricBitstream& fabric_bitstream,
const FabricBitRegionId& fabric_region,
const e_config_protocol_type& config_type, bool fast_xml,
const int& xml_hierarchy_depth) {
const int& xml_hierarchy_depth,
const BitstreamWriterOption& options) {
if (false == valid_file_stream(fp)) {
return 1;
}
@ -228,7 +244,7 @@ static int write_fabric_regional_config_bit_to_xml_file(
fabric_bitstream.region_bits(fabric_region)) {
status = write_fabric_config_bit_to_xml_file(
fp, bitstream_manager, fabric_bitstream, fabric_bit, config_type,
fast_xml, xml_hierarchy_depth + 1, bl_addr, wl_addr);
fast_xml, xml_hierarchy_depth + 1, bl_addr, wl_addr, options);
if (1 == status) {
return status;
}
@ -296,7 +312,7 @@ int write_fabric_bitstream_to_xml_file(
fp, bitstream_manager, fabric_bitstream, region, config_protocol.type(),
BLWL_PROTOCOL_FLATTEN == config_protocol.bl_protocol_type() &&
BLWL_PROTOCOL_FLATTEN == config_protocol.wl_protocol_type(),
xml_hierarchy_depth + 1);
xml_hierarchy_depth + 1, options);
if (1 == status) {
break;
}