diff options
Diffstat (limited to 'sim')
-rw-r--r-- | sim/faults.cc | 9 | ||||
-rw-r--r-- | sim/faults.hh | 59 |
2 files changed, 44 insertions, 24 deletions
diff --git a/sim/faults.cc b/sim/faults.cc index 58a631263..17efaf1c4 100644 --- a/sim/faults.cc +++ b/sim/faults.cc @@ -28,9 +28,8 @@ #include "sim/faults.hh" -NoFaultType * const NoFault = new NoFaultType("none"); -MachineCheckFaultType * const MachineCheckFault = - new MachineCheckFaultType("mchk"); -AlignmentFaultType * const AlignmentFault = - new AlignmentFaultType("unalign"); +FaultName MachineCheckFault::_name = "mchk"; +FaultStat MachineCheckFault::_stat; +FaultName AlignmentFault::_name = "unalign"; +FaultStat AlignmentFault::_stat; diff --git a/sim/faults.hh b/sim/faults.hh index dbec399af..ea2e21a7d 100644 --- a/sim/faults.hh +++ b/sim/faults.hh @@ -29,34 +29,55 @@ #ifndef __FAULTS_HH__ #define __FAULTS_HH__ +#include "base/refcnt.hh" +#include "sim/stats.hh" + class FaultBase; -typedef FaultBase * Fault; +typedef RefCountingPtr<FaultBase> Fault; + +typedef const char * FaultName; +typedef Stats::Scalar<> FaultStat; + +// Each class has it's name statically define in _name, +// and has a virtual function to access it's name. +// The function is necessary because otherwise, all objects +// which are being accessed cast as a FaultBase * (namely +// all faults returned using the Fault type) will use the +// generic FaultBase name. -class FaultBase +class FaultBase : public RefCounted { -public: - FaultBase(char * newName, int newId = 0) : name(newName), id(newId) {;} - const char * name; - int id; + public: + virtual FaultName name() + { + return "none"; + } + virtual FaultStat & stat() = 0; + template<typename T> + bool isA() {return dynamic_cast<T *>(this);} }; -extern class NoFaultType : public FaultBase -{ -public: - NoFaultType(char * newName) : FaultBase(newName) {;} -} * const NoFault; +static FaultBase * const NoFault __attribute__ ((unused)) = 0; -extern class MachineCheckFaultType : public FaultBase +class MachineCheckFault : public FaultBase { -public: - MachineCheckFaultType(char * newName) : FaultBase(newName) {;} -} * const MachineCheckFault; + private: + static FaultName _name; + static FaultStat _stat; + public: + FaultName name() {return _name;} + FaultStat & stat() {return _stat;} +}; -extern class AlignmentFaultType : public FaultBase +class AlignmentFault : public FaultBase { -public: - AlignmentFaultType(char * newName) : FaultBase(newName) {;} -} * const AlignmentFault; + private: + static FaultName _name; + static FaultStat _stat; + public: + FaultName name() {return _name;} + FaultStat & stat() {return _stat;} +}; #endif // __FAULTS_HH__ |