__pu_value *reg_var(Pu *L, const PuString &varname) { __pu_value *got = NULL; VarMap *varmap = L->varstack.top(); VarMap::Bucket_T *it = varmap->find(varname); if (it != 0) { got = &(it->value); } else { VarMap *varmap = L->varstack.bottom(); VarMap::Bucket_T *it = varmap->find(varname); if (it != 0) { got = &(it->value); } } if (got == NULL) { VarMap *varmap = L->varstack.top(); VarMap::Bucket_T *ret = varmap->insert(varname, __pu_value(L)); got = &(ret->value); } return got; }
AstVarScope* createVarSc(AstVarScope* oldvarscp, string name, int width/*0==fromoldvar*/) { // Because we've already scoped it, we may need to add both the AstVar and the AstVarScope if (!oldvarscp->scopep()) oldvarscp->v3fatalSrc("Var unscoped"); AstVar* varp; AstNodeModule* addmodp = oldvarscp->scopep()->modp(); // We need a new AstVar, but only one for all scopes, to match the new AstVarScope VarMap::iterator iter = m_modVarMap.find(make_pair(addmodp,name)); if (iter != m_modVarMap.end()) { // Created module's AstVar earlier under some other scope varp = iter->second; } else { if (width==0) { varp = new AstVar (oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, oldvarscp->varp()); varp->widthSignedFrom(oldvarscp); } else { // Used for vset and dimensions, so can zero init varp = new AstVar (oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, AstBitPacked(), width); } addmodp->addStmtp(varp); m_modVarMap.insert(make_pair(make_pair(addmodp, name), varp)); } AstVarScope* varscp = new AstVarScope (oldvarscp->fileline(), oldvarscp->scopep(), varp); oldvarscp->scopep()->addVarp(varscp); return varscp; }
virtual void visit(AstVarRef* nodep, AstNUser*) { if (nodep->lvalue() && !nodep->user2()) { nodep->user2(true); // mark this ref as visited AstVar* key = nodep->varp(); VarMap::iterator it = m_lhsmapp->find(key); if (it == m_lhsmapp->end()) { // this key does not exist yet, so create it RefVec* refs = new RefVec(); refs->push_back(nodep); m_lhsmapp->insert(pair<AstVar*, RefVec*>(key, refs)); } else { (*it).second->push_back(nodep); } nodep->user3p(m_sel); // attach the sel to this varref } nodep->iterateChildren(*this); }