Commit 2e8bfbb9 by Jim Stichnoth

Subzero: Refactor Operand::dump().

A "standalone" version of dump() is provided, taking just an Ostream argument and not requiring a Cfg or GlobalContext argument. BUG= none R=kschimpf@google.com Review URL: https://codereview.chromium.org/570713006
parent 8fcefc38
......@@ -1356,11 +1356,6 @@ void InstX8632Xchg::dump(const Cfg *Func) const {
dumpSources(Func);
}
void OperandX8632::dump(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrDump();
Str << "<OperandX8632>";
}
void OperandX8632Mem::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit();
Str << TypeX8632Attributes[getType()].WidthString << " ";
......@@ -1405,8 +1400,7 @@ void OperandX8632Mem::emit(const Cfg *Func) const {
Str << "]";
}
void OperandX8632Mem::dump(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrDump();
void OperandX8632Mem::dump(const Cfg *Func, Ostream &Str) const {
if (SegmentReg != DefaultSegment) {
assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
Str << InstX8632SegmentRegNames[SegmentReg] << ":";
......@@ -1414,7 +1408,10 @@ void OperandX8632Mem::dump(const Cfg *Func) const {
bool Dumped = false;
Str << "[";
if (Base) {
if (Func)
Base->dump(Func);
else
Base->dump(Str);
Dumped = true;
}
if (Index) {
......@@ -1422,7 +1419,10 @@ void OperandX8632Mem::dump(const Cfg *Func) const {
Str << "+";
if (Shift > 0)
Str << (1u << Shift) << "*";
if (Func)
Index->dump(Func);
else
Index->dump(Str);
Dumped = true;
}
// Pretty-print the Offset.
......@@ -1438,11 +1438,11 @@ void OperandX8632Mem::dump(const Cfg *Func) const {
if (!OffsetIsZero) { // Suppress if Offset is known to be 0
if (!OffsetIsNegative) // Suppress if Offset is known to be negative
Str << "+";
Offset->dump(Func);
Offset->dump(Func, Str);
}
} else {
// There is only the offset.
Offset->dump(Func);
Offset->dump(Func, Str);
}
Str << "]";
}
......@@ -1468,8 +1468,7 @@ void VariableSplit::emit(const Cfg *Func) const {
Str << "]";
}
void VariableSplit::dump(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrDump();
void VariableSplit::dump(const Cfg *Func, Ostream &Str) const {
switch (Part) {
case Low:
Str << "low";
......@@ -1482,7 +1481,10 @@ void VariableSplit::dump(const Cfg *Func) const {
break;
}
Str << "(";
if (Func)
Var->dump(Func);
else
Var->dump(Str);
Str << ")";
}
......
......@@ -35,7 +35,10 @@ public:
kSplit
};
virtual void emit(const Cfg *Func) const = 0;
void dump(const Cfg *Func) const;
using Operand::dump;
virtual void dump(const Cfg *, Ostream &Str) const {
Str << "<OperandX8632>";
}
protected:
OperandX8632(OperandKindX8632 Kind, Type Ty)
......@@ -72,7 +75,8 @@ public:
uint16_t getShift() const { return Shift; }
SegmentRegisters getSegmentRegister() const { return SegmentReg; }
virtual void emit(const Cfg *Func) const;
virtual void dump(const Cfg *Func) const;
using OperandX8632::dump;
virtual void dump(const Cfg *Func, Ostream &Str) const;
static bool classof(const Operand *Operand) {
return Operand->getKind() == static_cast<OperandKind>(kMem);
......@@ -107,7 +111,8 @@ public:
return new (Func->allocate<VariableSplit>()) VariableSplit(Func, Var, Part);
}
virtual void emit(const Cfg *Func) const;
virtual void dump(const Cfg *Func) const;
using OperandX8632::dump;
virtual void dump(const Cfg *Func, Ostream &Str) const;
static bool classof(const Operand *Operand) {
return Operand->getKind() == static_cast<OperandKind>(kSplit);
......
......@@ -201,8 +201,11 @@ void Variable::emit(const Cfg *Func) const {
Func->getTarget()->emitVariable(this, Func);
}
void Variable::dump(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrDump();
void Variable::dump(const Cfg *Func, Ostream &Str) const {
if (Func == NULL) {
Str << "%" << getName();
return;
}
const CfgNode *CurrentNode = Func->getCurrentNode();
(void)CurrentNode; // used only in assert()
assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode);
......@@ -241,8 +244,7 @@ void ConstantRelocatable::emit(GlobalContext *Ctx) const {
}
}
void ConstantRelocatable::dump(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrDump();
void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const {
Str << "@" << Name;
if (Offset)
Str << "+" << Offset;
......
......@@ -51,7 +51,14 @@ public:
return Vars[I];
}
virtual void emit(const Cfg *Func) const = 0;
virtual void dump(const Cfg *Func) const = 0;
// The dump(Func,Str) implementation must be sure to handle the
// situation where Func==NULL.
virtual void dump(const Cfg *Func, Ostream &Str) const = 0;
void dump(const Cfg *Func) const {
assert(Func);
dump(Func, Func->getContext()->getStrDump());
}
void dump(Ostream &Str) const { dump(NULL, Str); }
// Query whether this object was allocated in isolation, or added to
// some higher-level pool. This determines whether a containing
......@@ -82,10 +89,10 @@ private:
class Constant : public Operand {
public:
uint32_t getPoolEntryID() const { return PoolEntryID; }
using Operand::dump;
virtual void emit(const Cfg *Func) const { emit(Func->getContext()); }
virtual void dump(const Cfg *Func) const { dump(Func->getContext()); }
virtual void emit(GlobalContext *Ctx) const = 0;
virtual void dump(GlobalContext *Ctx) const = 0;
virtual void dump(const Cfg *Func, Ostream &Str) const = 0;
static bool classof(const Operand *Operand) {
OperandKind Kind = Operand->getKind();
......@@ -124,10 +131,7 @@ public:
// specialization.
virtual void emit(GlobalContext *Ctx) const;
using Constant::dump;
virtual void dump(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrDump();
Str << getValue();
}
virtual void dump(const Cfg *, Ostream &Str) const { Str << getValue(); }
static bool classof(const Operand *Operand) {
return Operand->getKind() == K;
......@@ -146,8 +150,7 @@ typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger;
typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat;
typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble;
template <> inline void ConstantInteger::dump(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrDump();
template <> inline void ConstantInteger::dump(const Cfg *, Ostream &Str) const {
if (getType() == IceType_i1)
Str << (getValue() ? "true" : "false");
else
......@@ -193,7 +196,7 @@ public:
using Constant::emit;
using Constant::dump;
virtual void emit(GlobalContext *Ctx) const;
virtual void dump(GlobalContext *Ctx) const;
virtual void dump(const Cfg *Func, Ostream &Str) const;
static bool classof(const Operand *Operand) {
OperandKind Kind = Operand->getKind();
......@@ -225,14 +228,10 @@ public:
}
using Constant::emit;
using Constant::dump;
// The target needs to implement this.
virtual void emit(GlobalContext *Ctx) const;
using Constant::dump;
virtual void dump(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrEmit();
Str << "undef";
}
virtual void dump(const Cfg *, Ostream &Str) const { Str << "undef"; }
static bool classof(const Operand *Operand) {
return Operand->getKind() == kConstUndef;
......@@ -415,7 +414,8 @@ public:
Variable asType(Type Ty);
virtual void emit(const Cfg *Func) const;
virtual void dump(const Cfg *Func) const;
using Operand::dump;
virtual void dump(const Cfg *Func, Ostream &Str) const;
static bool classof(const Operand *Operand) {
return Operand->getKind() == kVariable;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment