mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
MC/AsmParser: Attempt to constant fold expressions up-front. This ensures we avoid fixups for obvious cases like '-(16)'.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96064 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
08b85f371e
commit
e9a60eb498
@ -325,9 +325,17 @@ bool AsmParser::ParseExpression(const MCExpr *&Res) {
|
||||
/// expr ::= primaryexpr
|
||||
///
|
||||
bool AsmParser::ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) {
|
||||
// Parse the expression.
|
||||
Res = 0;
|
||||
return ParsePrimaryExpr(Res, EndLoc) ||
|
||||
ParseBinOpRHS(1, Res, EndLoc);
|
||||
if (ParsePrimaryExpr(Res, EndLoc) || ParseBinOpRHS(1, Res, EndLoc))
|
||||
return true;
|
||||
|
||||
// Try to constant fold it up front, if possible.
|
||||
int64_t Value;
|
||||
if (Res->EvaluateAsAbsolute(Value))
|
||||
Res = MCConstantExpr::Create(Value, getContext());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AsmParser::ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) {
|
||||
|
@ -28,3 +28,9 @@
|
||||
swapgs
|
||||
// CHECK: swapgs
|
||||
// CHECK: encoding: [0x0f,0x01,0xf8]
|
||||
|
||||
// CHECK: movl %eax, 16(%ebp) # encoding: [0x89,0x45,0x10]
|
||||
movl %eax, 16(%ebp)
|
||||
// CHECK: movl %eax, -16(%ebp) # encoding: [0x89,0x45,0xf0]
|
||||
movl %eax, -16(%ebp)
|
||||
|
||||
|
@ -5,28 +5,28 @@
|
||||
# Immediates
|
||||
# CHECK: addl $1, %eax
|
||||
addl $1, %eax
|
||||
# CHECK: addl $1+2, %eax
|
||||
# CHECK: addl $3, %eax
|
||||
addl $(1+2), %eax
|
||||
# CHECK: addl $a, %eax
|
||||
addl $a, %eax
|
||||
# CHECK: addl $1+2, %eax
|
||||
# CHECK: addl $3, %eax
|
||||
addl $1 + 2, %eax
|
||||
|
||||
# Disambiguation
|
||||
|
||||
# FIXME: Add back when we can match this.
|
||||
#addl $1, 4+4
|
||||
# FIXME: Add back when we can match this.
|
||||
#addl $1, (4+4)
|
||||
# CHECK: addl $1, 4+4(%eax)
|
||||
# CHECK: addl $1, 8
|
||||
addl $1, 4+4
|
||||
# CHECK: addl $1, 8
|
||||
addl $1, (4+4)
|
||||
# CHECK: addl $1, 8(%eax)
|
||||
addl $1, 4+4(%eax)
|
||||
# CHECK: addl $1, 4+4(%eax)
|
||||
# CHECK: addl $1, 8(%eax)
|
||||
addl $1, (4+4)(%eax)
|
||||
# CHECK: addl $1, 8(%eax)
|
||||
addl $1, 8(%eax)
|
||||
# CHECK: addl $1, (%eax)
|
||||
addl $1, (%eax)
|
||||
# CHECK: addl $1, 4+4(,%eax)
|
||||
# CHECK: addl $1, 8(,%eax)
|
||||
addl $1, (4+4)(,%eax)
|
||||
|
||||
# Indirect Memory Operands
|
||||
|
@ -1,6 +1,6 @@
|
||||
# RUN: llvm-mc -triple i386-unknown-unknown %s -I %p | FileCheck %s
|
||||
|
||||
# CHECK: .byte 1+1
|
||||
# CHECK: .byte 2
|
||||
.if 1+2
|
||||
.if 1-1
|
||||
.byte 1
|
||||
|
Loading…
Reference in New Issue
Block a user