[llvm-commits] [llvm] r126443 - in /llvm/trunk: include/llvm/MC/MCParser/MCAsmParserExtension.h lib/MC/MCParser/AsmParser.cpp lib/MC/MCParser/ELFAsmParser.cpp lib/MC/MCParser/MCAsmParserExtension.cpp test/MC/ARM/bracket-darwin.s test/MC/ELF/bracket-exprs.s test/MC/ELF/bracket.s
Joerg Sonnenberger
joerg at bec.de
Thu Feb 24 13:59:22 PST 2011
Author: joerg
Date: Thu Feb 24 15:59:22 2011
New Revision: 126443
URL: http://llvm.org/viewvc/llvm-project?rev=126443&view=rev
Log:
Restore r125595 (reverted in r126336) with modifications:
Introduce a variable in the AsmParserExtension whether [] is valid in an
expression. If it is true, parse them like (). Enable this for ELF only.
Added:
llvm/trunk/test/MC/ARM/bracket-darwin.s
llvm/trunk/test/MC/ELF/bracket-exprs.s
llvm/trunk/test/MC/ELF/bracket.s
Modified:
llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h?rev=126443&r1=126442&r2=126443&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h Thu Feb 24 15:59:22 2011
@@ -38,6 +38,8 @@
return (Obj->*Handler)(Directive, DirectiveLoc);
}
+ bool BracketExpressionsSupported;
+
public:
virtual ~MCAsmParserExtension();
@@ -68,6 +70,8 @@
const AsmToken &getTok() { return getParser().getTok(); }
+ bool HasBracketExpressions() const { return BracketExpressionsSupported; }
+
/// @}
};
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=126443&r1=126442&r2=126443&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Feb 24 15:59:22 2011
@@ -173,6 +173,7 @@
bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc);
bool ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc);
+ bool ParseBracketExpr(const MCExpr *&Res, SMLoc &EndLoc);
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
/// and set \arg Res to the identifier contents.
@@ -492,6 +493,20 @@
return false;
}
+/// ParseBracketExpr - Parse a bracket expression and return it.
+/// NOTE: This assumes the leading '[' has already been consumed.
+///
+/// bracketexpr ::= expr]
+///
+bool AsmParser::ParseBracketExpr(const MCExpr *&Res, SMLoc &EndLoc) {
+ if (ParseExpression(Res)) return true;
+ if (Lexer.isNot(AsmToken::RBrac))
+ return TokError("expected ']' in brackets expression");
+ EndLoc = Lexer.getLoc();
+ Lex();
+ return false;
+}
+
/// ParsePrimaryExpr - Parse a primary expression and return it.
/// primaryexpr ::= (parenexpr
/// primaryexpr ::= symbol
@@ -587,6 +602,11 @@
case AsmToken::LParen:
Lex(); // Eat the '('.
return ParseParenExpr(Res, EndLoc);
+ case AsmToken::LBrac:
+ if (!PlatformParser->HasBracketExpressions())
+ return TokError("brackets expression not supported on this target");
+ Lex(); // Eat the '['.
+ return ParseBracketExpr(Res, EndLoc);
case AsmToken::Minus:
Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res, EndLoc))
Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=126443&r1=126442&r2=126443&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Thu Feb 24 15:59:22 2011
@@ -33,7 +33,9 @@
bool SeenIdent;
public:
- ELFAsmParser() : SeenIdent(false) {}
+ ELFAsmParser() : SeenIdent(false) {
+ BracketExpressionsSupported = true;
+ }
virtual void Initialize(MCAsmParser &Parser) {
// Call the base implementation.
Modified: llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp?rev=126443&r1=126442&r2=126443&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/MCAsmParserExtension.cpp Thu Feb 24 15:59:22 2011
@@ -10,7 +10,8 @@
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
using namespace llvm;
-MCAsmParserExtension::MCAsmParserExtension() {
+MCAsmParserExtension::MCAsmParserExtension() :
+ BracketExpressionsSupported(false) {
}
MCAsmParserExtension::~MCAsmParserExtension() {
Added: llvm/trunk/test/MC/ARM/bracket-darwin.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/bracket-darwin.s?rev=126443&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/bracket-darwin.s (added)
+++ llvm/trunk/test/MC/ARM/bracket-darwin.s Thu Feb 24 15:59:22 2011
@@ -0,0 +1,5 @@
+// RUN: not llvm-mc -triple arm-apple-darwin %s 2> %t
+// RUN: FileCheck -input-file %t %s
+
+// CHECK: error: brackets expression not supported on this target
+.byte [4-3]
Added: llvm/trunk/test/MC/ELF/bracket-exprs.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/bracket-exprs.s?rev=126443&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/bracket-exprs.s (added)
+++ llvm/trunk/test/MC/ELF/bracket-exprs.s Thu Feb 24 15:59:22 2011
@@ -0,0 +1,16 @@
+// RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
+// RUN: llvm-mc -triple arm-unknown-linux %s | FileCheck %s
+
+// CHECK: .byte 1
+.if [~0 >> 1] == -1
+.byte 1
+.else
+.byte 2
+.endif
+
+// CHECK: .byte 3
+.if 4 * [4 + (3 + [2 * 2] + 1)] == 48
+.byte 3
+.else
+.byte 4
+.endif
Added: llvm/trunk/test/MC/ELF/bracket.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/bracket.s?rev=126443&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/bracket.s (added)
+++ llvm/trunk/test/MC/ELF/bracket.s Thu Feb 24 15:59:22 2011
@@ -0,0 +1,8 @@
+// RUN: not llvm-mc -triple i386-unknown-unknown %s 2> %t1 > %t2
+// RUN: FileCheck < %t1 %s
+
+// CHECK: error: expected ']' in brackets expression
+.size x, [.-x)
+
+// CHECK: error: expected ')' in parentheses expression
+.size y, (.-y]
More information about the llvm-commits
mailing list