diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-02-13 01:28:07 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-02-13 01:28:07 +0000 |
commit | e9a60eb4987a096df10de0442af1e2929bc32547 (patch) | |
tree | e4bbfd391c97a7ec2fd1b972bd814880a6b1f73e | |
parent | 08b85f371e036beb8b07ad58c4f53920be24ad2a (diff) | |
download | external_llvm-e9a60eb4987a096df10de0442af1e2929bc32547.zip external_llvm-e9a60eb4987a096df10de0442af1e2929bc32547.tar.gz external_llvm-e9a60eb4987a096df10de0442af1e2929bc32547.tar.bz2 |
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
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 12 | ||||
-rw-r--r-- | test/MC/AsmParser/X86/x86_32-new-encoder.s | 6 | ||||
-rw-r--r-- | test/MC/AsmParser/X86/x86_operands.s | 18 | ||||
-rw-r--r-- | test/MC/AsmParser/conditional_asm.s | 2 |
4 files changed, 26 insertions, 12 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index d5bc396..51ad5d1 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -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) { diff --git a/test/MC/AsmParser/X86/x86_32-new-encoder.s b/test/MC/AsmParser/X86/x86_32-new-encoder.s index a440a25..efac73f 100644 --- a/test/MC/AsmParser/X86/x86_32-new-encoder.s +++ b/test/MC/AsmParser/X86/x86_32-new-encoder.s @@ -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) + diff --git a/test/MC/AsmParser/X86/x86_operands.s b/test/MC/AsmParser/X86/x86_operands.s index 8e6543e..edddd1f 100644 --- a/test/MC/AsmParser/X86/x86_operands.s +++ b/test/MC/AsmParser/X86/x86_operands.s @@ -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 diff --git a/test/MC/AsmParser/conditional_asm.s b/test/MC/AsmParser/conditional_asm.s index b8a514f..f619ef9 100644 --- a/test/MC/AsmParser/conditional_asm.s +++ b/test/MC/AsmParser/conditional_asm.s @@ -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 |