From 8de2e2ee7778e7c554a17551fefeab306033002e Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 8 Oct 2021 00:30:37 -0700 Subject: [PATCH] arch: Virtualize printing a PCState. Introduce a virtual output() method which prints the current PCState to the given output stream, and define an overload for << to use that method. This will make it possible to print a PCState without knowing what the actual type is. Change-Id: I663619b168c0b2b90c148b45ae16d77f03934e5b Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52039 Tested-by: kokoro Reviewed-by: Bobby R. Bruce Maintainer: Bobby R. Bruce --- src/arch/generic/pcstate.hh | 70 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/arch/generic/pcstate.hh b/src/arch/generic/pcstate.hh index 284797d22d..d4a317ed4e 100644 --- a/src/arch/generic/pcstate.hh +++ b/src/arch/generic/pcstate.hh @@ -80,6 +80,8 @@ class PCStateBase : public Serializable virtual PCStateBase *clone() const = 0; + virtual void output(std::ostream &os) const = 0; + virtual bool equals(const PCStateBase &other) const { @@ -123,6 +125,13 @@ class PCStateBase : public Serializable } }; +static inline std::ostream & +operator<<(std::ostream & os, const PCStateBase &pc) +{ + pc.output(os); + return os; +} + static inline bool operator==(const PCStateBase &a, const PCStateBase &b) { @@ -189,6 +198,12 @@ class PCStateCommon : public PCStateBase npc(val); } + void + output(std::ostream &os) const override + { + ccprintf(os, "(%#x=>%#x)", this->pc(), this->npc()); + } + bool equals(const PCStateBase &other) const override { @@ -268,14 +283,6 @@ class SimplePCState : public PCStateCommon } }; -template -std::ostream & -operator<<(std::ostream & os, const SimplePCState &pc) -{ - ccprintf(os, "(%#x=>%#x)", pc.pc(), pc.npc()); - return os; -} - // A PC and microcode PC. template class UPCState : public SimplePCState @@ -284,6 +291,13 @@ class UPCState : public SimplePCState typedef SimplePCState Base; public: + void + output(std::ostream &os) const override + { + Base::output(os); + ccprintf(os, ".(%d=>%d)", this->upc(), this->nupc()); + } + PCStateBase * clone() const override { @@ -328,15 +342,6 @@ class UPCState : public SimplePCState } }; -template -std::ostream & -operator<<(std::ostream & os, const UPCState &pc) -{ - ccprintf(os, "(%#x=>%#x).(%d=>%d)", - pc.pc(), pc.npc(), pc.upc(), pc.nupc()); - return os; -} - // A PC with a delay slot. template class DelaySlotPCState : public SimplePCState @@ -347,6 +352,12 @@ class DelaySlotPCState : public SimplePCState Addr _nnpc; public: + void + output(std::ostream &os) const override + { + ccprintf(os, "(%#x=>%#x=>%#x)", this->pc(), this->npc(), nnpc()); + } + PCStateBase * clone() const override { @@ -409,15 +420,6 @@ class DelaySlotPCState : public SimplePCState } }; -template -std::ostream & -operator<<(std::ostream & os, const DelaySlotPCState &pc) -{ - ccprintf(os, "(%#x=>%#x=>%#x)", - pc.pc(), pc.npc(), pc.nnpc()); - return os; -} - // A PC with a delay slot and a microcode PC. template class DelaySlotUPCState : public DelaySlotPCState @@ -426,6 +428,13 @@ class DelaySlotUPCState : public DelaySlotPCState typedef DelaySlotPCState Base; public: + void + output(std::ostream &os) const override + { + Base::output(os); + ccprintf(os, ".(%d=>%d)", this->upc(), this->nupc()); + } + PCStateBase * clone() const override { @@ -469,15 +478,6 @@ class DelaySlotUPCState : public DelaySlotPCState } }; -template -std::ostream & -operator<<(std::ostream & os, const DelaySlotUPCState &pc) -{ - ccprintf(os, "(%#x=>%#x=>%#x).(%d=>%d)", - pc.pc(), pc.npc(), pc.nnpc(), pc.upc(), pc.nupc()); - return os; -} - } } // namespace gem5