Move RelPtr/RelSlice out of arches into common
The bba approach seems widely used enough that it's reasonable for this to become part of common code. Signed-off-by: D. Shah <dave@ds0.me>
This commit is contained in:
parent
3fc5455ec5
commit
75ee2fc4e6
39
common/relptr.h
Normal file
39
common/relptr.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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(); }
|
||||||
|
});
|
38
ecp5/arch.h
38
ecp5/arch.h
@ -29,43 +29,7 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
/**** Everything in this section must be kept in sync with chipdb.py ****/
|
/**** Everything in this section must be kept in sync with chipdb.py ****/
|
||||||
|
|
||||||
template <typename T> struct RelPtr
|
#include "relptr.h"
|
||||||
{
|
|
||||||
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(); }
|
|
||||||
});
|
|
||||||
|
|
||||||
NPNR_PACKED_STRUCT(struct BelWirePOD {
|
NPNR_PACKED_STRUCT(struct BelWirePOD {
|
||||||
LocationPOD rel_wire_loc;
|
LocationPOD rel_wire_loc;
|
||||||
|
43
ice40/arch.h
43
ice40/arch.h
@ -25,48 +25,7 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
/**** Everything in this section must be kept in sync with chipdb.py ****/
|
/**** Everything in this section must be kept in sync with chipdb.py ****/
|
||||||
|
|
||||||
template <typename T> struct RelPtr
|
#include "relptr.h"
|
||||||
{
|
|
||||||
int32_t offset;
|
|
||||||
|
|
||||||
// void set(const T *ptr) {
|
|
||||||
// offset = reinterpret_cast<const char*>(ptr) -
|
|
||||||
// reinterpret_cast<const char*>(this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
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(); }
|
|
||||||
});
|
|
||||||
|
|
||||||
NPNR_PACKED_STRUCT(struct BelWirePOD {
|
NPNR_PACKED_STRUCT(struct BelWirePOD {
|
||||||
int32_t port;
|
int32_t port;
|
||||||
|
40
nexus/arch.h
40
nexus/arch.h
@ -28,45 +28,7 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
template <typename T> struct RelPtr
|
#include "relptr.h"
|
||||||
{
|
|
||||||
int32_t offset;
|
|
||||||
|
|
||||||
// void set(const T *ptr) {
|
|
||||||
// offset = reinterpret_cast<const char*>(ptr) -
|
|
||||||
// reinterpret_cast<const char*>(this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
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(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
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(); }
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Fully deduplicated database
|
Fully deduplicated database
|
||||||
|
Loading…
Reference in New Issue
Block a user