cpu: Add a mechanism which lets a reg class name its members.
This can be used to get the "pretty" name for a given register index within a register class, and can be specialized per ISA, or even per ISA object. Jira Issue: https://gem5.atlassian.net/browse/GEM5-1060 Change-Id: I7b290db73c7d04e0f61293ae82fc92ca5b4fe692 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48706 Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -39,10 +39,17 @@
|
||||
*/
|
||||
|
||||
#include "cpu/reg_class.hh"
|
||||
#include "base/cprintf.hh"
|
||||
|
||||
namespace gem5
|
||||
{
|
||||
|
||||
std::string
|
||||
DefaultRegClassOps::regName(const RegId &id) const
|
||||
{
|
||||
return csprintf("r%d", id.index());
|
||||
}
|
||||
|
||||
const char *RegId::regClassStrings[] = {
|
||||
"IntRegClass",
|
||||
"FloatRegClass",
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "arch/vecregs.hh"
|
||||
#include "base/types.hh"
|
||||
@@ -65,19 +66,43 @@ enum RegClass
|
||||
MiscRegClass ///< Control (misc) register
|
||||
};
|
||||
|
||||
class RegId;
|
||||
|
||||
class RegClassOps
|
||||
{
|
||||
public:
|
||||
virtual std::string regName(const RegId &id) const = 0;
|
||||
};
|
||||
|
||||
class DefaultRegClassOps : public RegClassOps
|
||||
{
|
||||
public:
|
||||
std::string regName(const RegId &id) const override;
|
||||
};
|
||||
|
||||
class RegClassInfo
|
||||
{
|
||||
private:
|
||||
size_t _size;
|
||||
const RegIndex _zeroReg;
|
||||
|
||||
static inline DefaultRegClassOps defaultOps;
|
||||
RegClassOps *_ops = &defaultOps;
|
||||
|
||||
public:
|
||||
RegClassInfo(size_t new_size, RegIndex new_zero = -1) :
|
||||
RegClassInfo(size_t new_size, RegIndex new_zero=-1) :
|
||||
_size(new_size), _zeroReg(new_zero)
|
||||
{}
|
||||
RegClassInfo(size_t new_size, RegClassOps &new_ops, RegIndex new_zero=-1) :
|
||||
RegClassInfo(new_size, new_zero)
|
||||
{
|
||||
_ops = &new_ops;
|
||||
}
|
||||
|
||||
size_t size() const { return _size; }
|
||||
RegIndex zeroReg() const { return _zeroReg; }
|
||||
|
||||
std::string regName(const RegId &id) const { return _ops->regName(id); }
|
||||
};
|
||||
|
||||
/** Register ID: describe an architectural register with its class and index.
|
||||
|
||||
Reference in New Issue
Block a user