diff options
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 26 | ||||
-rw-r--r-- | lib/MC/MCInst.cpp | 7 | ||||
-rw-r--r-- | lib/MC/MCMachOStreamer.cpp | 29 |
3 files changed, 35 insertions, 27 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index e5899fc899..d0a2ebbc30 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -10,13 +10,14 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/ADT/SmallString.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" -#include "llvm/MC/MCAsmInfo.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Format.h" @@ -271,18 +272,6 @@ void MCAsmStreamer::EmitValueToOffset(const MCValue &Offset, OS << ".org " << Offset << ", " << (unsigned) Value << '\n'; } -static raw_ostream &operator<<(raw_ostream &OS, const MCOperand &Op) { - if (Op.isReg()) - return OS << "reg:" << Op.getReg(); - if (Op.isImm()) - return OS << "imm:" << Op.getImm(); - if (Op.isMBBLabel()) - return OS << "mbblabel:(" - << Op.getMBBLabelFunction() << ", " << Op.getMBBLabelBlock(); - assert(Op.isMCValue() && "Invalid operand!"); - return OS << "val:" << Op.getMCValue(); -} - void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { assert(CurSection && "Cannot emit contents before setting section!"); @@ -312,15 +301,8 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { // Otherwise fall back to a structural printing for now. Eventually we should // always have access to the target specific printer. - OS << "MCInst(" - << "opcode=" << Inst.getOpcode() << ", " - << "operands=["; - for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) { - if (i) - OS << ", "; - OS << Inst.getOperand(i); - } - OS << "])\n"; + Inst.print(OS); + OS << '\n'; } void MCAsmStreamer::Finish() { diff --git a/lib/MC/MCInst.cpp b/lib/MC/MCInst.cpp index 469dc7975e..ec061463b7 100644 --- a/lib/MC/MCInst.cpp +++ b/lib/MC/MCInst.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCExpr.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -23,9 +24,9 @@ void MCOperand::print(raw_ostream &OS) const { else if (isMBBLabel()) OS << "MBB:(" << getMBBLabelFunction() << "," << getMBBLabelBlock() << ")"; - else if (isMCValue()) { - OS << "Value:("; - getMCValue().print(OS); + else if (isExpr()) { + OS << "Expr:("; + getExpr()->print(OS); OS << ")"; } else OS << "UNDEFINED"; diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 5a7b01b476..7a94e98dd2 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -12,6 +12,7 @@ #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCCodeEmitter.h" +#include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSymbol.h" @@ -95,6 +96,30 @@ public: return Value; } + const MCExpr *AddValueSymbols(const MCExpr *Value) { + switch (Value->getKind()) { + case MCExpr::Constant: + break; + + case MCExpr::Binary: { + const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value); + AddValueSymbols(BE->getLHS()); + AddValueSymbols(BE->getRHS()); + break; + } + + case MCExpr::SymbolRef: + getSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol()); + break; + + case MCExpr::Unary: + AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr()); + break; + } + + return Value; + } + /// @name MCStreamer Interface /// @{ @@ -330,8 +355,8 @@ void MCMachOStreamer::EmitValueToOffset(const MCValue &Offset, void MCMachOStreamer::EmitInstruction(const MCInst &Inst) { // Scan for values. for (unsigned i = 0; i != Inst.getNumOperands(); ++i) - if (Inst.getOperand(i).isMCValue()) - AddValueSymbols(Inst.getOperand(i).getMCValue()); + if (Inst.getOperand(i).isExpr()) + AddValueSymbols(Inst.getOperand(i).getExpr()); if (!Emitter) llvm_unreachable("no code emitter available!"); |