openfpga/src/fabric/build_top_module_memory.cpp
/********************************************************************
 * Load configurable children from a fabric key to top-level module
 *
 * Note: 
 *   - This function will overwrite any exisiting configurable children
 *     under the top module
 *
 * Return 0 - Success
 * Return 1 - Fatal errors
 ********************************************************************/
Load configurable children from a fabric key to top-level module
Note:
- This function will overwrite any exisiting configurable children
under the top module

Return 0 - Success
Return 1 - Fatal errors
Load configurable children from a fabric key to top - level module Note : - This function will overwrite any exisiting configurable children under the top module Return 0 - Success Return 1 - Fatal errors
int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager,
                                                   const ModuleId& top_module,
                                                   const CircuitLibrary& circuit_lib,
                                                   const ConfigProtocol& config_protocol,
                                                   const FabricKey& fabric_key) {
  module_manager.clear_configurable_children(top_module);
  size_t curr_configurable_child_id = 0;
  for (const FabricRegionId& region : fabric_key.regions()) {
    ConfigRegionId top_module_config_region = module_manager.add_config_region(top_module);
    for (const FabricKeyId& key : fabric_key.region_keys(region)) {
      std::pair<ModuleId, size_t> instance_info(ModuleId::INVALID(), 0);
      if (!fabric_key.key_alias(key).empty()) {
        if (!fabric_key.key_name(key).empty()) {
          instance_info.first = module_manager.find_module(fabric_key.key_name(key));
          instance_info.second = module_manager.instance_id(top_module, instance_info.first, fabric_key.key_alias(key));
        } else {
          instance_info = find_module_manager_instance_module_info(module_manager, top_module, fabric_key.key_alias(key)); 
        }
      } else { 
        instance_info.first = module_manager.find_module(fabric_key.key_name(key));
        instance_info.second = fabric_key.key_value(key);
      }
      if (false == module_manager.valid_module_id(instance_info.first)) {
        if (!fabric_key.key_alias(key).empty()) {
          VTR_LOG_ERROR("Invalid key alias '%s'!\n",
                        fabric_key.key_alias(key).c_str()); 
        } else {
          VTR_LOG_ERROR("Invalid key name '%s'!\n",
                        fabric_key.key_name(key).c_str()); 
        }
        return CMD_EXEC_FATAL_ERROR;                    
      }
      if (false == module_manager.valid_module_instance_id(top_module, instance_info.first, instance_info.second)) {
        if (!fabric_key.key_alias(key).empty()) {
          VTR_LOG_ERROR("Invalid key alias '%s'!\n",
                        fabric_key.key_alias(key).c_str()); 
        } else {
          VTR_LOG_ERROR("Invalid key value '%ld'!\n",
                        instance_info.second); 
        }
        return CMD_EXEC_FATAL_ERROR;                    
      }
      if (0 == find_module_num_config_bits(module_manager, instance_info.first,
                                           circuit_lib, config_protocol.memory_model(), 
                                           config_protocol.type())) {
        if (!fabric_key.key_alias(key).empty()) {
          VTR_LOG_ERROR("Invalid key alias '%s' which has zero configuration bits!\n",
                        fabric_key.key_alias(key).c_str()); 
        } else {
          VTR_LOG_ERROR("Invalid key name '%s' which has zero configuration bits!\n",
                        fabric_key.key_name(key).c_str()); 
        }
        return CMD_EXEC_FATAL_ERROR;                    
      }
      module_manager.add_configurable_child(top_module,
                                            instance_info.first,
                                            instance_info.second);
      module_manager.add_configurable_child_to_region(top_module,
                                                      top_module_config_region,
                                                      instance_info.first, 
                                                      instance_info.second,
                                                      curr_configurable_child_id);
      curr_configurable_child_id++;
    }
  }
  return CMD_EXEC_SUCCESS;
}
int load_top_module_memory_modules_from_fabric_key ( ModuleManager & module_manager , const ModuleId & top_module , const CircuitLibrary & circuit_lib , const ConfigProtocol & config_protocol , const FabricKey & fabric_key ) { module_manager . clear_configurable_children ( top_module ) ; size_t curr_configurable_child_id = 0 ; for ( const FabricRegionId & region : fabric_key . regions ( ) ) { ConfigRegionId top_module_config_region = module_manager . add_config_region ( top_module ) ; for ( const FabricKeyId & key : fabric_key . region_keys ( region ) ) { std :: pair < ModuleId , size_t > instance_info ( ModuleId :: INVALID ( ) , 0 ) ; if ( ! fabric_key . key_alias ( key ) . empty ( ) ) { if ( ! fabric_key . key_name ( key ) . empty ( ) ) { instance_info . first = module_manager . find_module ( fabric_key . key_name ( key ) ) ; instance_info . second = module_manager . instance_id ( top_module , instance_info . first , fabric_key . key_alias ( key ) ) ; } else { instance_info = find_module_manager_instance_module_info ( module_manager , top_module , fabric_key . key_alias ( key ) ) ; } } else { instance_info . first = module_manager . find_module ( fabric_key . key_name ( key ) ) ; instance_info . second = fabric_key . key_value ( key ) ; } if ( false == module_manager . valid_module_id ( instance_info . first ) ) { if ( ! fabric_key . key_alias ( key ) . empty ( ) ) { VTR_LOG_ERROR ( " \n " , fabric_key . key_alias ( key ) . c_str ( ) ) ; } else { VTR_LOG_ERROR ( " \n " , fabric_key . key_name ( key ) . c_str ( ) ) ; } return CMD_EXEC_FATAL_ERROR ; } if ( false == module_manager . valid_module_instance_id ( top_module , instance_info . first , instance_info . second ) ) { if ( ! fabric_key . key_alias ( key ) . empty ( ) ) { VTR_LOG_ERROR ( " \n " , fabric_key . key_alias ( key ) . c_str ( ) ) ; } else { VTR_LOG_ERROR ( " \n " , instance_info . second ) ; } return CMD_EXEC_FATAL_ERROR ; } if ( 0 == find_module_num_config_bits ( module_manager , instance_info . first , circuit_lib , config_protocol . memory_model ( ) , config_protocol . type ( ) ) ) { if ( ! fabric_key . key_alias ( key ) . empty ( ) ) { VTR_LOG_ERROR ( " \n " , fabric_key . key_alias ( key ) . c_str ( ) ) ; } else { VTR_LOG_ERROR ( " \n " , fabric_key . key_name ( key ) . c_str ( ) ) ; } return CMD_EXEC_FATAL_ERROR ; } module_manager . add_configurable_child ( top_module , instance_info . first , instance_info . second ) ; module_manager . add_configurable_child_to_region ( top_module , top_module_config_region , instance_info . first , instance_info . second , curr_configurable_child_id ) ; curr_configurable_child_id ++ ; } } return CMD_EXEC_SUCCESS ; }
Load configurable children from a fabric key to top-level module
 Note:
   - This function will overwrite any exisiting configurable children
     under the top module
Load configurable children from a fabric key to top - level module Note : - This function will overwrite any exisiting configurable children under the top module
/* Ensure a clean start */ /* Create a configurable region in the top module */ /* Find if instance id is valid */ /* If we have an alias, we try to find a instance in this name */ /* If we have the key, we can quickly spot instance id.
         * Otherwise, we have to exhaustively find the module id and instance id
         */ /* If we do not have an alias, we use the name and value to build the info deck */ /* If the the child has not configuration bits, error out */ /* Now we can add the child to configurable children of the top module */