aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2018-06-19 12:08:37 +0200
committerClifford Wolf <clifford@clifford.at>2018-06-19 12:08:37 +0200
commitc910846c5cefe03ce60d50418389f158846f8341 (patch)
tree6c0da0ba4c22c4309ed5c6ee7b11e66826950b7f /common
parente3519ddfcdfa0e0d3a2942ecf4802c3751db0e17 (diff)
downloadnextpnr-c910846c5cefe03ce60d50418389f158846f8341.tar.gz
nextpnr-c910846c5cefe03ce60d50418389f158846f8341.tar.bz2
nextpnr-c910846c5cefe03ce60d50418389f158846f8341.zip
Refactor Arch/Context design hierarchy
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'common')
-rw-r--r--common/nextpnr.cc10
-rw-r--r--common/nextpnr.h47
2 files changed, 35 insertions, 22 deletions
diff --git a/common/nextpnr.cc b/common/nextpnr.cc
index dbe2a6f7..b093d855 100644
--- a/common/nextpnr.cc
+++ b/common/nextpnr.cc
@@ -21,9 +21,9 @@
NEXTPNR_NAMESPACE_BEGIN
-Context *IdString::global_ctx = nullptr;
+BaseCtx *IdString::global_ctx = nullptr;
-void IdString::set(const Context *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()) {
@@ -35,17 +35,17 @@ void IdString::set(const Context *ctx, const std::string &s)
}
}
-const std::string &IdString::str(const Context *ctx) const
+const std::string &IdString::str(const BaseCtx *ctx) const
{
return *ctx->idstring_idx_to_str->at(index);
}
-const char *IdString::c_str(const Context *ctx) const
+const char *IdString::c_str(const BaseCtx *ctx) const
{
return str(ctx).c_str();
}
-void IdString::initialize_add(const Context *ctx, const char *s, int idx)
+void IdString::initialize_add(const BaseCtx *ctx, const char *s, int idx)
{
assert(ctx->idstring_str_to_idx->count(s) == 0);
assert(int(ctx->idstring_idx_to_str->size()) == idx);
diff --git a/common/nextpnr.h b/common/nextpnr.h
index b8305247..08c941a5 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -41,27 +41,28 @@
NEXTPNR_NAMESPACE_BEGIN
+struct BaseCtx;
struct Context;
struct IdString
{
int index = 0;
- static Context *global_ctx;
+ static BaseCtx *global_ctx;
- static void initialize_arch(const Context *ctx);
- static void initialize_add(const Context *ctx, const char *s, int idx);
+ static void initialize_arch(const BaseCtx *ctx);
+ static void initialize_add(const BaseCtx *ctx, const char *s, int idx);
IdString() {}
- void set(const Context *ctx, const std::string &s);
+ void set(const BaseCtx *ctx, const std::string &s);
- IdString(const Context *ctx, const std::string &s) { set(ctx, s); }
+ IdString(const BaseCtx *ctx, const std::string &s) { set(ctx, s); }
- IdString(const Context *ctx, const char *s) { set(ctx, s); }
+ IdString(const BaseCtx *ctx, const char *s) { set(ctx, s); }
- const std::string &str(const Context *ctx) const;
- const char *c_str(const Context *ctx) const;
+ const std::string &str(const BaseCtx *ctx) const;
+ const char *c_str(const BaseCtx *ctx) const;
bool operator<(const IdString &other) const { return index < other.index; }
@@ -184,7 +185,9 @@ struct GraphicElement
NEXTPNR_NAMESPACE_END
+#define NEXTPNR_ARCH_TOP
#include "arch.h"
+#undef NEXTPNR_ARCH_TOP
NEXTPNR_NAMESPACE_BEGIN
@@ -232,25 +235,22 @@ struct CellInfo
std::unordered_map<IdString, IdString> pins;
};
-struct Context : Arch
+struct BaseCtx
{
// --------------------------------------------------------------
mutable std::unordered_map<std::string, int> *idstring_str_to_idx;
mutable std::vector<const std::string *> *idstring_idx_to_str;
- IdString id(const std::string &s) const override
- {
- return IdString(this, s);
- }
- IdString id(const char *s) const override { return IdString(this, s); }
+ 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, NetInfo *> nets;
std::unordered_map<IdString, CellInfo *> cells;
- Context(ArchArgs args) : Arch(args)
+ BaseCtx()
{
assert(IdString::global_ctx == nullptr);
IdString::global_ctx = this;
@@ -259,11 +259,24 @@ struct Context : Arch
idstring_idx_to_str = new std::vector<const std::string *>;
IdString::initialize_add(this, "", 0);
IdString::initialize_arch(this);
-
- // ...
}
};
NEXTPNR_NAMESPACE_END
+#define NEXTPNR_ARCH_BOTTOM
+#include "arch.h"
+#undef NEXTPNR_ARCH_BOTTOM
+
+NEXTPNR_NAMESPACE_BEGIN
+
+struct Context : Arch
+{
+ bool verbose = false;
+
+ Context(ArchArgs args) : Arch(args) {}
+};
+
+NEXTPNR_NAMESPACE_END
+
#endif