Пример #1
0
int FliObjHdl::initialise(std::string &name, std::string &fq_name)
{
    bool is_signal = (get_acc_type() == accSignal || get_acc_full_type() == accAliasSignal);
    mtiTypeIdT typeId;

    switch (get_type()) {
    case GPI_STRUCTURE:
        if (is_signal) {
            typeId = mti_GetSignalType(get_handle<mtiSignalIdT>());
        } else {
            typeId = mti_GetVarType(get_handle<mtiVariableIdT>());
        }

        m_num_elems = mti_GetNumRecordElements(typeId);
        break;
    case GPI_GENARRAY:
        m_indexable = true;
    case GPI_MODULE:
        m_num_elems = 1;
        break;
    default:
        LOG_CRITICAL("Invalid object type for FliObjHdl. (%s (%s))", name.c_str(), get_type_str());
        return -1;
    }

    return GpiObjHdl::initialise(name, fq_name);
}
Пример #2
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;
}
Пример #3
0
int FliSignalObjHdl::initialise(std::string &name)
{
    /* Pre allocte buffers on signal type basis */
    m_fli_type = mti_GetTypeKind(mti_GetSignalType(m_fli_hdl));

    switch (m_fli_type) {
        case MTI_TYPE_ENUM:
            m_val_len = 1;
            m_val_buff = (char*)malloc(m_val_len+1);
            if (!m_val_buff) {
                LOG_CRITICAL("Unable to alloc mem for signal read buffer");
            }
            m_val_buff[m_val_len] = '\0';
            break;
        case MTI_TYPE_SCALAR:
        case MTI_TYPE_PHYSICAL:
            m_val_len = 32;
            m_val_buff = (char*)malloc(m_val_len+1);
            if (!m_val_buff) {
                LOG_CRITICAL("Unable to alloc mem for signal read buffer");
            }
            m_val_buff[m_val_len] = '\0';
            break;
        case MTI_TYPE_ARRAY:
            m_val_len = mti_TickLength(mti_GetSignalType(m_fli_hdl));
            m_val_buff = (char*)malloc(m_val_len+1);
            if (!m_val_buff) {
                LOG_CRITICAL("Unable to alloc mem for signal read buffer");
            }
            m_val_buff[m_val_len] = '\0';
            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");
            }
            break;
        default:
            LOG_CRITICAL("Unable to handle onject type for %s (%d)",
                         name.c_str(), m_fli_type);
    }

    GpiObjHdl::initialise(name);

    return 0;
}
Пример #4
0
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);
    }
}
Пример #5
0
GpiObjHdl *FliImpl::create_gpi_obj_from_handle(void *hdl, std::string &name, std::string &fq_name, int accType, int accFullType)
{
    GpiObjHdl *new_obj = NULL;

    LOG_DEBUG("Attepmting to create GPI object from handle (Type=%d, FullType=%d).", accType, accFullType);
    if (!VS_TYPE_IS_VHDL(accFullType)) {
        LOG_DEBUG("Handle is not a VHDL type.");
        return NULL;
    }

    if (!isTypeValue(accType)) {
        /* Need a Pseudo-region to handle generate loops in a consistent manner across interfaces
         * and across the different methods of accessing data.
         */
        std::string rgn_name = mti_GetRegionName(static_cast<mtiRegionIdT>(hdl));
        if (name != rgn_name) {
            LOG_DEBUG("Found pseudo-region %s -> %p", fq_name.c_str(), hdl);
            new_obj = new FliObjHdl(this, hdl, GPI_GENARRAY, accType, accFullType);
        } else {
            LOG_DEBUG("Found region %s -> %p", fq_name.c_str(), hdl);
            new_obj = new FliObjHdl(this, hdl, GPI_MODULE, accType, accFullType);
        }
    } else {
        bool is_var;
        bool is_const;
        mtiTypeIdT valType;
        mtiTypeKindT typeKind;

        if (isTypeSignal(accType, accFullType)) {
            LOG_DEBUG("Found a signal %s -> %p", fq_name.c_str(), hdl);
            is_var   = false;
            is_const = false;
            valType  = mti_GetSignalType(static_cast<mtiSignalIdT>(hdl));
        } else {
            LOG_DEBUG("Found a variable %s -> %p", fq_name.c_str(), hdl);
            is_var   = true;
            is_const = isValueConst(accFullType);
            valType  = mti_GetVarType(static_cast<mtiVariableIdT>(hdl));
        }

        typeKind = mti_GetTypeKind(valType);

        switch (typeKind) {
            case MTI_TYPE_ENUM:
                if (isValueLogic(valType)) {
                    new_obj = new FliLogicObjHdl(this, hdl, GPI_REGISTER, is_const, accType, accFullType, is_var, valType, typeKind);
                } else if (isValueBoolean(valType) || isValueChar(valType)) {
                    new_obj = new FliIntObjHdl(this, hdl, GPI_INTEGER, is_const, accType, accFullType, is_var, valType, typeKind);
                } else {
                    new_obj = new FliEnumObjHdl(this, hdl, GPI_ENUM, is_const, accType, accFullType, is_var, valType, typeKind);
                }
                break;
            case MTI_TYPE_SCALAR:
            case MTI_TYPE_PHYSICAL:
                new_obj = new FliIntObjHdl(this, hdl, GPI_INTEGER, is_const, accType, accFullType, is_var, valType, typeKind);
                break;
            case MTI_TYPE_REAL:
                new_obj = new FliRealObjHdl(this, hdl, GPI_REAL, is_const, accType, accFullType, is_var, valType, typeKind);
                break;
            case MTI_TYPE_ARRAY: {
                    mtiTypeIdT   elemType     = mti_GetArrayElementType(valType);
                    mtiTypeKindT elemTypeKind = mti_GetTypeKind(elemType);

                    switch (elemTypeKind) {
                        case MTI_TYPE_ENUM:
                            if (isValueLogic(elemType)) {
                                new_obj = new FliLogicObjHdl(this, hdl, GPI_REGISTER, is_const, accType, accFullType, is_var, valType, typeKind); // std_logic_vector
                            } else if (isValueChar(elemType)) {
                                new_obj = new FliStringObjHdl(this, hdl, GPI_STRING, is_const, accType, accFullType, is_var, valType, typeKind);
                            } else {
                                new_obj = new FliValueObjHdl(this, hdl, GPI_ARRAY, false, accType, accFullType, is_var, valType, typeKind); // array of enums
                            }
                            break;
                        default:
                            new_obj = new FliValueObjHdl(this, hdl, GPI_ARRAY, false, accType, accFullType, is_var, valType, typeKind);// array of (array, Integer, Real, Record, etc.) 
                    }
                }
                break;
            case MTI_TYPE_RECORD:
                new_obj = new FliValueObjHdl(this, hdl, GPI_STRUCTURE, false, accType, accFullType, is_var, valType, typeKind);
                break;
            default:
                LOG_ERROR("Unable to handle object type for %s (%d)", name.c_str(), typeKind);
                return NULL;
        }
    }

    if (NULL == new_obj) {
        LOG_DEBUG("Didn't find anything named %s", fq_name.c_str());
        return NULL;
    }

    if (new_obj->initialise(name,fq_name) < 0) {
        LOG_ERROR("Failed to initialise the handle %s", name.c_str());
        delete new_obj;
        return NULL;
    }

    return new_obj;
}