VhpiIterator::VhpiIterator(GpiImplInterface *impl, GpiObjHdl *hdl) : GpiIterator(impl, hdl), m_iterator(NULL), m_iter_obj(NULL) { vhpiHandleT iterator; vhpiHandleT vhpi_hdl = m_parent->get_handle<vhpiHandleT>(); vhpiClassKindT type = (vhpiClassKindT)vhpi_get(vhpiKindP, vhpi_hdl); if (NULL == (selected = iterate_over.get_options(type))) { LOG_WARN("VHPI: Implementation does not know how to iterate over %s(%d)", vhpi_get_str(vhpiKindStrP, vhpi_hdl), type); return; } /* Find the first mapping type that yields a valid iterator */ for (one2many = selected->begin(); one2many != selected->end(); one2many++) { iterator = vhpi_iterator(*one2many, vhpi_hdl); if (iterator) break; LOG_DEBUG("vhpi_iterate vhpiOneToManyT=%d returned NULL", *one2many); } if (NULL == iterator) { LOG_DEBUG("vhpi_iterate return NULL for all relationships on %s (%d) kind:%s", vhpi_get_str(vhpiCaseNameP, vhpi_hdl), type, vhpi_get_str(vhpiKindStrP, vhpi_hdl)); selected = NULL; return; } LOG_DEBUG("Created iterator working from scope %d (%s)", vhpi_get(vhpiKindP, vhpi_hdl), vhpi_get_str(vhpiKindStrP, vhpi_hdl)); /* On some simulators (Aldec) vhpiRootInstK is a null level of hierachy * We check that something is going to come back if not we try the level * down */ m_iter_obj = vhpi_hdl; m_iterator = iterator; }
// this function gets handle to signal of specified hierarchical name vhpiHandleT getHandle( char* _szSigName ) { vhpiHandleT hSigHdl,hHdl,hSubItr,hSubHdl; // get handle to root instance if ( ( hHdl = vhpi_handle( vhpiRootInst, NULL ) ) ) { // get handle to signal - try root instance first if ( !( hSigHdl = vhpi_handle_by_name( _szSigName, hHdl ) ) ) { // if failed, iterate internal regions if (( hSubItr = vhpi_iterator( vhpiInternalRegions, hHdl ) )) { while (( hSubHdl = vhpi_scan( hSubItr ) )) if ( !( hSigHdl = vhpi_handle_by_name( _szSigName, hSubHdl ) ) ) { // if failed, print info vhpi_printf( "getHandle(): No signals found searching root and internal regions or ambiguous signal name\n" ); return NULL; } } else { vhpi_printf( "getHandle(): No internal regions found\n" ); return NULL; } } // if getting handle succeeded, print information on console... if ( strcmp( vhpi_get_str( vhpiKindStrP, hSigHdl ), "vhpiPortDeclK" ) == 0 ) // ...with mode in case of port vhpi_printf( "getHandle(): Port %s found: kind %s, mode %s\n",vhpi_get_str( vhpiFullNameP, hSigHdl ), vhpi_get_str( vhpiKindStrP, hSigHdl ), conv_mode( vhpi_get( vhpiModeP, hSigHdl ) ) ); else // ...without mode in case of other object vhpi_printf( "getHandle(): Object %s found: kind %s\n", vhpi_get_str( vhpiFullNameP, hSigHdl ), vhpi_get_str( vhpiKindStrP, hSigHdl ) ); return hSigHdl; } else { vhpi_printf( "getHandle(): No root instance found\n" ); return NULL; } }
GpiIterator::Status VhpiIterator::next_handle(std::string &name, GpiObjHdl **hdl, void **raw_hdl) { vhpiHandleT obj; GpiObjHdl *new_obj; if (!selected) return GpiIterator::END; /* We want the next object in the current mapping. * If the end of mapping is reached then we want to * try then next one until a new object is found */ do { obj = NULL; if (m_iterator) { obj = vhpi_scan(m_iterator); if (obj && (vhpiProcessStmtK == vhpi_get(vhpiKindP, obj))) { LOG_DEBUG("Skipping %s (%s)", vhpi_get_str(vhpiFullNameP, obj), vhpi_get_str(vhpiKindStrP, obj)); obj=NULL; continue; } if (obj) { LOG_DEBUG("Found an item %s", vhpi_get_str(vhpiFullNameP, obj)); break; } else { LOG_DEBUG("vhpi_scan on %d returned NULL", *one2many); } LOG_DEBUG("End of vhpiOneToManyT=%d iteration", *one2many); m_iterator = NULL; } else { LOG_DEBUG("No valid vhpiOneToManyT=%d iterator", *one2many); } if (++one2many >= selected->end()) { obj = NULL; break; } m_iterator = vhpi_iterator(*one2many, m_iter_obj); } while (!obj); if (NULL == obj) { LOG_DEBUG("No more children, all relationships tested"); return GpiIterator::END; } const char *c_name = vhpi_get_str(vhpiCaseNameP, obj); if (!c_name) { int type = vhpi_get(vhpiKindP, obj); if (type < VHPI_TYPE_MIN) { *raw_hdl = (void*)obj; return GpiIterator::NOT_NATIVE_NO_NAME; } LOG_DEBUG("Unable to get the name for this object of type %d", type); return GpiIterator::NATIVE_NO_NAME; } name = c_name; LOG_DEBUG("vhpi_scan found %s (%d) kind:%s name:%s", name.c_str(), vhpi_get(vhpiKindP, obj), vhpi_get_str(vhpiKindStrP, obj), vhpi_get_str(vhpiCaseNameP, obj)); /* We try and create a handle internally, if this is not possible we return and GPI will try other implementations with the name */ std::string fq_name = m_parent->get_fullname(); if (fq_name == ":") { fq_name += name; } else { fq_name += "." + name; } VhpiImpl *vhpi_impl = reinterpret_cast<VhpiImpl*>(m_impl); new_obj = vhpi_impl->create_gpi_obj_from_handle(obj, name, fq_name); if (new_obj) { *hdl = new_obj; return GpiIterator::NATIVE; } else return GpiIterator::NOT_NATIVE; }
int VhpiSignalObjHdl::initialise(std::string &name, std::string &fq_name) { // Determine the type of object, either scalar or vector m_value.format = vhpiObjTypeVal; m_value.bufSize = 0; m_value.value.str = NULL; m_value.numElems = 0; /* We also alloc a second value member for use with read string operations */ m_binvalue.format = vhpiBinStrVal; m_binvalue.bufSize = 0; m_binvalue.numElems = 0; m_binvalue.value.str = NULL; vhpiHandleT handle = GpiObjHdl::get_handle<vhpiHandleT>(); if (0 > vhpi_get_value(get_handle<vhpiHandleT>(), &m_value)) { if (vhpiSliceNameK == vhpi_get(vhpiKindP, handle)) { m_value.format = vhpiEnumVecVal; } else { LOG_DEBUG("vhpi_get_value failed and not a vhpiSliceNameK setting to vhpiRawDataVal"); m_value.format = vhpiRawDataVal; } } LOG_DEBUG("Found %s of format type %s (%d) format object with %d elems buffsize %d size %d", name.c_str(), ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format), m_value.format, m_value.numElems, m_value.bufSize, vhpi_get(vhpiSizeP, handle)); // Default - overridden below in certain special cases m_num_elems = m_value.numElems; switch (m_value.format) { case vhpiIntVal: case vhpiEnumVal: case vhpiLogicVal: case vhpiRealVal: case vhpiCharVal: { break; } case vhpiIntVecVal: case vhpiEnumVecVal: case vhpiLogicVecVal: { m_num_elems = vhpi_get(vhpiSizeP, handle); m_value.bufSize = m_num_elems*sizeof(vhpiEnumT); m_value.value.enumvs = (vhpiEnumT *)malloc(m_value.bufSize + 1); if (!m_value.value.enumvs) { LOG_CRITICAL("Unable to alloc mem for write buffer: ABORTING"); } LOG_DEBUG("Overriding num_elems to %d", m_num_elems); break; } case vhpiStrVal: { m_num_elems = vhpi_get(vhpiSizeP, handle); m_value.bufSize = (m_num_elems)*sizeof(vhpiCharT) + 1; m_value.value.str = (vhpiCharT *)malloc(m_value.bufSize); m_value.numElems = m_num_elems; if (!m_value.value.str) { LOG_CRITICAL("Unable to alloc mem for write buffer"); } LOG_DEBUG("Overriding num_elems to %d", m_num_elems); break; } case vhpiRawDataVal: { // This is an internal representation - the only way to determine // the size is to iterate over the members and count sub-elements m_num_elems = 0; vhpiHandleT result = NULL; vhpiHandleT iterator = vhpi_iterator(vhpiIndexedNames, handle); while (true) { result = vhpi_scan(iterator); if (NULL == result) break; m_num_elems++; } LOG_DEBUG("Found vhpiRawDataVal with %d elements", m_num_elems); goto gpi_init; } default: { LOG_ERROR("Unable to determine property for %s (%d) format object", ((VhpiImpl*)GpiObjHdl::m_impl)->format_to_string(m_value.format), m_value.format); } } if (m_num_elems) { m_binvalue.bufSize = m_num_elems*sizeof(vhpiCharT) + 1; m_binvalue.value.str = (vhpiCharT *)calloc(m_binvalue.bufSize, sizeof(vhpiCharT)); if (!m_binvalue.value.str) { LOG_CRITICAL("Unable to alloc mem for read buffer of signal %s", name.c_str()); } } gpi_init: return GpiObjHdl::initialise(name, fq_name); }
// this function adds new object to structure TValObjPtrs* addValObj( vhpiHandleT _hNewHandle, TValObjPtrs* _pActualPointer, int _nActualSize ) { TValObjPtrs hNewHandle; hNewHandle.hHdl = _hNewHandle; hNewHandle.vValue = getFieldValue( _hNewHandle ); hNewHandle.nIndex = _nActualSize; hNewHandle.nType = 0; for ( int i = 0; i < 10; i++ ) { hNewHandle.enumOnes[i] = -1; hNewHandle.enumZeros[i] = -1; } hNewHandle.enumMin = 2147483647; hNewHandle.enumMax = 0; hNewHandle.szName = strdup( (char*)vhpi_get_str( vhpiNameP, _hNewHandle ) ); hNewHandle.pBoolVar = new bool; hNewHandle.pIntVar = new int; hNewHandle.pRealVar = new double; hNewHandle.pUserVars = NULL; if ( _hNewHandle ) { if ( ( hNewHandle.vValue->format >= vhpiEnumVecVal ) && ( hNewHandle.vValue->format <= vhpiRealVecVal ) ) { // if array type ports, when numElems is defined hNewHandle.pBoolVecVar = new bool [hNewHandle.vValue->numElems]; hNewHandle.pIntVecVar = new int [hNewHandle.vValue->numElems]; hNewHandle.pRealVecVar = new double [hNewHandle.vValue->numElems]; } else { hNewHandle.pBoolVecVar = new bool; hNewHandle.pIntVecVar = new int; hNewHandle.pRealVecVar = new double; } // detect binary logic enum types to enable numerical conversions if ( ( hNewHandle.vValue->format == vhpiEnumVal ) || ( hNewHandle.vValue->format == vhpiEnumVecVal ) ) { vhpiHandleT hLiteralIt = NULL; vhpiHandleT hLiteralHdl = NULL; vhpiHandleT hTypeHdl = NULL; int nTypeIndex = 0; int nOnesIndex = 0; int nZerosIndex = 0; // get handle to object type hTypeHdl = vhpi_handle( vhpiBaseType, _hNewHandle ); // iterate on all literals of scalar type if (( hLiteralIt = vhpi_iterator( vhpiEnumLiterals, hTypeHdl ) )); // iterate on all literals of array's element type else (( hLiteralIt = vhpi_iterator( vhpiEnumLiterals, vhpi_handle( vhpiElemSubtype, hTypeHdl ) ) )); if ( hLiteralIt ) while (( hLiteralHdl = vhpi_scan( hLiteralIt ) )) { // get literal string value char* szStrVal; szStrVal = strdup( (char*)vhpi_get_str( vhpiStrValP, hLiteralHdl ) ); // get its position (index) in enum type nTypeIndex = vhpi_get( vhpiPositionP, hLiteralHdl ); // set the limits of indexes in enum type if ( nTypeIndex > hNewHandle.enumMax ) hNewHandle.enumMax = nTypeIndex; if ( nTypeIndex < hNewHandle.enumMin ) hNewHandle.enumMin = nTypeIndex; // check if literal string value belongs to binary logic values set if ( ( strcmp( szStrVal, "1" ) == 0 ) || ( strcmp( szStrVal, "H" ) == 0 ) ) // store indexes of literals treated as one in numeric calculations hNewHandle.enumOnes[nOnesIndex++] = nTypeIndex; else if ( ( strcmp( szStrVal, "0" ) == 0 ) || ( strcmp( szStrVal, "L" ) == 0 ) ) // store indexes of literals treated as zero in numeric calculations hNewHandle.enumZeros[nZerosIndex++] = nTypeIndex; free( szStrVal ); } else vhpi_printf( "addVAlObj(): No enum literals found.\n" ); // if type contains one and zero literals if ( ( nZerosIndex != 0 ) && ( nOnesIndex != 0 ) ) hNewHandle.nType = 1; // release handles vhpi_release_handle( hTypeHdl ); vhpi_release_handle( hLiteralHdl ); } } // reallocate array appended with new structure TValObjPtrs* hTempHandle; int index; // allocate memory for copy of actual handles array hTempHandle = new TValObjPtrs [_nActualSize+1]; // copy array contents for ( index = 0; index < _nActualSize; index++ ) { hTempHandle[index] = _pActualPointer[index]; } // append array with new object handle hTempHandle[index++] = hNewHandle; // remove actual array from memory delete [] _pActualPointer ; // allocate memory for new actual array _pActualPointer = new TValObjPtrs [_nActualSize+1]; // copy array contents from temp array for ( index = 0; index < _nActualSize + 1; index++ ) { _pActualPointer[index] = hTempHandle[index]; } // remove temp array delete [] hTempHandle; return _pActualPointer; }