aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/nextpnr.cc8
-rw-r--r--common/nextpnr.h150
-rw-r--r--ecp5/arch.cc2
-rw-r--r--generic/arch.cc2
-rw-r--r--ice40/arch.cc2
5 files changed, 90 insertions, 74 deletions
diff --git a/common/nextpnr.cc b/common/nextpnr.cc
index 3861e5fe..c60d0e86 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 BaseCtx *ctx, const std::string &s)
+void IdString::set(const IdStringDB *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 BaseCtx *ctx, const std::string &s)
}
}
-const std::string &IdString::str(const BaseCtx *ctx) const { return *ctx->idstring_idx_to_str->at(index); }
+const std::string &IdString::str(const IdStringDB *ctx) const { return *ctx->idstring_idx_to_str->at(index); }
-const char *IdString::c_str(const BaseCtx *ctx) const { return str(ctx).c_str(); }
+const char *IdString::c_str(const IdStringDB *ctx) const { return str(ctx).c_str(); }
-void IdString::initialize_add(const BaseCtx *ctx, const char *s, int idx)
+void IdString::initialize_add(const IdStringDB *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 50465869..e53e4d01 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -2,6 +2,7 @@
* nextpnr -- Next Generation Place and Route
*
* Copyright (C) 2018 Clifford Wolf <clifford@symbioticeda.com>
+ * Copyright (C) 2018 Serge Bazanski <q3k@symbioticeda.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -88,28 +89,28 @@ inline void assert_false_impl(std::string message, std::string filename, int lin
#define NPNR_ASSERT_MSG(cond, msg) except_assert_impl((cond), msg, #cond, __FILE__, __LINE__)
#define NPNR_ASSERT_FALSE(msg) assert_false_impl(msg, __FILE__, __LINE__)
-struct BaseCtx;
+struct IdStringDB;
struct Context;
struct IdString
{
int index = 0;
- static void initialize_arch(const BaseCtx *ctx);
+ static void initialize_arch(const IdStringDB *ctx);
- static void initialize_add(const BaseCtx *ctx, const char *s, int idx);
+ static void initialize_add(const IdStringDB *ctx, const char *s, int idx);
IdString() {}
- void set(const BaseCtx *ctx, const std::string &s);
+ void set(const IdStringDB *ctx, const std::string &s);
- IdString(const BaseCtx *ctx, const std::string &s) { set(ctx, s); }
+ IdString(const IdStringDB *ctx, const std::string &s) { set(ctx, s); }
- IdString(const BaseCtx *ctx, const char *s) { set(ctx, s); }
+ IdString(const IdStringDB *ctx, const char *s) { set(ctx, s); }
- const std::string &str(const BaseCtx *ctx) const;
+ const std::string &str(const IdStringDB *ctx) const;
- const char *c_str(const BaseCtx *ctx) const;
+ const char *c_str(const IdStringDB *ctx) const;
bool operator<(const IdString &other) const { return index < other.index; }
@@ -238,23 +239,18 @@ struct CellInfo
std::unordered_map<IdString, IdString> pins;
};
-struct BaseCtx
+class IdStringDB
{
- // --------------------------------------------------------------
-
+ 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); }
- // --------------------------------------------------------------
-
- std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets;
- std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells;
-
- BaseCtx()
+ IdStringDB()
{
idstring_str_to_idx = new std::unordered_map<std::string, int>;
idstring_idx_to_str = new std::vector<const std::string *>;
@@ -262,62 +258,22 @@ struct BaseCtx
IdString::initialize_arch(this);
}
- ~BaseCtx()
+ ~IdStringDB()
{
delete idstring_str_to_idx;
delete idstring_idx_to_str;
}
-
- Context *getCtx() { return reinterpret_cast<Context *>(this); }
-
- const Context *getCtx() const { return reinterpret_cast<const Context *>(this); }
-
- // --------------------------------------------------------------
-
- bool allUiReload = false;
- bool frameUiReload = false;
- std::unordered_set<BelId> belUiReload;
- std::unordered_set<WireId> wireUiReload;
- std::unordered_set<PipId> pipUiReload;
- std::unordered_set<GroupId> groupUiReload;
-
- void refreshUi() { allUiReload = true; }
-
- void refreshUiFrame() { frameUiReload = true; }
-
- void refreshUiBel(BelId bel) { belUiReload.insert(bel); }
-
- void refreshUiWire(WireId wire) { wireUiReload.insert(wire); }
-
- void refreshUiPip(PipId pip) { pipUiReload.insert(pip); }
-
- void refreshUiGroup(GroupId group) { groupUiReload.insert(group); }
};
-NEXTPNR_NAMESPACE_END
-
-#include "arch.h"
-
-NEXTPNR_NAMESPACE_BEGIN
-
-struct Context : Arch
+class DeterministicRNG
{
- bool verbose = false;
- bool debug = false;
- bool force = false;
- bool timing_driven = true;
- float target_freq = 12e6;
-
- Context(ArchArgs args) : Arch(args) {}
-
- // --------------------------------------------------------------
+ private:
+ uint64_t rngstate;
- // provided by router1.cc
- bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay);
-
- // --------------------------------------------------------------
-
- uint64_t rngstate = 0x3141592653589793;
+ public:
+ DeterministicRNG() : rngstate(0x3141592653589793)
+ {
+ }
uint64_t rng64()
{
@@ -377,6 +333,66 @@ struct Context : Arch
shuffle(a);
}
+};
+
+class BaseCtx : public IdStringDB, public DeterministicRNG
+{
+ public:
+ std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets;
+ std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells;
+
+ BaseCtx() {}
+ ~BaseCtx() {}
+
+ Context *getCtx() { return reinterpret_cast<Context *>(this); }
+
+ const Context *getCtx() const { return reinterpret_cast<const Context *>(this); }
+
+ // --------------------------------------------------------------
+
+ bool allUiReload = false;
+ bool frameUiReload = false;
+ std::unordered_set<BelId> belUiReload;
+ std::unordered_set<WireId> wireUiReload;
+ std::unordered_set<PipId> pipUiReload;
+ std::unordered_set<GroupId> groupUiReload;
+
+ void refreshUi() { allUiReload = true; }
+
+ void refreshUiFrame() { frameUiReload = true; }
+
+ void refreshUiBel(BelId bel) { belUiReload.insert(bel); }
+
+ void refreshUiWire(WireId wire) { wireUiReload.insert(wire); }
+
+ void refreshUiPip(PipId pip) { pipUiReload.insert(pip); }
+
+ void refreshUiGroup(GroupId group) { groupUiReload.insert(group); }
+};
+
+NEXTPNR_NAMESPACE_END
+
+#include "arch.h"
+
+NEXTPNR_NAMESPACE_BEGIN
+
+struct Context : Arch
+{
+ bool verbose = false;
+ bool debug = false;
+ bool force = false;
+ bool timing_driven = true;
+ float target_freq = 12e6;
+
+ Context(ArchArgs args) : Arch(args) {}
+
+ // --------------------------------------------------------------
+
+ // provided by router1.cc
+ bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay);
+
+ // --------------------------------------------------------------
+
uint32_t checksum() const;
void check() const;
diff --git a/ecp5/arch.cc b/ecp5/arch.cc
index 0ffede3b..83e32351 100644
--- a/ecp5/arch.cc
+++ b/ecp5/arch.cc
@@ -62,7 +62,7 @@ BelType Arch::belTypeFromId(IdString type) const
// -----------------------------------------------------------------------
-void IdString::initialize_arch(const BaseCtx *ctx)
+void IdString::initialize_arch(const IdStringDB *ctx)
{
#define X(t) initialize_add(ctx, #t, PIN_##t);
diff --git a/generic/arch.cc b/generic/arch.cc
index 390830aa..edc2ef26 100644
--- a/generic/arch.cc
+++ b/generic/arch.cc
@@ -157,7 +157,7 @@ void Arch::setGroupDecal(GroupId group, DecalXY decalxy)
Arch::Arch(ArchArgs) {}
-void IdString::initialize_arch(const BaseCtx *ctx) {}
+void IdString::initialize_arch(const IdStringDB *ctx) {}
// ---------------------------------------------------------------
diff --git a/ice40/arch.cc b/ice40/arch.cc
index 69848aff..08e32ae6 100644
--- a/ice40/arch.cc
+++ b/ice40/arch.cc
@@ -102,7 +102,7 @@ BelType Arch::belTypeFromId(IdString type) const
// -----------------------------------------------------------------------
-void IdString::initialize_arch(const BaseCtx *ctx)
+void IdString::initialize_arch(const IdStringDB *ctx)
{
#define X(t) initialize_add(ctx, #t, PIN_##t);
#include "portpins.inc"