aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2012-01-13 19:12:18 +0000
committerDevang Patel <dpatel@apple.com>2012-01-13 19:12:18 +0000
commitc798cc42831150f678b080c0994c1cc024bae653 (patch)
tree50e11748954e0ff0d8b1c42d526b10c4ad8243f8
parent4a5c0fd70e7a2001b682c8972dab6b0127313c8f (diff)
downloadexternal_llvm-c798cc42831150f678b080c0994c1cc024bae653.zip
external_llvm-c798cc42831150f678b080c0994c1cc024bae653.tar.gz
external_llvm-c798cc42831150f678b080c0994c1cc024bae653.tar.bz2
Refactor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148131 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/AsmParser/X86AsmParser.cpp86
1 files changed, 46 insertions, 40 deletions
diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp
index ce3831f..0a8f00d 100644
--- a/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -48,6 +48,7 @@ private:
X86Operand *ParseOperand();
X86Operand *ParseATTOperand();
X86Operand *ParseIntelOperand();
+ X86Operand *ParseIntelMemOperand(StringRef TokenString, unsigned Size);
X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
bool ParseDirectiveWord(unsigned Size, SMLoc L);
@@ -573,59 +574,64 @@ static bool isIntelMemOperand(StringRef OpStr, unsigned &Size) {
return Size != 0;
}
-X86Operand *X86AsmParser::ParseIntelOperand() {
-
- const AsmToken &Tok = Parser.getTok();
+/// ParseIntelMemOperand - Parse intel style memory operand.
+X86Operand *X86AsmParser::ParseIntelMemOperand(StringRef TokenString,
+ unsigned Size) {
SMLoc Start = Parser.getTok().getLoc(), End;
-
- // register
- if(unsigned RegNo = getIntelRegisterOperand(Tok.getString())) {
- Parser.Lex();
- End = Parser.getTok().getLoc();
- return X86Operand::CreateReg(RegNo, Start, End);
- }
-
- // mem operand
unsigned SegReg = 0, BaseReg = 0, IndexReg = 0, Scale = 1;
- StringRef OpStr = Tok.getString();
- unsigned Size = 0;
- if (isIntelMemOperand(OpStr, Size)) {
+ Parser.Lex();
+ if (TokenString == "PTR")
Parser.Lex();
- if (Tok.getString() == "PTR")
- Parser.Lex();
else {
Error(Start, "unexpected token!");
return 0;
}
+
+ if (TokenString == "[")
+ Parser.Lex();
+ else {
+ Error(Start, "unexpected token!");
+ return 0;
+ }
+
+ SMLoc LParenLoc = Parser.getTok().getLoc();
+ BaseReg = getIntelRegisterOperand(TokenString);
+ if (BaseReg == 0) {
+ Error(LParenLoc, "unexpected token!");
+ return 0;
+ }
+ Parser.Lex();
+ const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
+ SMLoc ExprEnd;
+ if (getParser().ParseExpression(Disp, ExprEnd)) return 0;
+ End = Parser.getTok().getLoc();
+ if (TokenString == "]")
+ Parser.Lex();
+ if (BaseReg == 0) {
+ Error(End, "unexpected token!");
+ return 0;
+ }
+ return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
+ Start, End, Size);
+}
- if (Tok.getString() == "[")
- Parser.Lex();
- else {
- Error(Start, "unexpected token!");
- return 0;
- }
+X86Operand *X86AsmParser::ParseIntelOperand() {
- SMLoc LParenLoc = Parser.getTok().getLoc();
- BaseReg = getIntelRegisterOperand(Tok.getString());
- if (BaseReg == 0) {
- Error(LParenLoc, "unexpected token!");
- return 0;
- }
+ StringRef TokenString = Parser.getTok().getString();
+ SMLoc Start = Parser.getTok().getLoc(), End;
+
+ // register
+ if(unsigned RegNo = getIntelRegisterOperand(TokenString)) {
Parser.Lex();
- const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
- SMLoc ExprEnd;
- if (getParser().ParseExpression(Disp, ExprEnd)) return 0;
End = Parser.getTok().getLoc();
- if (Tok.getString() == "]")
- Parser.Lex();
- if (BaseReg == 0) {
- Error(End, "unexpected token!");
- return 0;
- }
- return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
- Start, End, Size);
+ return X86Operand::CreateReg(RegNo, Start, End);
}
+ // mem operand
+ unsigned Size = 0;
+ if (isIntelMemOperand(TokenString, Size))
+ ParseIntelMemOperand(TokenString, Size);
+
// immediate.
const MCExpr *Val;
if (!getParser().ParseExpression(Val, End)) {