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 { ...@@ -1356,11 +1356,6 @@ void InstX8632Xchg::dump(const Cfg *Func) const {
dumpSources(Func); dumpSources(Func);
} }
void OperandX8632::dump(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrDump();
Str << "<OperandX8632>";
}
void OperandX8632Mem::emit(const Cfg *Func) const { void OperandX8632Mem::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit(); Ostream &Str = Func->getContext()->getStrEmit();
Str << TypeX8632Attributes[getType()].WidthString << " "; Str << TypeX8632Attributes[getType()].WidthString << " ";
...@@ -1405,8 +1400,7 @@ void OperandX8632Mem::emit(const Cfg *Func) const { ...@@ -1405,8 +1400,7 @@ void OperandX8632Mem::emit(const Cfg *Func) const {
Str << "]"; Str << "]";
} }
void OperandX8632Mem::dump(const Cfg *Func) const { void OperandX8632Mem::dump(const Cfg *Func, Ostream &Str) const {
Ostream &Str = Func->getContext()->getStrDump();
if (SegmentReg != DefaultSegment) { if (SegmentReg != DefaultSegment) {
assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
Str << InstX8632SegmentRegNames[SegmentReg] << ":"; Str << InstX8632SegmentRegNames[SegmentReg] << ":";
...@@ -1414,7 +1408,10 @@ void OperandX8632Mem::dump(const Cfg *Func) const { ...@@ -1414,7 +1408,10 @@ void OperandX8632Mem::dump(const Cfg *Func) const {
bool Dumped = false; bool Dumped = false;
Str << "["; Str << "[";
if (Base) { if (Base) {
Base->dump(Func); if (Func)
Base->dump(Func);
else
Base->dump(Str);
Dumped = true; Dumped = true;
} }
if (Index) { if (Index) {
...@@ -1422,7 +1419,10 @@ void OperandX8632Mem::dump(const Cfg *Func) const { ...@@ -1422,7 +1419,10 @@ void OperandX8632Mem::dump(const Cfg *Func) const {
Str << "+"; Str << "+";
if (Shift > 0) if (Shift > 0)
Str << (1u << Shift) << "*"; Str << (1u << Shift) << "*";
Index->dump(Func); if (Func)
Index->dump(Func);
else
Index->dump(Str);
Dumped = true; Dumped = true;
} }
// Pretty-print the Offset. // Pretty-print the Offset.
...@@ -1438,11 +1438,11 @@ void OperandX8632Mem::dump(const Cfg *Func) const { ...@@ -1438,11 +1438,11 @@ void OperandX8632Mem::dump(const Cfg *Func) const {
if (!OffsetIsZero) { // Suppress if Offset is known to be 0 if (!OffsetIsZero) { // Suppress if Offset is known to be 0
if (!OffsetIsNegative) // Suppress if Offset is known to be negative if (!OffsetIsNegative) // Suppress if Offset is known to be negative
Str << "+"; Str << "+";
Offset->dump(Func); Offset->dump(Func, Str);
} }
} else { } else {
// There is only the offset. // There is only the offset.
Offset->dump(Func); Offset->dump(Func, Str);
} }
Str << "]"; Str << "]";
} }
...@@ -1468,8 +1468,7 @@ void VariableSplit::emit(const Cfg *Func) const { ...@@ -1468,8 +1468,7 @@ void VariableSplit::emit(const Cfg *Func) const {
Str << "]"; Str << "]";
} }
void VariableSplit::dump(const Cfg *Func) const { void VariableSplit::dump(const Cfg *Func, Ostream &Str) const {
Ostream &Str = Func->getContext()->getStrDump();
switch (Part) { switch (Part) {
case Low: case Low:
Str << "low"; Str << "low";
...@@ -1482,7 +1481,10 @@ void VariableSplit::dump(const Cfg *Func) const { ...@@ -1482,7 +1481,10 @@ void VariableSplit::dump(const Cfg *Func) const {
break; break;
} }
Str << "("; Str << "(";
Var->dump(Func); if (Func)
Var->dump(Func);
else
Var->dump(Str);
Str << ")"; Str << ")";
} }
......
...@@ -35,7 +35,10 @@ public: ...@@ -35,7 +35,10 @@ public:
kSplit kSplit
}; };
virtual void emit(const Cfg *Func) const = 0; 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: protected:
OperandX8632(OperandKindX8632 Kind, Type Ty) OperandX8632(OperandKindX8632 Kind, Type Ty)
...@@ -72,7 +75,8 @@ public: ...@@ -72,7 +75,8 @@ public:
uint16_t getShift() const { return Shift; } uint16_t getShift() const { return Shift; }
SegmentRegisters getSegmentRegister() const { return SegmentReg; } SegmentRegisters getSegmentRegister() const { return SegmentReg; }
virtual void emit(const Cfg *Func) const; 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) { static bool classof(const Operand *Operand) {
return Operand->getKind() == static_cast<OperandKind>(kMem); return Operand->getKind() == static_cast<OperandKind>(kMem);
...@@ -107,7 +111,8 @@ public: ...@@ -107,7 +111,8 @@ public:
return new (Func->allocate<VariableSplit>()) VariableSplit(Func, Var, Part); return new (Func->allocate<VariableSplit>()) VariableSplit(Func, Var, Part);
} }
virtual void emit(const Cfg *Func) const; 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) { static bool classof(const Operand *Operand) {
return Operand->getKind() == static_cast<OperandKind>(kSplit); return Operand->getKind() == static_cast<OperandKind>(kSplit);
......
...@@ -201,8 +201,11 @@ void Variable::emit(const Cfg *Func) const { ...@@ -201,8 +201,11 @@ void Variable::emit(const Cfg *Func) const {
Func->getTarget()->emitVariable(this, Func); Func->getTarget()->emitVariable(this, Func);
} }
void Variable::dump(const Cfg *Func) const { void Variable::dump(const Cfg *Func, Ostream &Str) const {
Ostream &Str = Func->getContext()->getStrDump(); if (Func == NULL) {
Str << "%" << getName();
return;
}
const CfgNode *CurrentNode = Func->getCurrentNode(); const CfgNode *CurrentNode = Func->getCurrentNode();
(void)CurrentNode; // used only in assert() (void)CurrentNode; // used only in assert()
assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode); assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode);
...@@ -241,8 +244,7 @@ void ConstantRelocatable::emit(GlobalContext *Ctx) const { ...@@ -241,8 +244,7 @@ void ConstantRelocatable::emit(GlobalContext *Ctx) const {
} }
} }
void ConstantRelocatable::dump(GlobalContext *Ctx) const { void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const {
Ostream &Str = Ctx->getStrDump();
Str << "@" << Name; Str << "@" << Name;
if (Offset) if (Offset)
Str << "+" << Offset; Str << "+" << Offset;
......
...@@ -51,7 +51,14 @@ public: ...@@ -51,7 +51,14 @@ public:
return Vars[I]; return Vars[I];
} }
virtual void emit(const Cfg *Func) const = 0; 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 // Query whether this object was allocated in isolation, or added to
// some higher-level pool. This determines whether a containing // some higher-level pool. This determines whether a containing
...@@ -82,10 +89,10 @@ private: ...@@ -82,10 +89,10 @@ private:
class Constant : public Operand { class Constant : public Operand {
public: public:
uint32_t getPoolEntryID() const { return PoolEntryID; } uint32_t getPoolEntryID() const { return PoolEntryID; }
using Operand::dump;
virtual void emit(const Cfg *Func) const { emit(Func->getContext()); } 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 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) { static bool classof(const Operand *Operand) {
OperandKind Kind = Operand->getKind(); OperandKind Kind = Operand->getKind();
...@@ -124,10 +131,7 @@ public: ...@@ -124,10 +131,7 @@ public:
// specialization. // specialization.
virtual void emit(GlobalContext *Ctx) const; virtual void emit(GlobalContext *Ctx) const;
using Constant::dump; using Constant::dump;
virtual void dump(GlobalContext *Ctx) const { virtual void dump(const Cfg *, Ostream &Str) const { Str << getValue(); }
Ostream &Str = Ctx->getStrDump();
Str << getValue();
}
static bool classof(const Operand *Operand) { static bool classof(const Operand *Operand) {
return Operand->getKind() == K; return Operand->getKind() == K;
...@@ -146,8 +150,7 @@ typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger; ...@@ -146,8 +150,7 @@ typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger;
typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat;
typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble;
template <> inline void ConstantInteger::dump(GlobalContext *Ctx) const { template <> inline void ConstantInteger::dump(const Cfg *, Ostream &Str) const {
Ostream &Str = Ctx->getStrDump();
if (getType() == IceType_i1) if (getType() == IceType_i1)
Str << (getValue() ? "true" : "false"); Str << (getValue() ? "true" : "false");
else else
...@@ -193,7 +196,7 @@ public: ...@@ -193,7 +196,7 @@ public:
using Constant::emit; using Constant::emit;
using Constant::dump; using Constant::dump;
virtual void emit(GlobalContext *Ctx) const; 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) { static bool classof(const Operand *Operand) {
OperandKind Kind = Operand->getKind(); OperandKind Kind = Operand->getKind();
...@@ -225,14 +228,10 @@ public: ...@@ -225,14 +228,10 @@ public:
} }
using Constant::emit; using Constant::emit;
using Constant::dump;
// The target needs to implement this. // The target needs to implement this.
virtual void emit(GlobalContext *Ctx) const; virtual void emit(GlobalContext *Ctx) const;
virtual void dump(const Cfg *, Ostream &Str) const { Str << "undef"; }
using Constant::dump;
virtual void dump(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrEmit();
Str << "undef";
}
static bool classof(const Operand *Operand) { static bool classof(const Operand *Operand) {
return Operand->getKind() == kConstUndef; return Operand->getKind() == kConstUndef;
...@@ -415,7 +414,8 @@ public: ...@@ -415,7 +414,8 @@ public:
Variable asType(Type Ty); Variable asType(Type Ty);
virtual void emit(const Cfg *Func) const; 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) { static bool classof(const Operand *Operand) {
return Operand->getKind() == kVariable; 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