diff options
author | Chris Lattner <sabre@nondot.org> | 2009-09-08 06:34:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-09-08 06:34:07 +0000 |
commit | be73e8c4e7ca3dcec4aadef237d8e1779e0836fc (patch) | |
tree | 449faf02e92bfdbd6ae6150924aacd9575c7544a /lib/MC/MCExpr.cpp | |
parent | 8b4ada248a0fa7f6b464a049e7351497bc883b91 (diff) | |
download | external_llvm-be73e8c4e7ca3dcec4aadef237d8e1779e0836fc.zip external_llvm-be73e8c4e7ca3dcec4aadef237d8e1779e0836fc.tar.gz external_llvm-be73e8c4e7ca3dcec4aadef237d8e1779e0836fc.tar.bz2 |
make formatting of expressions more closely match the existing asmprinter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81202 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCExpr.cpp')
-rw-r--r-- | lib/MC/MCExpr.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 8842117..2bb674f 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -39,9 +39,16 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const { case MCExpr::Binary: { const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this); - OS << '('; - BE.getLHS()->print(OS, MAI); - OS << ' '; + + // Only print parens around the LHS if it is non-trivial. + if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) { + BE.getLHS()->print(OS, MAI); + } else { + OS << '('; + BE.getLHS()->print(OS, MAI); + OS << ')'; + } + switch (BE.getOpcode()) { default: assert(0 && "Invalid opcode!"); case MCBinaryExpr::Add: OS << '+'; break; @@ -63,9 +70,15 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const { case MCBinaryExpr::Sub: OS << '-'; break; case MCBinaryExpr::Xor: OS << '^'; break; } - OS << ' '; - BE.getRHS()->print(OS, MAI); - OS << ')'; + + // Only print parens around the LHS if it is non-trivial. + if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) { + BE.getRHS()->print(OS, MAI); + } else { + OS << '('; + BE.getRHS()->print(OS, MAI); + OS << ')'; + } return; } } |