bool FliImpl::isValueLogic(mtiTypeIdT type) { mtiInt32T numEnums = mti_TickLength(type); if (numEnums == 2) { char **enum_values = mti_GetEnumValues(type); std::string str0 = enum_values[0]; std::string str1 = enum_values[1]; if (str0.compare("'0'") == 0 && str1.compare("'1'") == 0) { return true; } } else if (numEnums == 9) { const char enums[9][4] = {"'U'","'X'","'0'","'1'","'Z'","'W'","'L'","'H'","'-'"}; char **enum_values = mti_GetEnumValues(type); for (int i = 0; i < 9; i++) { std::string str = enum_values[i]; if (str.compare(enums[i]) != 0) { return false; } } return true; } return false; }
int FliVariableObjHdl::initialise(std::string &name) { /* Pre allocte buffers on signal type basis */ m_fli_type = mti_GetTypeKind(mti_GetVarType(m_fli_hdl)); switch (m_fli_type) { case MTI_TYPE_ENUM: m_val_len = 1; break; case MTI_TYPE_SCALAR: case MTI_TYPE_PHYSICAL: m_val_len = 32; break; case MTI_TYPE_ARRAY: m_val_len = mti_TickLength(mti_GetVarType(m_fli_hdl)); m_mti_buff = (mtiInt32T*)malloc(sizeof(*m_mti_buff) * m_val_len); if (!m_mti_buff) { LOG_CRITICAL("Unable to alloc mem for signal mti read buffer: ABORTING"); } break; default: LOG_ERROR("Unable to handle object type for %s (%d)", name.c_str(), m_fli_type); } m_val_buff = (char*)malloc(m_val_len+1); if (!m_val_buff) { LOG_CRITICAL("Unable to alloc mem for signal read buffer: ABORTING"); } m_val_buff[m_val_len] = '\0'; GpiObjHdl::initialise(name); return 0; }
/** * convert_logic_vector_to_int() - Convert a multibit signal into the * corresponding numerical value * * @vec: std_logic_vector signal to convert * * Return: 32-bit integer equivalent to the input signal */ int convert_logic_vector_to_int(mtiSignalIdT vec) { mtiSignalIdT *elems_list; mtiTypeIdT sig_type; mtiInt32T num_elems; int data; int i; /* Get an handle to the type of the given signal */ sig_type = mti_GetSignalType(vec); /* Get the number of elements that compose the vector */ num_elems = mti_TickLength(sig_type); assert(num_elems <= 25); /* Extract the list of individual elements */ elems_list = mti_GetSignalSubelements(vec, 0); data = 0; for (i = 0; i < num_elems; ++i) { /* If a 1 is received, increment the corresponding bit of the result */ if (mti_GetSignalValue(elems_list[i]) == STD_LOGIC_1) { data += 1 << (num_elems - i - 1); } } mti_VsimFree(elems_list); return data; }
int FliEnumObjHdl::initialise(std::string &name, std::string &fq_name) { m_num_elems = 1; m_value_enum = mti_GetEnumValues(m_val_type); m_num_enum = mti_TickLength(m_val_type); return FliValueObjHdl::initialise(name, fq_name); }
int FliLogicObjHdl::initialise(std::string &name, std::string &fq_name) { switch (m_fli_type) { case MTI_TYPE_ENUM: m_num_elems = 1; m_value_enum = mti_GetEnumValues(m_val_type); m_num_enum = mti_TickLength(m_val_type); break; case MTI_TYPE_ARRAY: { mtiTypeIdT elemType = mti_GetArrayElementType(m_val_type); m_range_left = mti_TickLeft(m_val_type); m_range_right = mti_TickRight(m_val_type); m_num_elems = mti_TickLength(m_val_type); m_indexable = true; m_value_enum = mti_GetEnumValues(elemType); m_num_enum = mti_TickLength(elemType); m_mti_buff = (char*)malloc(sizeof(*m_mti_buff) * m_num_elems); if (!m_mti_buff) { LOG_CRITICAL("Unable to alloc mem for value object mti read buffer: ABORTING"); return -1; } } break; default: LOG_CRITICAL("Object type is not 'logic' for %s (%d)", name.c_str(), m_fli_type); return -1; } for (mtiInt32T i = 0; i < m_num_enum; i++) { m_enum_map[m_value_enum[i][1]] = i; // enum is of the format 'U' or '0', etc. } m_val_buff = (char*)malloc(m_num_elems+1); if (!m_val_buff) { LOG_CRITICAL("Unable to alloc mem for value object read buffer: ABORTING"); } m_val_buff[m_num_elems] = '\0'; return FliValueObjHdl::initialise(name, fq_name); }
int FliValueObjHdl::initialise(std::string &name, std::string &fq_name) { if (get_type() == GPI_ARRAY) { m_range_left = mti_TickLeft(m_val_type); m_range_right = mti_TickRight(m_val_type); m_num_elems = mti_TickLength(m_val_type); m_indexable = true; } return FliSignalObjHdl::initialise(name, fq_name); }
bool FliImpl::isValueBoolean(mtiTypeIdT type) { if (mti_TickLength(type) == 2) { char **enum_values = mti_GetEnumValues(type); std::string strFalse = enum_values[0]; std::string strTrue = enum_values[1]; if (strFalse.compare("FALSE") == 0 && strTrue.compare("TRUE") == 0) { return true; } } return false; }
/* This function is called by the simulator to initialize the * tester module. It makes a data structure of the tester's ports * (taken from the entity's port list) and creates a process which * will handle all the signal changes. */ void tester_init( mtiRegionIdT region, char *param, mtiInterfaceListT *generics, mtiInterfaceListT *ports ) { inst_rec_ptr ip; mtiInterfaceListT *p; int is_array_type; ip = (inst_rec_ptr)mti_Malloc(sizeof(inst_rec)); mti_AddRestartCB( mti_Free, ip ); /* Traverse the list of ports and get port names and widths. */ num_ports = 0; for ( p = ports; p; p = p->nxt ) { tester_ports[num_ports].name = p->name; is_array_type = (mti_GetTypeKind(p->type) == MTI_TYPE_ARRAY); tester_ports[num_ports].is_array_type = is_array_type; if ( is_array_type ) { tester_ports[num_ports].width = mti_TickLength(p->type); } else { tester_ports[num_ports].width = 1; } ip->ports[ num_ports] = p->u.port; ip->drivers[ num_ports] = mti_CreateDriver(p->u.port); tester_ports[num_ports].number = num_ports; num_ports++; } ip->test_values = mti_CreateProcess("test", test_value_proc, ip); /* Check for an optional parameter on the FOREIGN attribute that * indicates whether or not to display debug messages. */ if ( param && (strcmp(param, "verbose") == 0) ) { ip->verbose = 1; } else { ip->verbose = 0; } /* Open the vector file and process the first test/drive statement. */ if ( open_vector_file(ip) ) { read_next_statement(ip); } }
int FliStringObjHdl::initialise(std::string &name, std::string &fq_name) { m_num_elems = mti_TickLength(m_val_type); m_mti_buff = (char*)malloc(sizeof(char) * m_num_elems); if (!m_mti_buff) { LOG_CRITICAL("Unable to alloc mem for value object mti read buffer: ABORTING"); return -1; } m_val_buff = (char*)malloc(m_num_elems+1); if (!m_val_buff) { LOG_CRITICAL("Unable to alloc mem for value object read buffer: ABORTING"); return -1; } m_val_buff[m_num_elems] = '\0'; return FliValueObjHdl::initialise(name, fq_name); }
void FliIterator::populate_handle_list(FliIterator::OneToMany childType) { switch (childType) { case FliIterator::OTM_CONSTANTS: { mtiRegionIdT parent = m_parent->get_handle<mtiRegionIdT>(); mtiVariableIdT id; for (id = mti_FirstVarByRegion(parent); id; id = mti_NextVar()) { if (id) { m_vars.push_back(id); } } } break; case FliIterator::OTM_SIGNALS: { mtiRegionIdT parent = m_parent->get_handle<mtiRegionIdT>(); mtiSignalIdT id; for (id = mti_FirstSignal(parent); id; id = mti_NextSignal()) { if (id) { m_sigs.push_back(id); } } } break; case FliIterator::OTM_REGIONS: { mtiRegionIdT parent = m_parent->get_handle<mtiRegionIdT>(); mtiRegionIdT id; for (id = mti_FirstLowerRegion(parent); id; id = mti_NextRegion(id)) { if (id) { m_regs.push_back(id); } } } break; case FliIterator::OTM_SIGNAL_SUB_ELEMENTS: if (m_parent->get_type() == GPI_STRUCTURE) { mtiSignalIdT parent = m_parent->get_handle<mtiSignalIdT>(); mtiTypeIdT type = mti_GetSignalType(parent); mtiSignalIdT *ids = mti_GetSignalSubelements(parent,NULL); LOG_DEBUG("GPI_STRUCTURE: %d fields", mti_TickLength(type)); for (int i = 0; i < mti_TickLength(type); i++) { m_sigs.push_back(ids[i]); } mti_VsimFree(ids); } else if (m_parent->get_indexable()) { FliValueObjHdl *fli_obj = reinterpret_cast<FliValueObjHdl *>(m_parent); int left = m_parent->get_range_left(); int right = m_parent->get_range_right(); if (left > right) { for (int i = left; i >= right; i--) { m_sigs.push_back(static_cast<mtiSignalIdT>(fli_obj->get_sub_hdl(i))); } } else { for (int i = left; i <= right; i++) { m_sigs.push_back(static_cast<mtiSignalIdT>(fli_obj->get_sub_hdl(i))); } } } break; case FliIterator::OTM_VARIABLE_SUB_ELEMENTS: if (m_parent->get_type() == GPI_STRUCTURE) { mtiVariableIdT parent = m_parent->get_handle<mtiVariableIdT>(); mtiTypeIdT type = mti_GetVarType(parent); mtiVariableIdT *ids = mti_GetVarSubelements(parent,NULL); LOG_DEBUG("GPI_STRUCTURE: %d fields", mti_TickLength(type)); for (int i = 0; i < mti_TickLength(type); i++) { m_vars.push_back(ids[i]); } mti_VsimFree(ids); } else if (m_parent->get_indexable()) { FliValueObjHdl *fli_obj = reinterpret_cast<FliValueObjHdl *>(m_parent); int left = m_parent->get_range_left(); int right = m_parent->get_range_right(); if (left > right) { for (int i = left; i >= right; i--) { m_vars.push_back(static_cast<mtiVariableIdT>(fli_obj->get_sub_hdl(i))); } } else { for (int i = left; i <= right; i++) { m_vars.push_back(static_cast<mtiVariableIdT>(fli_obj->get_sub_hdl(i))); } } } break; default: LOG_WARN("Unhandled OneToMany Type (%d)", childType); } }
bool FliImpl::isValueChar(mtiTypeIdT type) { const int NUM_ENUMS_IN_CHAR_TYPE = 256; return (mti_TickLength(type) == NUM_ENUMS_IN_CHAR_TYPE); }