예제 #1
0
파일: symbol.cpp 프로젝트: Yang-Ho/Compiler
string SymbolTable::GetAddress(string name, string off) {
    Symbol* sym = LookUp(name);
    if (sym) {
        if (sym->GetType() == SYMBOL_PARAM) {
            if (sym->GetLoc() < 0) {
                sym->SetLoc(next_temp);
                return "Param";
            } else {
                stringstream ss;
                if (off == "") {
                    ss<<"local["<<sym->GetLoc()<<"]";
                } else {
                    ss<<"local["<<sym->GetLoc()<<"+"<<off<<"]";
                }
                return ss.str();
            }
        } else if (sym->GetType() == SYMBOL_FUNC) {
            return sym->GetName();
        } else if (sym->GetType() == SYMBOL_GLOBAL) {
            stringstream ss;
            if (off == "") {
                ss<<"global["<<sym->GetLoc()<<"]";
            } else {
                ss<<"global["<<sym->GetLoc()<<"+"<<off<<"]";
            }
            return ss.str();
        } else {
            stringstream ss;
            if (off == "") {
                ss<<"local["<<sym->GetLoc()<<"]";
            } else {
                ss<<"local["<<sym->GetLoc()<<"+"<<off<<"]";
            }
            return ss.str();
        }
    } else {
        return "";
    }
}