openfpga/src/annotation/check_pb_type_annotation.cpp
/********************************************************************
 * This function will recursively traverse pb_type graph to ensure
 * 1. there is only a physical mode under each pb_type
 * 2. physical mode appears only when its parent is a physical mode.
 *******************************************************************/
This function will recursively traverse pb_type graph to ensure
1. there is only a physical mode under each pb_type
2. physical mode appears only when its parent is a physical mode.
This function will recursively traverse pb_type graph to ensure 1 . there is only a physical mode under each pb_type 2 . physical mode appears only when its parent is a physical mode .
static 
void rec_check_vpr_physical_pb_mode_annotation(t_pb_type* cur_pb_type,
                                               const bool& expect_physical_mode,
                                               const VprDeviceAnnotation& vpr_device_annotation,
                                               size_t& num_err) {
  if (true == is_primitive_pb_type(cur_pb_type)) {
    return;
  }
  if (true == expect_physical_mode) {
    if (nullptr == vpr_device_annotation.physical_mode(cur_pb_type)) {
      VTR_LOG_ERROR("Unable to find a physical mode for a multi-mode pb_type '%s'!\n",
                    cur_pb_type->name);
      VTR_LOG_ERROR("Please specify in the OpenFPGA architecture\n");
      num_err++;
      return;
    }
  } else {
    VTR_ASSERT_SAFE(false == expect_physical_mode);
    if (nullptr != vpr_device_annotation.physical_mode(cur_pb_type)) {
      VTR_LOG_ERROR("Find a physical mode '%s' for pb_type '%s' which is not under any physical mode!\n",
                    vpr_device_annotation.physical_mode(cur_pb_type)->name,
                    cur_pb_type->name);
      num_err++;
      return;
    }
  }
  for (int imode = 0; imode < cur_pb_type->num_modes; ++imode) {
    bool expect_child_physical_mode = false;
    if (&(cur_pb_type->modes[imode]) == vpr_device_annotation.physical_mode(cur_pb_type)) {
      expect_child_physical_mode = true && expect_physical_mode; 
    }
    for (int ichild = 0; ichild < cur_pb_type->modes[imode].num_pb_type_children; ++ichild) { 
      rec_check_vpr_physical_pb_mode_annotation(&(cur_pb_type->modes[imode].pb_type_children[ichild]),
                                                expect_child_physical_mode, vpr_device_annotation,
                                                num_err);
    }
  }
}
static void rec_check_vpr_physical_pb_mode_annotation ( t_pb_type * cur_pb_type , const bool & expect_physical_mode , const VprDeviceAnnotation & vpr_device_annotation , size_t & num_err ) { if ( true == is_primitive_pb_type ( cur_pb_type ) ) { return ; } if ( true == expect_physical_mode ) { if ( nullptr == vpr_device_annotation . physical_mode ( cur_pb_type ) ) { VTR_LOG_ERROR ( " \n " , cur_pb_type -> name ) ; VTR_LOG_ERROR ( " \n " ) ; num_err ++ ; return ; } } else { VTR_ASSERT_SAFE ( false == expect_physical_mode ) ; if ( nullptr != vpr_device_annotation . physical_mode ( cur_pb_type ) ) { VTR_LOG_ERROR ( " \n " , vpr_device_annotation . physical_mode ( cur_pb_type ) -> name , cur_pb_type -> name ) ; num_err ++ ; return ; } } for ( int imode = 0 ; imode < cur_pb_type -> num_modes ; ++ imode ) { bool expect_child_physical_mode = false ; if ( & ( cur_pb_type -> modes [ imode ] ) == vpr_device_annotation . physical_mode ( cur_pb_type ) ) { expect_child_physical_mode = true && expect_physical_mode ; } for ( int ichild = 0 ; ichild < cur_pb_type -> modes [ imode ] . num_pb_type_children ; ++ ichild ) { rec_check_vpr_physical_pb_mode_annotation ( & ( cur_pb_type -> modes [ imode ] . pb_type_children [ ichild ] ) , expect_child_physical_mode , vpr_device_annotation , num_err ) ; } } }
This function will recursively traverse pb_type graph to ensure
 1. there is only a physical mode under each pb_type
 2. physical mode appears only when its parent is a physical mode.
This function will recursively traverse pb_type graph to ensure 1 . there is only a physical mode under each pb_type 2 . physical mode appears only when its parent is a physical mode .
/* We do not check any primitive pb_type */ /* For non-primitive pb_type:
   * - If we expect a physical mode to exist under this pb_type
   *   we should be able to find one in the annoation 
   * - If we do NOT expect a physical mode, make sure we find 
   *   nothing in the annotation
   */ /* Traverse all the modes
   * - for pb_type children under a physical mode, we expect an physical mode 
   * - for pb_type children under non-physical mode, we expect no physical mode 
   */