mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-17 00:50:58 +00:00
[MC] Add support for GNU as-compatible binary operator precedence
GNU as and Darwin give the various binary operators different precedence. LLVM's MC supported the Darwin semantics but not the GNU semantics. This fixes PR25311. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251271 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7e2b51ddb0
commit
434302d503
@ -1101,8 +1101,9 @@ bool AsmParser::parseAbsoluteExpression(int64_t &Res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned AsmParser::getBinOpPrecedence(AsmToken::TokenKind K,
|
||||
MCBinaryExpr::Opcode &Kind) {
|
||||
static unsigned getDarwinBinOpPrecedence(AsmToken::TokenKind K,
|
||||
MCBinaryExpr::Opcode &Kind,
|
||||
bool ShouldUseLogicalShr) {
|
||||
switch (K) {
|
||||
default:
|
||||
return 0; // not a binop.
|
||||
@ -1154,7 +1155,7 @@ unsigned AsmParser::getBinOpPrecedence(AsmToken::TokenKind K,
|
||||
Kind = MCBinaryExpr::Shl;
|
||||
return 4;
|
||||
case AsmToken::GreaterGreater:
|
||||
Kind = MAI.shouldUseLogicalShr() ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
|
||||
Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
|
||||
return 4;
|
||||
|
||||
// High Intermediate Precedence: +, -
|
||||
@ -1178,6 +1179,89 @@ unsigned AsmParser::getBinOpPrecedence(AsmToken::TokenKind K,
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned getGNUBinOpPrecedence(AsmToken::TokenKind K,
|
||||
MCBinaryExpr::Opcode &Kind,
|
||||
bool ShouldUseLogicalShr) {
|
||||
switch (K) {
|
||||
default:
|
||||
return 0; // not a binop.
|
||||
|
||||
// Lowest Precedence: &&, ||
|
||||
case AsmToken::AmpAmp:
|
||||
Kind = MCBinaryExpr::LAnd;
|
||||
return 2;
|
||||
case AsmToken::PipePipe:
|
||||
Kind = MCBinaryExpr::LOr;
|
||||
return 1;
|
||||
|
||||
// Low Precedence: ==, !=, <>, <, <=, >, >=
|
||||
case AsmToken::EqualEqual:
|
||||
Kind = MCBinaryExpr::EQ;
|
||||
return 3;
|
||||
case AsmToken::ExclaimEqual:
|
||||
case AsmToken::LessGreater:
|
||||
Kind = MCBinaryExpr::NE;
|
||||
return 3;
|
||||
case AsmToken::Less:
|
||||
Kind = MCBinaryExpr::LT;
|
||||
return 3;
|
||||
case AsmToken::LessEqual:
|
||||
Kind = MCBinaryExpr::LTE;
|
||||
return 3;
|
||||
case AsmToken::Greater:
|
||||
Kind = MCBinaryExpr::GT;
|
||||
return 3;
|
||||
case AsmToken::GreaterEqual:
|
||||
Kind = MCBinaryExpr::GTE;
|
||||
return 3;
|
||||
|
||||
// Low Intermediate Precedence: +, -
|
||||
case AsmToken::Plus:
|
||||
Kind = MCBinaryExpr::Add;
|
||||
return 4;
|
||||
case AsmToken::Minus:
|
||||
Kind = MCBinaryExpr::Sub;
|
||||
return 4;
|
||||
|
||||
// High Intermediate Precedence: |, &, ^
|
||||
//
|
||||
// FIXME: gas seems to support '!' as an infix operator?
|
||||
case AsmToken::Pipe:
|
||||
Kind = MCBinaryExpr::Or;
|
||||
return 5;
|
||||
case AsmToken::Caret:
|
||||
Kind = MCBinaryExpr::Xor;
|
||||
return 5;
|
||||
case AsmToken::Amp:
|
||||
Kind = MCBinaryExpr::And;
|
||||
return 5;
|
||||
|
||||
// Highest Precedence: *, /, %, <<, >>
|
||||
case AsmToken::Star:
|
||||
Kind = MCBinaryExpr::Mul;
|
||||
return 6;
|
||||
case AsmToken::Slash:
|
||||
Kind = MCBinaryExpr::Div;
|
||||
return 6;
|
||||
case AsmToken::Percent:
|
||||
Kind = MCBinaryExpr::Mod;
|
||||
return 6;
|
||||
case AsmToken::LessLess:
|
||||
Kind = MCBinaryExpr::Shl;
|
||||
return 6;
|
||||
case AsmToken::GreaterGreater:
|
||||
Kind = ShouldUseLogicalShr ? MCBinaryExpr::LShr : MCBinaryExpr::AShr;
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned AsmParser::getBinOpPrecedence(AsmToken::TokenKind K,
|
||||
MCBinaryExpr::Opcode &Kind) {
|
||||
bool ShouldUseLogicalShr = MAI.shouldUseLogicalShr();
|
||||
return IsDarwin ? getDarwinBinOpPrecedence(K, Kind, ShouldUseLogicalShr)
|
||||
: getGNUBinOpPrecedence(K, Kind, ShouldUseLogicalShr);
|
||||
}
|
||||
|
||||
/// \brief Parse all binary operators with precedence >= 'Precedence'.
|
||||
/// Res contains the LHS of the expression on input.
|
||||
bool AsmParser::parseBinOpRHS(unsigned Precedence, const MCExpr *&Res,
|
||||
|
@ -413,7 +413,7 @@ fcmovae %st(1), %st(0) // CHECK: fcmovnb %st(1), %st(0)
|
||||
fcmova %st(1), %st(0) // CHECK: fcmovnbe %st(1), %st(0)
|
||||
|
||||
// rdar://8456417
|
||||
.byte 88 + 1 & 15 // CHECK: .byte 9
|
||||
.byte (88 + 1) & 15 // CHECK: .byte 9
|
||||
|
||||
// rdar://8456412
|
||||
mov %rdx, %cr0
|
||||
|
Loading…
Reference in New Issue
Block a user