void SymbolTable::closeScope() // be responsible for release Attributes. { for (UnitSymtab::iterator i = currentSymtab().begin(); i != currentSymtab().end(); ++i) { delete i->second; } symtabStack_.pop_back(); }
/** * emitPostCall * * Save callee-saved regs * extend AR for locals * find static data area * initialize locals * fall through to code * @return index to label in symbol table for caller methods */ void emitPostCall(DList instList, SymtabStack symtabStack, int index, int frameSize){ SymTable symtab = currentSymtab(symtabStack); SymTable symtab_0 = lastSymtab(symtabStack); char* name = (char*)SymGetFieldByIndex(symtab_0, index,SYM_NAME_FIELD); char* inst = nssave(2,name,":"); dlinkAppend(instList,dlinkNodeAlloc(inst)); //save $ra inst = ssave("\tsw $ra,76($sp)"); dlinkAppend(instList,dlinkNodeAlloc(inst)); char regN[5]; char frameStr[10]; int si = 0; //save s0-s7 regs for( ; si<8; si++){ sprintf(regN,"$s%d,%d($sp)",si,(si*4)+4); inst = nssave(2,"\tsw ",regN); dlinkAppend(instList,dlinkNodeAlloc(inst)); } inst = ssave("\tmove $fp,$sp"); dlinkAppend(instList,dlinkNodeAlloc(inst)); //allocate room for any local variables if (frameSize != 0) { sprintf(frameStr,"%d",frameSize); inst = nssave(2,"\taddi $sp,$sp,",frameStr); dlinkAppend(instList,dlinkNodeAlloc(inst)); //store any local variables on the stack(kind of) int i = 0; int max = SymMaxIndex(symtab); int offset = 0; for(;i<=max;i++) { offset = -(int)SymGetFieldByIndex(symtab,i,SYMTAB_OFFSET_FIELD); SymPutFieldByIndex(symtab,i,SYMTAB_OFFSET_FIELD,(Generic)offset); } } }
bool SymbolTable::enterSymbol(const string & name, Attributes *attr) { return currentSymtab().insert( UnitSymtab::value_type(name, attr) ).second; }
bool SymbolTable::declaredLocally(const string & name) { return currentSymtab().find(name) != currentSymtab().end(); }