sc_addr SCsTranslator::resolveScAddr(sElement *el)
{
    assert(SC_ADDR_IS_EMPTY(el->addr));

    sc_addr addr;
    SC_ADDR_MAKE_EMPTY(addr);
    if (!el->idtf.empty())
    {
        // try to find in system identifiers
        tStringAddrMap::iterator it = mSysIdtfAddrs.find(el->idtf);
        if (it != mSysIdtfAddrs.end())
        {
            addr = it->second;
        } else
        {
            // try to find in global identifiers
            it = msGlobalIdtfAddrs.find(el->idtf);
            if (it != msGlobalIdtfAddrs.end())
                addr = it->second;
            else
            {
                // try to find in local identifiers
                it = mLocalIdtfAddrs.find(el->idtf);
                if (it != mLocalIdtfAddrs.end())
                    addr = it->second;
                else
                {
                    // resolve system identifier
                    sc_result res = sc_helper_find_element_by_system_identifier(mContext, el->idtf.c_str(), (sc_uint32)el->idtf.size(), &addr);
                    if (res == SC_RESULT_OK)
                        mSysIdtfAddrs[el->idtf] = addr;
                }
            }
        }
    }

    if (SC_ADDR_IS_NOT_EMPTY(addr))
    {
        sc_type t = 0;
        if (sc_memory_get_element_type(mContext, addr, &t) == SC_RESULT_OK)
            sc_memory_change_element_subtype(mContext, addr, ~sc_type_element_mask & (el->type | t));

        el->addr = addr;
        return addr;
    }

    // generate addr
    addr = createScAddr(el);


    // store in addrs map
    if (!el->idtf.empty())
    {
        switch (_getIdentifierVisibility(el->idtf))
        {
        case IdtfSystem:
            sc_helper_set_system_identifier(mContext, addr, el->idtf.c_str(), (sc_uint32)el->idtf.size());
            mSysIdtfAddrs[el->idtf] = addr;
            break;
        case IdtfLocal:
            mLocalIdtfAddrs[el->idtf] = addr;
            break;
        case IdtfGlobal:
            msGlobalIdtfAddrs[el->idtf] = addr;
            break;
        }

    }

    return addr;
}
Beispiel #2
0
bool ScMemoryContext::setElementSubtype(ScAddr const & addr, sc_type subtype)
{
    check_expr(isValid());
    return sc_memory_change_element_subtype(mContext, addr.mRealAddr, subtype) == SC_RESULT_OK;
}