The Sparta Modeling Framework
Loading...
Searching...
No Matches
TranslationIF.hpp
1
8#pragma once
9
10#include "sparta/memory/AddressTypes.hpp"
13
14namespace sparta
15{
16 namespace memory
17 {
31 {
32 public:
33
37
38 TranslationIF& operator=(const TranslationIF&) = delete;
39 TranslationIF(const TranslationIF&) = delete;
40
46 TranslationIF(const std::string& input_type,
47 const std::string& output_type) :
48 input_type_(input_type),
49 output_type_(output_type)
50 { }
51
58 TranslationIF("virtual", "physical")
59 { }
60
64 virtual ~TranslationIF() {}
65
68
72
76 const std::string& getInputType() const { return input_type_; }
77
81 const std::string& getOutputType() const { return output_type_; }
82
85
89
98 bool tryTranslate(const addr_t& addr, Translation* trans=nullptr) const {
99 Translation local_trans;
100 Translation& t(trans!=nullptr ? (*trans) : local_trans);
101 if(!tryTranslate_(addr, t)){
102 // Determine failure cause.
103 // Check if failure is caused by out-of-range or block-spanning
104 // If not, why???
105 throw MemoryTranslationError(addr, "Cannot translate");
106 }
107 return true;
108 }
109
118 addr_t translate(const addr_t& addr, Translation* trans=nullptr) const {
119 Translation local_trans;
120 Translation& t(trans!=nullptr ? (*trans) : local_trans);
121
122 if(!tryTranslate_(addr, t)){
124 // Check if failure is caused by out-of-range or block-spanning
125 // If not, why???
126 throw MemoryTranslationError(addr, "Cannot translate");
127 }
128 return t.getOutputAddress();
129 }
130
133
134 private:
135
143 virtual bool tryTranslate_(const addr_t& addr, Translation& trans) const noexcept {
144 trans = Translation(addr, addr);
145 return true;
146 }
147
148 const std::string input_type_;
149 const std::string output_type_;
150
151 };
152 } // namespace memory
153} // namespace sparta
154
File that contains some exception types related to memory interfaces.
File that defines Translation classes and typedefs for addressing.
Indicates that there was an issue translating an address in the SPARTA framework.
Blocking translation interface with 1:1 translation unless subclassed.
TranslationIF()
Default Constructor.
addr_t translate(const addr_t &addr, Translation *trans=nullptr) const
Perform a translation from input-type to output-type.
const std::string & getInputType() const
gets the name of the input address type (e.g. virtual)
bool tryTranslate(const addr_t &addr, Translation *trans=nullptr) const
Perform a translation from input-type to output-type.
virtual ~TranslationIF()
Virtual Destructor.
const std::string & getOutputType() const
gets the name of the output address type (e.g. physical)
TranslationIF(const std::string &input_type, const std::string &output_type)
Constructor.
An older class used to help in encapsulate read/virtual addresses.
addr_t getOutputAddress() const
Returns output address of this translation.
uint64_t addr_t
Type for generic address representation in generic interfaces, errors and printouts within SPARTA.
Macros for handling exponential backoff.