bool Buffer::operator != (const Buffer &rhs) const { if (rhs.readAvailable() != readAvailable()) return true; return opCmp(rhs) != 0; }
bool Buffer::operator!= (const std::string &string) const { if (string.size() != readAvailable()) return true; return opCmp(string.c_str(), string.size()) != 0; }
bool Buffer::operator == (const Buffer &rhs) const { if (rhs.readAvailable() != readAvailable()) return false; return opCmp(rhs) == 0; }
bool Buffer::operator!= (const char *string) const { size_t length = strlen(string); if (length != readAvailable()) return true; return opCmp(string, length) != 0; }
int allocateRegForOp(Operand* op, FILE* fp){ //在varList中寻找op对应的变量的VarDes VarDes* var = varList; while(var!=NULL){ if(opCmp(var->op, op)==0) break; var = var->next; } //如果op对应的变量第一次被使用 则记录栈中相对于栈底($fp)的位置(偏移量) int isFirstUsed = FALSE; if(var == NULL){ isFirstUsed = TRUE; var = malloc(sizeof(VarDes)); memset(var, 0, sizeof(VarDes)); var->op = op; var->regNo = -1; if(var->op->kind == VAR_OP || var->op->kind == TEM_VAR_OP){ offset += 4; var->offset = offset; } if(var->op->kind != CONST_OP) addVarToList(var); } //如果op对应的变量没有被分配寄存器 则为其分配寄存器 if(var->regNo < 0){ int regNo = getReg(fp); var->regNo = regNo; regList[regNo].var = var; if(var->op->kind == CONST_OP||var->op->kind == ADDR_OP||(isFirstUsed==FALSE && var->offset>=0)){ //不是第一次出现的变量 ldVar(var, fp); } } //每次寄存器中的变量被使用 old字段就会置零 regList[var->regNo].old = 0; return var->regNo; }