split MaybeParseRegister into its two logical uses, eliminating malloc+free traffic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117769 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-10-30 04:09:10 +00:00
parent 4b5236c966
commit e5658fa15e

View File

@ -49,7 +49,8 @@ private:
bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
ARMOperand *MaybeParseRegister(bool ParseWriteBack); int TryParseRegister();
ARMOperand *TryParseRegisterWithWriteBack();
ARMOperand *ParseRegisterList(); ARMOperand *ParseRegisterList();
ARMOperand *ParseMemory(); ARMOperand *ParseMemory();
@ -362,41 +363,45 @@ static unsigned MatchRegisterName(StringRef Name);
/// } /// }
/// Try to parse a register name. The token must be an Identifier when called, /// Try to parse a register name. The token must be an Identifier when called,
/// and if it is a register name the token is eaten and a Reg operand is created /// and if it is a register name the token is eaten and the register number is
/// and returned. Otherwise return null. /// returned. Otherwise return -1.
///
int ARMAsmParser::TryParseRegister() {
const AsmToken &Tok = Parser.getTok();
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
// FIXME: Validate register for the current architecture; we have to do
// validation later, so maybe there is no need for this here.
int RegNum = MatchRegisterName(Tok.getString());
if (RegNum == -1)
return -1;
Parser.Lex(); // Eat identifier token.
return RegNum;
}
/// Try to parse a register name. The token must be an Identifier when called,
/// and if it is a register name the token is eaten and the register number is
/// returned. Otherwise return -1.
/// ///
/// TODO this is likely to change to allow different register types and or to /// TODO this is likely to change to allow different register types and or to
/// parse for a specific register type. /// parse for a specific register type.
ARMOperand *ARMAsmParser::MaybeParseRegister(bool ParseWriteBack) { ARMOperand *ARMAsmParser::TryParseRegisterWithWriteBack() {
SMLoc S, E; SMLoc S = Parser.getTok().getLoc();
const AsmToken &Tok = Parser.getTok(); int RegNo = TryParseRegister();
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier"); if (RegNo == -1) return 0;
// FIXME: Validate register for the current architecture; we have to do SMLoc E = Parser.getTok().getLoc();
// validation later, so maybe there is no need for this here.
int RegNum;
RegNum = MatchRegisterName(Tok.getString());
if (RegNum == -1)
return 0;
S = Tok.getLoc();
Parser.Lex(); // Eat identifier token.
E = Parser.getTok().getLoc();
bool Writeback = false; bool Writeback = false;
if (ParseWriteBack) { const AsmToken &ExclaimTok = Parser.getTok();
const AsmToken &ExclaimTok = Parser.getTok(); if (ExclaimTok.is(AsmToken::Exclaim)) {
if (ExclaimTok.is(AsmToken::Exclaim)) { E = ExclaimTok.getLoc();
E = ExclaimTok.getLoc(); Writeback = true;
Writeback = true; Parser.Lex(); // Eat exclaim token
Parser.Lex(); // Eat exclaim token
}
} }
return ARMOperand::CreateReg(RegNum, Writeback, S, E); return ARMOperand::CreateReg(RegNo, Writeback, S, E);
} }
/// Parse a register list, return it if successful else return null. The first /// Parse a register list, return it if successful else return null. The first
@ -478,11 +483,8 @@ ARMOperand *ARMAsmParser::ParseMemory() {
Error(BaseRegTok.getLoc(), "register expected"); Error(BaseRegTok.getLoc(), "register expected");
return 0; return 0;
} }
int BaseRegNum = 0; int BaseRegNum = TryParseRegister();
if (ARMOperand *Op = MaybeParseRegister(false)) { if (BaseRegNum == -1) {
BaseRegNum = Op->getReg();
delete Op;
} else {
Error(BaseRegTok.getLoc(), "register expected"); Error(BaseRegTok.getLoc(), "register expected");
return 0; return 0;
} }
@ -593,13 +595,14 @@ bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
// See if there is a register following the "[Rn," or "[Rn]," we have so far. // See if there is a register following the "[Rn," or "[Rn]," we have so far.
const AsmToken &OffsetRegTok = Parser.getTok(); const AsmToken &OffsetRegTok = Parser.getTok();
if (OffsetRegTok.is(AsmToken::Identifier)) { if (OffsetRegTok.is(AsmToken::Identifier)) {
if (ARMOperand *Op = MaybeParseRegister(false)) { SMLoc CurLoc = OffsetRegTok.getLoc();
OffsetRegNum = TryParseRegister();
if (OffsetRegNum != -1) {
OffsetIsReg = true; OffsetIsReg = true;
E = Op->getEndLoc(); E = CurLoc;
OffsetRegNum = Op->getReg();
delete Op;
} }
} }
// If we parsed a register as the offset then their can be a shift after that // If we parsed a register as the offset then their can be a shift after that
if (OffsetRegNum != -1) { if (OffsetRegNum != -1) {
// Look for a comma then a shift // Look for a comma then a shift
@ -675,7 +678,7 @@ ARMOperand *ARMAsmParser::ParseOperand() {
switch (getLexer().getKind()) { switch (getLexer().getKind()) {
case AsmToken::Identifier: case AsmToken::Identifier:
if (ARMOperand *Op = MaybeParseRegister(true)) if (ARMOperand *Op = TryParseRegisterWithWriteBack())
return Op; return Op;
// This was not a register so parse other operands that start with an // This was not a register so parse other operands that start with an