mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126443 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
12d18a07a0
commit
93c65e6e66
@ -38,6 +38,8 @@ protected:
|
|||||||
return (Obj->*Handler)(Directive, DirectiveLoc);
|
return (Obj->*Handler)(Directive, DirectiveLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BracketExpressionsSupported;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~MCAsmParserExtension();
|
virtual ~MCAsmParserExtension();
|
||||||
|
|
||||||
@ -68,6 +70,8 @@ public:
|
|||||||
|
|
||||||
const AsmToken &getTok() { return getParser().getTok(); }
|
const AsmToken &getTok() { return getParser().getTok(); }
|
||||||
|
|
||||||
|
bool HasBracketExpressions() const { return BracketExpressionsSupported; }
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,6 +173,7 @@ private:
|
|||||||
bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
|
bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
|
||||||
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc);
|
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc);
|
||||||
bool ParseParenExpr(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)
|
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
|
||||||
/// and set \arg Res to the identifier contents.
|
/// and set \arg Res to the identifier contents.
|
||||||
@ -492,6 +493,20 @@ bool AsmParser::ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc) {
|
|||||||
return false;
|
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.
|
/// ParsePrimaryExpr - Parse a primary expression and return it.
|
||||||
/// primaryexpr ::= (parenexpr
|
/// primaryexpr ::= (parenexpr
|
||||||
/// primaryexpr ::= symbol
|
/// primaryexpr ::= symbol
|
||||||
@ -587,6 +602,11 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
|
|||||||
case AsmToken::LParen:
|
case AsmToken::LParen:
|
||||||
Lex(); // Eat the '('.
|
Lex(); // Eat the '('.
|
||||||
return ParseParenExpr(Res, EndLoc);
|
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:
|
case AsmToken::Minus:
|
||||||
Lex(); // Eat the operator.
|
Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res, EndLoc))
|
if (ParsePrimaryExpr(Res, EndLoc))
|
||||||
|
@ -33,7 +33,9 @@ class ELFAsmParser : public MCAsmParserExtension {
|
|||||||
bool SeenIdent;
|
bool SeenIdent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ELFAsmParser() : SeenIdent(false) {}
|
ELFAsmParser() : SeenIdent(false) {
|
||||||
|
BracketExpressionsSupported = true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void Initialize(MCAsmParser &Parser) {
|
virtual void Initialize(MCAsmParser &Parser) {
|
||||||
// Call the base implementation.
|
// Call the base implementation.
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
MCAsmParserExtension::MCAsmParserExtension() {
|
MCAsmParserExtension::MCAsmParserExtension() :
|
||||||
|
BracketExpressionsSupported(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MCAsmParserExtension::~MCAsmParserExtension() {
|
MCAsmParserExtension::~MCAsmParserExtension() {
|
||||||
|
5
test/MC/ARM/bracket-darwin.s
Normal file
5
test/MC/ARM/bracket-darwin.s
Normal file
@ -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]
|
16
test/MC/ELF/bracket-exprs.s
Normal file
16
test/MC/ELF/bracket-exprs.s
Normal file
@ -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
|
8
test/MC/ELF/bracket.s
Normal file
8
test/MC/ELF/bracket.s
Normal file
@ -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]
|
Loading…
Reference in New Issue
Block a user