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 /lib/MC | |
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
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 12 |
1 files changed, 10 insertions, 2 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) { |