openfpga/src/fabric/fabric_hierarchy_writer.cpp
/***************************************************************************************
 * Recursively output child module of the parent_module to a text file
 * We use Depth-First Search (DFS) here so that we can output a tree down to leaf first
 * Add space (indent) based on the depth in hierarchy
 * e.g. depth = 1 means a space as indent
 ***************************************************************************************/
Recursively output child module of the parent_module to a text file
We use Depth-First Search (DFS) here so that we can output a tree down to leaf first
Add space (indent) based on the depth in hierarchy
e.g. depth = 1 means a space as indent
Recursively output child module of the parent_module to a text file We use Depth - First Search ( DFS ) here so that we can output a tree down to leaf first Add space ( indent ) based on the depth in hierarchy e . g . depth = 1 means a space as indent
static 
int rec_output_module_hierarchy_to_text_file(std::fstream& fp,
                                             const size_t& hie_depth_to_stop,
                                             const size_t& current_hie_depth,
                                             const ModuleManager& module_manager,  
                                             const ModuleId& parent_module,
                                             const bool& verbose) {
  if (hie_depth_to_stop < current_hie_depth) {
    return 0;
  }
  if (false == valid_file_stream(fp)) {
    return 2;
  }
  for (const ModuleId& child_module : module_manager.child_modules(parent_module)) {
    if (false == write_space_to_file(fp, current_hie_depth * 2)) {
      return 2;
    }
    if (true != module_manager.valid_module_id(child_module)) {
      VTR_LOGV_ERROR(verbose,
                     "Unable to find the child module '%u'!\n",
                     size_t(child_module));
      return 1;
    }
    fp << "- ";
    fp << module_manager.module_name(child_module);
    if ( (0 != module_manager.child_modules(child_module).size())
      && (hie_depth_to_stop >= current_hie_depth + 1) ) {
      fp << ":";
    }
    fp << "\n";
    int status = rec_output_module_hierarchy_to_text_file(fp,
                                                          hie_depth_to_stop,
                                                          current_hie_depth + 1, 
                                                          module_manager,
                                                          child_module,
                                                          verbose);
    if (0 != status) {
      return status;
    }
  }
  return 0;
}
static int rec_output_module_hierarchy_to_text_file ( std :: fstream & fp , const size_t & hie_depth_to_stop , const size_t & current_hie_depth , const ModuleManager & module_manager , const ModuleId & parent_module , const bool & verbose ) { if ( hie_depth_to_stop < current_hie_depth ) { return 0 ; } if ( false == valid_file_stream ( fp ) ) { return 2 ; } for ( const ModuleId & child_module : module_manager . child_modules ( parent_module ) ) { if ( false == write_space_to_file ( fp , current_hie_depth * 2 ) ) { return 2 ; } if ( true != module_manager . valid_module_id ( child_module ) ) { VTR_LOGV_ERROR ( verbose , " \n " , size_t ( child_module ) ) ; return 1 ; } fp << " " ; fp << module_manager . module_name ( child_module ) ; if ( ( 0 != module_manager . child_modules ( child_module ) . size ( ) ) && ( hie_depth_to_stop >= current_hie_depth + 1 ) ) { fp << " " ; } fp << " \n " ; int status = rec_output_module_hierarchy_to_text_file ( fp , hie_depth_to_stop , current_hie_depth + 1 , module_manager , child_module , verbose ) ; if ( 0 != status ) { return status ; } } return 0 ; }
Recursively output child module of the parent_module to a text file
 We use Depth-First Search (DFS) here so that we can output a tree down to leaf first
 Add space (indent) based on the depth in hierarchy
 e.g.
Recursively output child module of the parent_module to a text file We use Depth - First Search ( DFS ) here so that we can output a tree down to leaf first Add space ( indent ) based on the depth in hierarchy e . g .
/* Stop if hierarchy depth is beyond the stop line */ /* Iterate over all the child module */ /* If this is the leaf node, we leave a new line 
     * Otherwise, we will leave a ':' to be compatible to YAML file format 
     */ /* Go to next level */ /* Increment the depth for the next level */