mirror of
https://github.com/YosysHQ/nextpnr.git
synced 2026-04-18 00:48:31 +00:00
Merge pull request #553 from YosysHQ/rel-slice
Switch from RelPtr to RelSlice
This commit is contained in:
42
common/relptr.h
Normal file
42
common/relptr.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// This is intended to be included inside arch.h only.
|
||||
|
||||
template <typename T> struct RelPtr
|
||||
{
|
||||
int32_t offset;
|
||||
|
||||
const T *get() const { return reinterpret_cast<const T *>(reinterpret_cast<const char *>(this) + offset); }
|
||||
|
||||
const T &operator[](size_t index) const { return get()[index]; }
|
||||
|
||||
const T &operator*() const { return *(get()); }
|
||||
|
||||
const T *operator->() const { return get(); }
|
||||
|
||||
RelPtr(const RelPtr &) = delete;
|
||||
RelPtr &operator=(const RelPtr &) = delete;
|
||||
};
|
||||
|
||||
NPNR_PACKED_STRUCT(template <typename T> struct RelSlice {
|
||||
int32_t offset;
|
||||
uint32_t length;
|
||||
|
||||
const T *get() const { return reinterpret_cast<const T *>(reinterpret_cast<const char *>(this) + offset); }
|
||||
|
||||
const T &operator[](size_t index) const
|
||||
{
|
||||
NPNR_ASSERT(index < length);
|
||||
return get()[index];
|
||||
}
|
||||
|
||||
const T *begin() const { return get(); }
|
||||
const T *end() const { return get() + length; }
|
||||
|
||||
const size_t size() const { return length; }
|
||||
|
||||
const T &operator*() const { return *(get()); }
|
||||
|
||||
const T *operator->() const { return get(); }
|
||||
|
||||
RelSlice(const RelSlice &) = delete;
|
||||
RelSlice &operator=(const RelSlice &) = delete;
|
||||
});
|
||||
Reference in New Issue
Block a user