[llvm] r179115 - [ms-inline asm] Use parsePrimaryExpr in lieu of parseExpression if we need to
Chad Rosier
mcrosier at apple.com
Tue Apr 9 12:34:59 PDT 2013
Author: mcrosier
Date: Tue Apr 9 14:34:59 2013
New Revision: 179115
URL: http://llvm.org/viewvc/llvm-project?rev=179115&view=rev
Log:
[ms-inline asm] Use parsePrimaryExpr in lieu of parseExpression if we need to
parse an identifier. Otherwise, parseExpression may parse multiple tokens,
which makes it impossible to properly compute an immediate displacement.
An example of such a case is the source operand (i.e., [Symbol + ImmDisp]) in
the below example:
__asm mov eax, [Symbol + ImmDisp]
The existing test cases exercise this patch.
rdar://13611297
Modified:
llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h?rev=179115&r1=179114&r2=179115&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Tue Apr 9 14:34:59 2013
@@ -151,6 +151,13 @@ public:
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
bool parseExpression(const MCExpr *&Res);
+ /// parsePrimaryExpr - Parse a primary expression.
+ ///
+ /// @param Res - The value of the expression. The result is undefined
+ /// on error.
+ /// @result - False on success.
+ virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) = 0;
+
/// parseParenExpression - Parse an arbitrary expression, assuming that an
/// initial '(' has already been consumed.
///
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=179115&r1=179114&r2=179115&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Apr 9 14:34:59 2013
@@ -221,6 +221,7 @@ public:
bool parseExpression(const MCExpr *&Res);
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc);
+ virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);
virtual bool parseAbsoluteExpression(int64_t &Res);
@@ -869,6 +870,10 @@ bool AsmParser::parseExpression(const MC
return parseExpression(Res, EndLoc);
}
+bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
+ return ParsePrimaryExpr(Res, EndLoc);
+}
+
const MCExpr *
AsmParser::ApplyModifierToExpr(const MCExpr *E,
MCSymbolRefExpr::VariantKind Variant) {
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=179115&r1=179114&r2=179115&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Tue Apr 9 14:34:59 2013
@@ -1130,7 +1130,7 @@ X86Operand *X86AsmParser::ParseIntelBrac
if (ParseRegister(TmpReg, Start, End)) {
const MCExpr *Disp;
SMLoc IdentStart = Tok.getLoc();
- if (getParser().parseExpression(Disp, End))
+ if (getParser().parsePrimaryExpr(Disp, End))
return 0;
if (X86Operand *Err = ParseIntelVarWithQualifier(Disp, IdentStart))
@@ -1182,7 +1182,7 @@ X86Operand *X86AsmParser::ParseIntelBrac
SM.onRegister(TmpReg);
UpdateLocLex = false;
break;
- } else if (!getParser().parseExpression(Disp, End)) {
+ } else if (!getParser().parsePrimaryExpr(Disp, End)) {
SM.onDispExpr();
UpdateLocLex = false;
break;
@@ -1324,7 +1324,7 @@ X86Operand *X86AsmParser::ParseIntelMemO
const MCExpr *Disp = 0;
SMLoc IdentStart = Tok.getLoc();
- if (getParser().parseExpression(Disp, End))
+ if (getParser().parsePrimaryExpr(Disp, End))
return 0;
if (!isParsingInlineAsm())
@@ -1401,7 +1401,7 @@ X86Operand *X86AsmParser::ParseIntelOffs
SMLoc End;
const MCExpr *Val;
- if (getParser().parseExpression(Val, End))
+ if (getParser().parsePrimaryExpr(Val, End))
return ErrorOperand(Start, "Unable to parse expression!");
// Don't emit the offset operator.
@@ -1437,7 +1437,7 @@ X86Operand *X86AsmParser::ParseIntelOper
SMLoc End;
const MCExpr *Val;
- if (getParser().parseExpression(Val, End))
+ if (getParser().parsePrimaryExpr(Val, End))
return 0;
unsigned Length = 0, Size = 0, Type = 0;
More information about the llvm-commits
mailing list