arch: Add some helpers to make it easier to cast PCState.
These helpers will make it easier to cast a PCStatePtr into an ISA specific class with less syntactic fluff. They are currently implemented with a static_cast for performance reasons, but could be implemented with a dynamic_cast and an assert for extra debugging if you were willing to pay the performance overhead. In the future this might be switched/enabled as an extra debugging mode, like how locking can have extra checks enabled in the Linux kernel. Change-Id: Ibc2443c6b991ebc2e5d0240a88436849cb6de2b9 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52033 Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
This commit is contained in:
@@ -54,6 +54,20 @@ class PCStateBase : public Serializable
|
||||
{
|
||||
public:
|
||||
virtual ~PCStateBase() = default;
|
||||
|
||||
template<class Target>
|
||||
Target &
|
||||
as()
|
||||
{
|
||||
return static_cast<Target &>(*this);
|
||||
}
|
||||
|
||||
template<class Target>
|
||||
const Target &
|
||||
as() const
|
||||
{
|
||||
return static_cast<const Target &>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
namespace GenericISA
|
||||
|
||||
Reference in New Issue
Block a user