remove the MAI argument to MCExpr::print and switch overthing to use << when printing them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93699 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-01-18 00:37:40 +00:00
parent 950558aa23
commit 8cb9a3b13f
9 changed files with 28 additions and 39 deletions

View File

@@ -51,7 +51,7 @@ public:
/// @name Utility Methods /// @name Utility Methods
/// @{ /// @{
void print(raw_ostream &OS, const MCAsmInfo *MAI) const; void print(raw_ostream &OS) const;
void dump() const; void dump() const;
/// @} /// @}
@@ -75,6 +75,11 @@ public:
static bool classof(const MCExpr *) { return true; } static bool classof(const MCExpr *) { return true; }
}; };
inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
E.print(OS);
return OS;
}
//// MCConstantExpr - Represent a constant integer expression. //// MCConstantExpr - Represent a constant integer expression.
class MCConstantExpr : public MCExpr { class MCConstantExpr : public MCExpr {

View File

@@ -194,8 +194,7 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) {
PersonalityRef = CreateLabelDiff(PersonalityRef, "personalityref_addr", PersonalityRef = CreateLabelDiff(PersonalityRef, "personalityref_addr",
Index); Index);
O << MAI->getData32bitsDirective(); O << MAI->getData32bitsDirective() << *PersonalityRef;
PersonalityRef->print(O, MAI);
Asm->EOL("Personality"); Asm->EOL("Personality");
Asm->EmitInt8(LSDAEncoding); Asm->EmitInt8(LSDAEncoding);

View File

@@ -118,9 +118,7 @@ void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
assert((Symbol->isUndefined() || Symbol->isAbsolute()) && assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
"Cannot define a symbol twice!"); "Cannot define a symbol twice!");
OS << *Symbol << " = "; OS << *Symbol << " = " << *Value << '\n';
Value->print(OS, &MAI);
OS << '\n';
// FIXME: Lift context changes into super class. // FIXME: Lift context changes into super class.
// FIXME: Set associated section. // FIXME: Set associated section.
@@ -194,9 +192,7 @@ void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size) {
case 8: OS << ".quad"; break; case 8: OS << ".quad"; break;
} }
OS << ' '; OS << ' ' << *truncateToSize(Value, Size) << '\n';
truncateToSize(Value, Size)->print(OS, &MAI);
OS << '\n';
} }
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
@@ -250,9 +246,7 @@ void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset, void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
unsigned char Value) { unsigned char Value) {
// FIXME: Verify that Offset is associated with the current section. // FIXME: Verify that Offset is associated with the current section.
OS << ".org "; OS << ".org " << *Offset << ", " << (unsigned) Value << '\n';
Offset->print(OS, &MAI);
OS << ", " << (unsigned) Value << '\n';
} }
void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {

View File

@@ -15,7 +15,7 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const { void MCExpr::print(raw_ostream &OS) const {
switch (getKind()) { switch (getKind()) {
case MCExpr::Constant: case MCExpr::Constant:
OS << cast<MCConstantExpr>(*this).getValue(); OS << cast<MCConstantExpr>(*this).getValue();
@@ -42,7 +42,7 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
case MCUnaryExpr::Not: OS << '~'; break; case MCUnaryExpr::Not: OS << '~'; break;
case MCUnaryExpr::Plus: OS << '+'; break; case MCUnaryExpr::Plus: OS << '+'; break;
} }
UE.getSubExpr()->print(OS, MAI); OS << *UE.getSubExpr();
return; return;
} }
@@ -51,11 +51,9 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
// Only print parens around the LHS if it is non-trivial. // Only print parens around the LHS if it is non-trivial.
if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) { if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) {
BE.getLHS()->print(OS, MAI); OS << *BE.getLHS();
} else { } else {
OS << '('; OS << '(' << *BE.getLHS() << ')';
BE.getLHS()->print(OS, MAI);
OS << ')';
} }
switch (BE.getOpcode()) { switch (BE.getOpcode()) {
@@ -92,11 +90,9 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
// Only print parens around the LHS if it is non-trivial. // Only print parens around the LHS if it is non-trivial.
if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) { if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {
BE.getRHS()->print(OS, MAI); OS << *BE.getRHS();
} else { } else {
OS << '('; OS << '(' << *BE.getRHS() << ')';
BE.getRHS()->print(OS, MAI);
OS << ')';
} }
return; return;
} }
@@ -106,7 +102,7 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
} }
void MCExpr::dump() const { void MCExpr::dump() const {
print(dbgs(), 0); print(dbgs());
dbgs() << '\n'; dbgs() << '\n';
} }

View File

@@ -23,9 +23,7 @@ void MCOperand::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
else if (isImm()) else if (isImm())
OS << "Imm:" << getImm(); OS << "Imm:" << getImm();
else if (isExpr()) { else if (isExpr()) {
OS << "Expr:("; OS << "Expr:(" << *getExpr() << ")";
getExpr()->print(OS, MAI);
OS << ")";
} else } else
OS << "UNDEFINED"; OS << "UNDEFINED";
OS << ">"; OS << ">";

View File

@@ -62,7 +62,7 @@ void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
} else { } else {
assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported"); assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
assert(Op.isExpr() && "unknown operand kind in printOperand"); assert(Op.isExpr() && "unknown operand kind in printOperand");
Op.getExpr()->print(O, &MAI); O << *Op.getExpr();
} }
} }

View File

@@ -39,7 +39,7 @@ void MSP430InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo) {
O << Op.getImm(); O << Op.getImm();
else { else {
assert(Op.isExpr() && "unknown pcrel immediate operand"); assert(Op.isExpr() && "unknown pcrel immediate operand");
Op.getExpr()->print(O, &MAI); O << *Op.getExpr();
} }
} }
@@ -53,8 +53,7 @@ void MSP430InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
O << '#' << Op.getImm(); O << '#' << Op.getImm();
} else { } else {
assert(Op.isExpr() && "unknown operand kind in printOperand"); assert(Op.isExpr() && "unknown operand kind in printOperand");
O << '#'; O << '#' << *Op.getExpr();
Op.getExpr()->print(O, &MAI);
} }
} }
@@ -65,8 +64,7 @@ void MSP430InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
// Print displacement first // Print displacement first
if (Disp.isExpr()) { if (Disp.isExpr()) {
O << '&'; O << '&' << *Disp.getExpr();
Disp.getExpr()->print(O, &MAI);
} else { } else {
assert(Disp.isImm() && "Expected immediate in displacement field"); assert(Disp.isImm() && "Expected immediate in displacement field");
if (!Base.getReg()) if (!Base.getReg())

View File

@@ -55,7 +55,7 @@ void X86ATTInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
O << (int)Op.getImm(); O << (int)Op.getImm();
else { else {
assert(Op.isExpr() && "unknown pcrel immediate operand"); assert(Op.isExpr() && "unknown pcrel immediate operand");
Op.getExpr()->print(O, &MAI); O << *Op.getExpr();
} }
} }
@@ -68,8 +68,7 @@ void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo) {
O << '$' << Op.getImm(); O << '$' << Op.getImm();
} else { } else {
assert(Op.isExpr() && "unknown operand kind in printOperand"); assert(Op.isExpr() && "unknown operand kind in printOperand");
O << '$'; O << '$' << *Op.getExpr();
Op.getExpr()->print(O, &MAI);
} }
} }
@@ -84,7 +83,7 @@ void X86ATTInstPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
O << DispVal; O << DispVal;
} else { } else {
assert(DispSpec.isExpr() && "non-immediate displacement for LEA?"); assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
DispSpec.getExpr()->print(O, &MAI); O << *DispSpec.getExpr();
} }
if (IndexReg.getReg() || BaseReg.getReg()) { if (IndexReg.getReg() || BaseReg.getReg()) {

View File

@@ -52,7 +52,7 @@ void X86IntelInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
O << Op.getImm(); O << Op.getImm();
else { else {
assert(Op.isExpr() && "unknown pcrel immediate operand"); assert(Op.isExpr() && "unknown pcrel immediate operand");
Op.getExpr()->print(O, &MAI); O << *Op.getExpr();
} }
} }
@@ -72,7 +72,7 @@ void X86IntelInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
O << Op.getImm(); O << Op.getImm();
} else { } else {
assert(Op.isExpr() && "unknown operand kind in printOperand"); assert(Op.isExpr() && "unknown operand kind in printOperand");
Op.getExpr()->print(O, &MAI); O << *Op.getExpr();
} }
} }
@@ -102,7 +102,7 @@ void X86IntelInstPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
if (!DispSpec.isImm()) { if (!DispSpec.isImm()) {
if (NeedPlus) O << " + "; if (NeedPlus) O << " + ";
assert(DispSpec.isExpr() && "non-immediate displacement for LEA?"); assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
DispSpec.getExpr()->print(O, &MAI); O << *DispSpec.getExpr();
} else { } else {
int64_t DispVal = DispSpec.getImm(); int64_t DispVal = DispSpec.getImm();
if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) { if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {