llvm-mc: Add MCExpr::{dump,print}.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80570 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-08-31 08:07:33 +00:00
parent 9643ac5514
commit 87392fde1f
2 changed files with 75 additions and 0 deletions

View File

@ -17,6 +17,7 @@ namespace llvm {
class MCContext;
class MCSymbol;
class MCValue;
class raw_ostream;
/// MCExpr - Base class for the full range of assembler expressions which are
/// needed for parsing.
@ -44,6 +45,13 @@ public:
ExprKind getKind() const { return Kind; }
/// @}
/// @name Utility Methods
/// @{
void print(raw_ostream &OS) const;
void dump() const;
/// @}
/// @name Expression Evaluation
/// @{

View File

@ -11,8 +11,75 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
void MCExpr::print(raw_ostream &OS) const {
switch (getKind()) {
case MCExpr::Constant:
OS << cast<MCConstantExpr>(*this).getValue();
return;
case MCExpr::SymbolRef:
cast<MCSymbolRefExpr>(*this).getSymbol().print(OS);
return;
case MCExpr::Unary: {
const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this);
switch (UE.getOpcode()) {
default: assert(0 && "Invalid opcode!");
case MCUnaryExpr::LNot: OS << '!'; break;
case MCUnaryExpr::Minus: OS << '-'; break;
case MCUnaryExpr::Not: OS << '~'; break;
case MCUnaryExpr::Plus: OS << '+'; break;
}
UE.getSubExpr()->print(OS);
return;
}
case MCExpr::Binary: {
const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this);
OS << '(';
BE.getLHS()->print(OS);
OS << ' ';
switch (BE.getOpcode()) {
default: assert(0 && "Invalid opcode!");
case MCBinaryExpr::Add: OS << '+'; break;
case MCBinaryExpr::And: OS << '&'; break;
case MCBinaryExpr::Div: OS << '/'; break;
case MCBinaryExpr::EQ: OS << "=="; break;
case MCBinaryExpr::GT: OS << '>'; break;
case MCBinaryExpr::GTE: OS << ">="; break;
case MCBinaryExpr::LAnd: OS << "&&"; break;
case MCBinaryExpr::LOr: OS << "||"; break;
case MCBinaryExpr::LT: OS << '<'; break;
case MCBinaryExpr::LTE: OS << "<="; break;
case MCBinaryExpr::Mod: OS << '%'; break;
case MCBinaryExpr::Mul: OS << '*'; break;
case MCBinaryExpr::NE: OS << "!="; break;
case MCBinaryExpr::Or: OS << '|'; break;
case MCBinaryExpr::Shl: OS << "<<"; break;
case MCBinaryExpr::Shr: OS << ">>"; break;
case MCBinaryExpr::Sub: OS << '-'; break;
case MCBinaryExpr::Xor: OS << '^'; break;
}
OS << ' ';
BE.getRHS()->print(OS);
OS << ')';
return;
}
}
assert(0 && "Invalid expression kind!");
}
void MCExpr::dump() const {
print(errs());
errs() << '\n';
}
/* *** */
const MCBinaryExpr * MCBinaryExpr::Create(Opcode Opc,
const MCExpr *LHS,
const MCExpr *RHS,