/******************************************************************** * This file includes functions that output bitstream database * to files in different formats *******************************************************************/ #include #include #include #include "vtr_assert.h" #include "util.h" #include "fpga_x2p_naming.h" #include "fpga_x2p_utils.h" #include "bitstream_manager_utils.h" #include "bitstream_writer.h" /******************************************************************** * This function write header information to a bitstream file *******************************************************************/ static void write_bitstream_xml_file_head(std::fstream& fp) { check_file_handler(fp); auto end = std::chrono::system_clock::now(); std::time_t end_time = std::chrono::system_clock::to_time_t(end); fp << "" << std::endl; fp << std::endl; } /******************************************************************** * Recursively write the bitstream of a block to a xml file * This function will use a Depth-First Search in outputting bitstream * for each block * 1. For block with bits as children, we will output the XML lines * 2. For block without bits/child blocks, we can return * 3. For block with child blocks, we visit each child recursively *******************************************************************/ static void rec_write_block_bitstream_to_xml_file(std::fstream& fp, const BitstreamManager& bitstream_manager, const ConfigBlockId& block) { check_file_handler(fp); /* Dive to child blocks if this block has any */ for (const ConfigBlockId& child_block : bitstream_manager.block_children(block)) { rec_write_block_bitstream_to_xml_file(fp, bitstream_manager, child_block); } if (0 == bitstream_manager.block_bits(block).size()) { return; } /* Write the bits of this block */ fp << "" << std::endl; std::vector block_hierarchy = find_bitstream_manager_block_hierarchy(bitstream_manager, block); /* Output hierarchy of this parent*/ fp << "\t" << std::endl; size_t hierarchy_counter = 0; for (const ConfigBlockId& temp_block : block_hierarchy) { fp << "\t\t" << std::endl; hierarchy_counter++; } fp << "\t" << std::endl; /* Output child bits under this block */ size_t bit_counter = 0; fp << "\t" << std::endl; for (const ConfigBitId& child_bit : bitstream_manager.block_bits(block)) { fp << "\t\t" << std::endl; bit_counter++; } fp << "\t" << std::endl; fp << "" < top_block = find_bitstream_manager_top_blocks(bitstream_manager); /* Make sure we have only 1 top block and its name matches the top module */ VTR_ASSERT(1 == top_block.size()); VTR_ASSERT(0 == top_block_name.compare(bitstream_manager.block_name(top_block[0]))); /* Write bitstream, block by block, in a recursive way */ rec_write_block_bitstream_to_xml_file(fp, bitstream_manager, top_block[0]); /* Close file handler */ fp.close(); /* End time count */ clock_t t_end = clock(); float run_time_sec = (float)(t_end - t_start) / CLOCKS_PER_SEC; vpr_printf(TIO_MESSAGE_INFO, "Writing bitstream to file took %g seconds...\n", run_time_sec); }