The Sparta Modeling Framework
Loading...
Searching...
No Matches
ArchDataSegment.hpp
1// <ArchDataSegment> -*- C++ -*-
2
3#pragma once
4
5#include <iostream>
6#include <math.h>
7
10#include "sparta/utils/Utils.hpp"
11
12
13namespace sparta
14{
15 class ArchData;
16
20 {
21 public:
22
23 typedef uint64_t offset_type; //<! Represents offset (address) into ArchData
24 typedef uint32_t ident_type; //<! DataView identifiers (distinguishes items in the same ArchData)
25
27 static const ident_type INVALID_ID = ~(ident_type)0;
28
29 ArchDataSegment(const ArchDataSegment&) = delete;
30 ArchDataSegment(const ArchDataSegment&&) = delete;
31 ArchDataSegment& operator=(const ArchDataSegment&) = delete;
32
45 offset_type size,
46 ident_type id,
47 ident_type subset_of=INVALID_ID,
48 offset_type subset_offset=0) :
49 offset_(0), is_placed_(false), size_(size),
50 adata_(data),
51 ident_(id),
52 subset_of_(subset_of),
53 subset_offset_(subset_offset)
54
55 {
56 // No reason not to allow this, it just can't have subsegments
57 //if(id == INVALID_ID){
58 // throw SpartaException("Cannot construct ArchDataSegment with identifier=INVALID_ID");
59 //}
60
61 if(!isPowerOf2(size)){
62 throw SpartaException("size must be a power of 2, is ")
63 << size;
64 }
65
66 sparta_assert(getOffset() == 0); // Ensure initialized to 0 because getOffset expects this
67 }
68
72 virtual ~ArchDataSegment() {};
73
81 void place(offset_type offset) {
82 if(is_placed_){
83 SpartaException ex("ArchDataSegment ");
84 ex << ident_ << " was already placed. Cannot place again";
85 throw ex;
86 }
87 offset_ = offset;
88 is_placed_ = true;
89
90 place_(offset);
91 }
92
98 void writeInitial() {
99 sparta_assert(is_placed_, "Should not be invoking writeInitial when is_placed_ is false");
101 }
102
103 // Layout State
104
109 bool isPlaced() const { return is_placed_; }
110
115 offset_type getOffset() const { return offset_; }
116
117
118 // Const Attributes
119
124 offset_type getLayoutSize() const { return size_; }
125
130 ident_type getLayoutID() const { return ident_; }
131
137 ident_type getSubsetOf() const { return subset_of_; }
138
145 offset_type getSubsetOffset() const { return subset_offset_; }
146
150 ArchData* getArchData() { return adata_; }
151
155 const ArchData* getArchData() const { return adata_; }
156
157 protected:
158
172 virtual void place_(offset_type offset) {
173 (void) offset;
174 }
175
184 virtual void writeInitial_() {
185 }
186
187 private:
188
189 // Placement
190 offset_type offset_;
191 bool is_placed_;
192 const offset_type size_;
193
194 // Backend data
195 ArchData* const adata_;
196
197 //
198 const ident_type ident_;
199 const ident_type subset_of_;
200 const offset_type subset_offset_;
201 };
202
203} // namespace sparta
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Exception class for all of Sparta.
static const ident_type INVALID_ID
Indicates an invalid ID for an ArchDataSegment or any refinement.
ArchDataSegment(ArchData *data, offset_type size, ident_type id, ident_type subset_of=INVALID_ID, offset_type subset_offset=0)
Constructor.
virtual ~ArchDataSegment()
Virtual destructor.
ArchData * getArchData()
Gets the ArchData associated with this segment.
offset_type getOffset() const
Gets the offset of this segment once placed.
void place(offset_type offset)
Sets the offset of this DataView within its ArchData then invokes the place_ method for subclasses to...
const ArchData * getArchData() const
Gets the ArchData associated with this segment.
void writeInitial()
Invokes writeInitial_, giving subclasses a chance to write a value to memory during initialization or...
ident_type getLayoutID() const
Gets the layout Identifier of this segment.
ident_type getSubsetOf() const
Gets the segment of which this segment is a subset.
offset_type getSubsetOffset() const
Gets the offset into the segment of which this segment is a subset.
virtual void place_(offset_type offset)
Allows subclasses to observe placement in an ArchData. Do not write an initial value from within this...
offset_type getLayoutSize() const
Gets the layout size of this segment (number of bytes)
bool isPlaced() const
Has this segment been placed yet.
virtual void writeInitial_()
Write initial value of this segment into ArchData. This occurrs immediately after placement and may o...
Contains a set of contiguous line of architectural data which can be referred to by any architected o...
Definition ArchData.hpp:39
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Macros for handling exponential backoff.
bool isPowerOf2(uint64_t x)
Determines if input is 0 or a power of 2.
Definition Utils.hpp:142