diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-12-17 01:07:20 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-12-17 01:07:20 +0000 |
commit | f2ed62d6bfe0693dbcb114b619a08fa9b397a422 (patch) | |
tree | a075e86cbfa4f05956a6c06127519addf0a75c5e /lib/MC/MCExpr.cpp | |
parent | dfe125cc9cfd524575973daa297c9aad10470390 (diff) | |
download | llvm-f2ed62d6bfe0693dbcb114b619a08fa9b397a422.tar.gz llvm-f2ed62d6bfe0693dbcb114b619a08fa9b397a422.tar.bz2 llvm-f2ed62d6bfe0693dbcb114b619a08fa9b397a422.tar.xz |
MC/Expr: Simplify (and add a FIXME).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122008 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCExpr.cpp')
-rw-r--r-- | lib/MC/MCExpr.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index a3ef71f630..5d2c707068 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -311,13 +311,21 @@ static bool EvaluateSymbolicAdd(const MCAssembler *Asm, const MCValue &LHS,const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst, MCValue &Res) { - // We can't add or subtract two symbols. - if ((LHS.getSymA() && RHS_A) || - (LHS.getSymB() && RHS_B)) + // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy + // about dealing with modifiers. This will ultimately bite us, one day. + const MCSymbolRefExpr *LHS_A = LHS.getSymA(); + const MCSymbolRefExpr *LHS_B = LHS.getSymB(); + int64_t LHS_Cst = LHS.getConstant(); + + // Fold the result constant immediately. + int64_t Result_Cst = LHS_Cst + RHS_Cst; + + // We can't represent the addition or subtraction of two symbols. + if ((LHS_A && RHS_A) || (LHS_B && RHS_B)) return false; - const MCSymbolRefExpr *A = LHS.getSymA() ? LHS.getSymA() : RHS_A; - const MCSymbolRefExpr *B = LHS.getSymB() ? LHS.getSymB() : RHS_B; + const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A; + const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B; if (B) { // If we have a negated symbol, then we must have also have a non-negated // symbol in order to encode the expression. We can do this check later to @@ -343,8 +351,7 @@ static bool EvaluateSymbolicAdd(const MCAssembler *Asm, if (AD.getFragment() == BD.getFragment()) { Res = MCValue::get(+ AD.getOffset() - BD.getOffset() - + LHS.getConstant() - + RHS_Cst); + + Result_Cst); return true; } @@ -353,8 +360,7 @@ static bool EvaluateSymbolicAdd(const MCAssembler *Asm, const MCSectionData &SecB = *BD.getFragment()->getParent(); int64_t Val = + Layout->getSymbolOffset(&AD) - Layout->getSymbolOffset(&BD) - + LHS.getConstant() - + RHS_Cst; + + Result_Cst; if (&SecA != &SecB) { if (!Addrs) return false; @@ -367,7 +373,7 @@ static bool EvaluateSymbolicAdd(const MCAssembler *Asm, } } - Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst); + Res = MCValue::get(A, B, Result_Cst); return true; } |