openfpga/src/fpga_bitstream/build_fabric_bitstream.cpp
static 
void rec_build_module_fabric_dependent_chain_bitstream(const BitstreamManager& bitstream_manager,
                                                       const ConfigBlockId& parent_block,
                                                       const ModuleManager& module_manager,
                                                       const ModuleId& top_module,
                                                       const ModuleId& parent_module,
                                                       const ConfigRegionId& config_region,
                                                       FabricBitstream& fabric_bitstream,
                                                       const FabricBitRegionId& fabric_bitstream_region) {

  /* Depth-first search: if we have any children in the parent_block, 
   * we dive to the next level first! 
   */
  if (0 < bitstream_manager.block_children(parent_block).size()) {
    if (parent_module == top_module) {
      for (size_t child_id = 0; child_id < module_manager.region_configurable_children(parent_module, config_region).size(); ++child_id) {
        ModuleId child_module = module_manager.region_configurable_children(parent_module, config_region)[child_id]; 
        size_t child_instance = module_manager.region_configurable_child_instances(parent_module, config_region)[child_id]; 
        /* Get the instance name and ensure it is not empty */
        std::string instance_name = module_manager.instance_name(parent_module, child_module, child_instance);
         
        /* Find the child block that matches the instance name! */ 
        ConfigBlockId child_block = bitstream_manager.find_child_block(parent_block, instance_name); 
        /* We must have one valid block id! */
        VTR_ASSERT(true == bitstream_manager.valid_block_id(child_block));

        /* Go recursively */
        rec_build_module_fabric_dependent_chain_bitstream(bitstream_manager, child_block,
                                                          module_manager, top_module,
                                                          child_module,
                                                          config_region,
                                                          fabric_bitstream,
                                                          fabric_bitstream_region);
      }
    } else { 
      for (size_t child_id = 0; child_id < module_manager.configurable_children(parent_module).size(); ++child_id) {
        ModuleId child_module = module_manager.configurable_children(parent_module)[child_id]; 
        size_t child_instance = module_manager.configurable_child_instances(parent_module)[child_id]; 
        /* Get the instance name and ensure it is not empty */
        std::string instance_name = module_manager.instance_name(parent_module, child_module, child_instance);
         
        /* Find the child block that matches the instance name! */ 
        ConfigBlockId child_block = bitstream_manager.find_child_block(parent_block, instance_name); 
        /* We must have one valid block id! */
        VTR_ASSERT(true == bitstream_manager.valid_block_id(child_block));

        /* Go recursively */
        rec_build_module_fabric_dependent_chain_bitstream(bitstream_manager, child_block,
                                                          module_manager, top_module,
                                                          child_module,
                                                          config_region,
                                                          fabric_bitstream,
                                                          fabric_bitstream_region);
      }
    }
    /* Ensure that there should be no configuration bits in the parent block */
    VTR_ASSERT(0 == bitstream_manager.block_bits(parent_block).size());
  }

  /* Note that, reach here, it means that this is a leaf node. 
   * We add the configuration bits to the fabric_bitstream,
   * And then, we can return
   */
  for (const ConfigBitId& config_bit : bitstream_manager.block_bits(parent_block)) {
    FabricBitId fabric_bit = fabric_bitstream.add_bit(config_bit);
    fabric_bitstream.add_bit_to_region(fabric_bitstream_region, fabric_bit);
  }
}
/********************************************************************
 * This function aims to build a bitstream for configuration chain-like protocol
 * It will walk through all the configurable children under a module
 * in a recursive way, following a Depth-First Search (DFS) strategy
 * For each configuration child, we use its instance name as a key to spot the 
 * configuration bits in bitstream manager.
 * Note that it is guarentee that the instance name in module manager is 
 * consistent with the block names in bitstream manager
 * We use this link to reorganize the bitstream in the sequence of memories as we stored
 * in the configurable_children() and configurable_child_instances() of each module of module manager 
 *******************************************************************/
This function aims to build a bitstream for configuration chain-like protocol
It will walk through all the configurable children under a module
in a recursive way, following a Depth-First Search (DFS) strategy
For each configuration child, we use its instance name as a key to spot the
configuration bits in bitstream manager.
Note that it is guarentee that the instance name in module manager is
consistent with the block names in bitstream manager
We use this link to reorganize the bitstream in the sequence of memories as we stored
in the configurable_children() and configurable_child_instances() of each module of module manager
This function aims to build a bitstream for configuration chain - like protocol It will walk through all the configurable children under a module in a recursive way following a Depth - First Search ( DFS ) strategy For each configuration child we use its instance name as a key to spot the configuration bits in bitstream manager . Note that it is guarentee that the instance name in module manager is consistent with the block names in bitstream manager We use this link to reorganize the bitstream in the sequence of memories as we stored in the configurable_children () and configurable_child_instances () of each module of module manager
static 
void rec_build_module_fabric_dependent_chain_bitstream(const BitstreamManager& bitstream_manager,
                                                       const ConfigBlockId& parent_block,
                                                       const ModuleManager& module_manager,
                                                       const ModuleId& top_module,
                                                       const ModuleId& parent_module,
                                                       const ConfigRegionId& config_region,
                                                       FabricBitstream& fabric_bitstream,
                                                       const FabricBitRegionId& fabric_bitstream_region) {
  if (0 < bitstream_manager.block_children(parent_block).size()) {
    if (parent_module == top_module) {
      for (size_t child_id = 0; child_id < module_manager.region_configurable_children(parent_module, config_region).size(); ++child_id) {
        ModuleId child_module = module_manager.region_configurable_children(parent_module, config_region)[child_id]; 
        size_t child_instance = module_manager.region_configurable_child_instances(parent_module, config_region)[child_id]; 
        std::string instance_name = module_manager.instance_name(parent_module, child_module, child_instance);
        ConfigBlockId child_block = bitstream_manager.find_child_block(parent_block, instance_name); 
        VTR_ASSERT(true == bitstream_manager.valid_block_id(child_block));
        rec_build_module_fabric_dependent_chain_bitstream(bitstream_manager, child_block,
                                                          module_manager, top_module,
                                                          child_module,
                                                          config_region,
                                                          fabric_bitstream,
                                                          fabric_bitstream_region);
      }
    } else { 
      for (size_t child_id = 0; child_id < module_manager.configurable_children(parent_module).size(); ++child_id) {
        ModuleId child_module = module_manager.configurable_children(parent_module)[child_id]; 
        size_t child_instance = module_manager.configurable_child_instances(parent_module)[child_id]; 
        std::string instance_name = module_manager.instance_name(parent_module, child_module, child_instance);
        ConfigBlockId child_block = bitstream_manager.find_child_block(parent_block, instance_name); 
        VTR_ASSERT(true == bitstream_manager.valid_block_id(child_block));
        rec_build_module_fabric_dependent_chain_bitstream(bitstream_manager, child_block,
                                                          module_manager, top_module,
                                                          child_module,
                                                          config_region,
                                                          fabric_bitstream,
                                                          fabric_bitstream_region);
      }
    }
    VTR_ASSERT(0 == bitstream_manager.block_bits(parent_block).size());
  }
  for (const ConfigBitId& config_bit : bitstream_manager.block_bits(parent_block)) {
    FabricBitId fabric_bit = fabric_bitstream.add_bit(config_bit);
    fabric_bitstream.add_bit_to_region(fabric_bitstream_region, fabric_bit);
  }
}
static void rec_build_module_fabric_dependent_chain_bitstream ( const BitstreamManager & bitstream_manager , const ConfigBlockId & parent_block , const ModuleManager & module_manager , const ModuleId & top_module , const ModuleId & parent_module , const ConfigRegionId & config_region , FabricBitstream & fabric_bitstream , const FabricBitRegionId & fabric_bitstream_region ) { if ( 0 < bitstream_manager . block_children ( parent_block ) . size ( ) ) { if ( parent_module == top_module ) { for ( size_t child_id = 0 ; child_id < module_manager . region_configurable_children ( parent_module , config_region ) . size ( ) ; ++ child_id ) { ModuleId child_module = module_manager . region_configurable_children ( parent_module , config_region ) [ child_id ] ; size_t child_instance = module_manager . region_configurable_child_instances ( parent_module , config_region ) [ child_id ] ; std :: string instance_name = module_manager . instance_name ( parent_module , child_module , child_instance ) ; ConfigBlockId child_block = bitstream_manager . find_child_block ( parent_block , instance_name ) ; VTR_ASSERT ( true == bitstream_manager . valid_block_id ( child_block ) ) ; rec_build_module_fabric_dependent_chain_bitstream ( bitstream_manager , child_block , module_manager , top_module , child_module , config_region , fabric_bitstream , fabric_bitstream_region ) ; } } else { for ( size_t child_id = 0 ; child_id < module_manager . configurable_children ( parent_module ) . size ( ) ; ++ child_id ) { ModuleId child_module = module_manager . configurable_children ( parent_module ) [ child_id ] ; size_t child_instance = module_manager . configurable_child_instances ( parent_module ) [ child_id ] ; std :: string instance_name = module_manager . instance_name ( parent_module , child_module , child_instance ) ; ConfigBlockId child_block = bitstream_manager . find_child_block ( parent_block , instance_name ) ; VTR_ASSERT ( true == bitstream_manager . valid_block_id ( child_block ) ) ; rec_build_module_fabric_dependent_chain_bitstream ( bitstream_manager , child_block , module_manager , top_module , child_module , config_region , fabric_bitstream , fabric_bitstream_region ) ; } } VTR_ASSERT ( 0 == bitstream_manager . block_bits ( parent_block ) . size ( ) ) ; } for ( const ConfigBitId & config_bit : bitstream_manager . block_bits ( parent_block ) ) { FabricBitId fabric_bit = fabric_bitstream . add_bit ( config_bit ) ; fabric_bitstream . add_bit_to_region ( fabric_bitstream_region , fabric_bit ) ; } }
This function aims to build a bitstream for configuration chain-like protocol
 It will walk through all the configurable children under a module
 in a recursive way, following a Depth-First Search (DFS) strategy
 For each configuration child, we use its instance name as a key to spot the
 configuration bits in bitstream manager.
This function aims to build a bitstream for configuration chain - like protocol It will walk through all the configurable children under a module in a recursive way following a Depth - First Search ( DFS ) strategy For each configuration child we use its instance name as a key to spot the configuration bits in bitstream manager .
/* Depth-first search: if we have any children in the parent_block, 
   * we dive to the next level first! 
   */ /* Get the instance name and ensure it is not empty */ /* Find the child block that matches the instance name! */ /* We must have one valid block id! */ /* Go recursively */ /* Get the instance name and ensure it is not empty */ /* Find the child block that matches the instance name! */ /* We must have one valid block id! */ /* Go recursively */ /* Ensure that there should be no configuration bits in the parent block */ /* Note that, reach here, it means that this is a leaf node. 
   * We add the configuration bits to the fabric_bitstream,
   * And then, we can return
   */