diff options
author | Sergiusz Bazanski <q3k@q3k.org> | 2018-07-20 18:24:16 +0100 |
---|---|---|
committer | Sergiusz Bazanski <q3k@q3k.org> | 2018-07-20 18:24:16 +0100 |
commit | 76e5236fb3c161a860b2c494fe44fde3011670af (patch) | |
tree | fbdb2e898de5fd26b8900b56fce1f7844cac3318 /common | |
parent | b5b956bd214742892cd242ec38e4cc64c213e59e (diff) | |
download | nextpnr-76e5236fb3c161a860b2c494fe44fde3011670af.tar.gz nextpnr-76e5236fb3c161a860b2c494fe44fde3011670af.tar.bz2 nextpnr-76e5236fb3c161a860b2c494fe44fde3011670af.zip |
Nuke IdStringDB
Diffstat (limited to 'common')
-rw-r--r-- | common/nextpnr.cc | 8 | ||||
-rw-r--r-- | common/nextpnr.h | 77 |
2 files changed, 38 insertions, 47 deletions
diff --git a/common/nextpnr.cc b/common/nextpnr.cc index c60d0e86..3861e5fe 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -27,7 +27,7 @@ assertion_failure::assertion_failure(std::string msg, std::string expr_str, std: { } -void IdString::set(const IdStringDB *ctx, const std::string &s) +void IdString::set(const BaseCtx *ctx, const std::string &s) { auto it = ctx->idstring_str_to_idx->find(s); if (it == ctx->idstring_str_to_idx->end()) { @@ -39,11 +39,11 @@ void IdString::set(const IdStringDB *ctx, const std::string &s) } } -const std::string &IdString::str(const IdStringDB *ctx) const { return *ctx->idstring_idx_to_str->at(index); } +const std::string &IdString::str(const BaseCtx *ctx) const { return *ctx->idstring_idx_to_str->at(index); } -const char *IdString::c_str(const IdStringDB *ctx) const { return str(ctx).c_str(); } +const char *IdString::c_str(const BaseCtx *ctx) const { return str(ctx).c_str(); } -void IdString::initialize_add(const IdStringDB *ctx, const char *s, int idx) +void IdString::initialize_add(const BaseCtx *ctx, const char *s, int idx) { NPNR_ASSERT(ctx->idstring_str_to_idx->count(s) == 0); NPNR_ASSERT(int(ctx->idstring_idx_to_str->size()) == idx); diff --git a/common/nextpnr.h b/common/nextpnr.h index 2baedef4..d42d3446 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -93,28 +93,28 @@ inline bool assert_fail_impl_str(std::string message, const char *expr_str, cons #define NPNR_ASSERT_FALSE(msg) (assert_fail_impl(msg, "false", __FILE__, __LINE__)) #define NPNR_ASSERT_FALSE_STR(msg) (assert_fail_impl_str(msg, "false", __FILE__, __LINE__)) -struct IdStringDB; +struct BaseCtx; struct Context; struct IdString { int index = 0; - static void initialize_arch(const IdStringDB *ctx); + static void initialize_arch(const BaseCtx *ctx); - static void initialize_add(const IdStringDB *ctx, const char *s, int idx); + static void initialize_add(const BaseCtx *ctx, const char *s, int idx); IdString() {} - void set(const IdStringDB *ctx, const std::string &s); + void set(const BaseCtx *ctx, const std::string &s); - IdString(const IdStringDB *ctx, const std::string &s) { set(ctx, s); } + IdString(const BaseCtx *ctx, const std::string &s) { set(ctx, s); } - IdString(const IdStringDB *ctx, const char *s) { set(ctx, s); } + IdString(const BaseCtx *ctx, const char *s) { set(ctx, s); } - const std::string &str(const IdStringDB *ctx) const; + const std::string &str(const BaseCtx *ctx) const; - const char *c_str(const IdStringDB *ctx) const; + const char *c_str(const BaseCtx *ctx) const; bool operator<(const IdString &other) const { return index < other.index; } @@ -247,39 +247,10 @@ struct CellInfo : ArchCellInfo std::unordered_map<IdString, IdString> pins; }; -class IdStringDB +struct DeterministicRNG { - friend class IdString; - - private: - mutable std::unordered_map<std::string, int> *idstring_str_to_idx; - mutable std::vector<const std::string *> *idstring_idx_to_str; - - public: - IdString id(const std::string &s) const { return IdString(this, s); } - IdString id(const char *s) const { return IdString(this, s); } - - IdStringDB() - { - idstring_str_to_idx = new std::unordered_map<std::string, int>; - idstring_idx_to_str = new std::vector<const std::string *>; - IdString::initialize_add(this, "", 0); - IdString::initialize_arch(this); - } - - ~IdStringDB() - { - delete idstring_str_to_idx; - delete idstring_idx_to_str; - } -}; - -class DeterministicRNG -{ - private: uint64_t rngstate; - public: DeterministicRNG() : rngstate(0x3141592653589793) {} uint64_t rng64() @@ -341,19 +312,35 @@ class DeterministicRNG } }; -class BaseCtx : public IdStringDB +struct BaseCtx { - private: + // Lock to perform mutating actions on the Context. std::mutex mutex; pthread_t mutex_owner; - public: + // ID String database. + mutable std::unordered_map<std::string, int> *idstring_str_to_idx; + mutable std::vector<const std::string *> *idstring_idx_to_str; + + // Placed nets and cells. std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets; std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells; - BaseCtx() {} - ~BaseCtx() {} + BaseCtx() + { + idstring_str_to_idx = new std::unordered_map<std::string, int>; + idstring_idx_to_str = new std::vector<const std::string *>; + IdString::initialize_add(this, "", 0); + IdString::initialize_arch(this); + } + + ~BaseCtx() + { + delete idstring_str_to_idx; + delete idstring_idx_to_str; + } + // Must be called before performing any mutating changes on the Ctx/Arch. void lock(void) { mutex.lock(); @@ -374,6 +361,10 @@ class BaseCtx : public IdStringDB } } + IdString id(const std::string &s) const { return IdString(this, s); } + + IdString id(const char *s) const { return IdString(this, s); } + Context *getCtx() { return reinterpret_cast<Context *>(this); } const Context *getCtx() const { return reinterpret_cast<const Context *>(this); } |