diff --git a/openfpga/src/annotation/read_xml_unique_blocks.cpp b/openfpga/src/annotation/read_xml_unique_blocks.cpp index e451328ff..e9e72cd90 100644 --- a/openfpga/src/annotation/read_xml_unique_blocks.cpp +++ b/openfpga/src/annotation/read_xml_unique_blocks.cpp @@ -12,10 +12,12 @@ #include "arch_error.h" #include "command_exit_codes.h" #include "device_rr_gsb_utils.h" +#include "mmap_file.h" #include "openfpga_digest.h" #include "read_xml_unique_blocks.h" #include "read_xml_util.h" #include "rr_gsb.h" +#include "unique_blocks_uxsdcxx.capnp.h" #include "write_xml_utils.h" /******************************************************************** @@ -155,9 +157,79 @@ int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, } } -int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, - bool verbose_output) { - return 0; +/*read the instances' coordinate of a unique block from a bin file*/ +std::vector> read_bin_unique_instance_coords( + const uniqueblockcap::BlockInfo::Reader& unique_block) { + std::vector> instance_coords; + if (unique_block.hasInstanceList()) { + auto instance_list = unique_block.getInstanceList(); + for (auto instance : instance_list) { + int instance_x = instance.getX(); + int instance_y = instance.getY(); + vtr::Point instance_coordinate(instance_x, instance_y); + instance_coords.push_back(instance_coordinate); + } + } + return instance_coords; } +/*read the unique block coordinate from a bin file */ +vtr::Point read_bin_unique_block_coord( + const uniqueblockcap::BlockInfo::Reader& unique_block) { + auto block_info = unique_block.getBlockInfo(); + std::string type = block_info.getType().Cstr(); + int block_x = block_info.getX(); + int block_y = block_info.getY(); + vtr::Point block_coordinate(block_x, block_y); + return block_coordinate; +} + +/*top-level function to read unique blocks from bin file*/ +int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, + bool verbose_output) { + /* clear unique modules & reserve memory to relavant vectors */ + device_rr_gsb.clear_unique_modules(); + // vtr::Point grid_coord(rr_gsb_.size()); + device_rr_gsb.reserve_unique_modules(); + MmapFile f(file_name); + ::uniqueblockcap::FlatArrayMessageReader reader(f.getData()); + auto root = reader.getRoot(); + if (root.hasAtomInfo()) { + auto block_list = root.getAtomInfo(); + for (auto unqiue_block : block_list) { + auto block_info = unique_block.getBlockInfo(); + std::string type = block_info.getType().Cstr(); + int block_x = block_info.getX(); + int block_y = block_info.getY(); + vtr::Point block_coordinate(block_x, block_y); + if (unique_block.hasInstanceList()) { + auto instance_list = unique_block.getInstanceList(); + std::vector> instance_coords; + for (auto instance : instance_list) { + int instance_x = instance.getX(); + int instance_y = instance.getY(); + vtr::Point instance_coordinate(instance_x, instance_y); + instance_coords.push_back(instance_coordinate); + } + } + /* get block coordinate and instance coordinate, try to setup + * device_rr_gsb */ + if (type == "sb") { + device_rr_gsb.preload_unique_sb_module(block_coordinate, + instance_coords); + } else if (type == "cby") { + device_rr_gsb.preload_unique_cby_module(block_coordinate, + instance_coords); + } else if (type == "cbx") { + device_rr_gsb.preload_unique_cbx_module(block_coordinate, + instance_coords); + } + } + } + device_rr_gsb.build_gsb_unique_module(); + if (verbose_output) { + report_unique_module_status_read(device_rr_gsb, true); + } + return CMD_EXEC_SUCCESS; +} } // namespace openfpga diff --git a/openfpga/src/annotation/read_xml_unique_blocks.h b/openfpga/src/annotation/read_xml_unique_blocks.h index d5a0dcca8..8c6f2103d 100644 --- a/openfpga/src/annotation/read_xml_unique_blocks.h +++ b/openfpga/src/annotation/read_xml_unique_blocks.h @@ -36,7 +36,14 @@ void report_unique_module_status_read(const DeviceRRGSB& device_rr_gsb, int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, bool verbose_output); +std::vector> read_bin_unique_instance_coords( + const uniqueblockcap::BlockInfo::Reader& unique_block); + +vtr::Point read_bin_unique_block_coord( + const uniqueblockcap::BlockInfo::Reader& unique_block); + int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, - bool verbose_output); + bool verbose_output) } // namespace openfpga + #endif diff --git a/openfpga/src/annotation/write_unique_blocks.cpp b/openfpga/src/annotation/write_unique_blocks.cpp index 9a6a5cf4e..370ea4e90 100644 --- a/openfpga/src/annotation/write_unique_blocks.cpp +++ b/openfpga/src/annotation/write_unique_blocks.cpp @@ -224,7 +224,6 @@ int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, const auto unique_block_coord = device_rr_gsb.get_sb_unique_block_coord(id); const std::vector> instance_map = device_rr_gsb.get_sb_unique_block_instance_coord(unique_block_coord); - std::cout << "what is instance size: " << instance_map.size() << std::endl; auto unique_block = block_list[id]; int status_code = write_bin_atom_block(instance_map, unique_block_coord,