From 22558704460b19425d28cc91b2565c7964ed7a19 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 23 May 2018 17:58:57 +0200 Subject: [PATCH] Create compile-able demo that doesn't do anything Signed-off-by: Clifford Wolf --- .gitignore | 1 + database.cc | 15 +++++++++++ apidraft.h => database.h | 56 ++++++++++++++++++++++++++++++---------- demo.cc | 13 ++++++++++ 4 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 .gitignore create mode 100644 database.cc rename apidraft.h => database.h (61%) create mode 100644 demo.cc diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..69ff7396 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/demo diff --git a/database.cc b/database.cc new file mode 100644 index 00000000..8eb64473 --- /dev/null +++ b/database.cc @@ -0,0 +1,15 @@ +#include "database.h" + +Chip::Chip(std::string) +{ +} + +ObjRange Chip::getBels() const +{ + return ObjRange(); +} + +IdString Chip::getObjName(ObjId obj) const +{ + return "*unknown*"; +} diff --git a/apidraft.h b/database.h similarity index 61% rename from apidraft.h rename to database.h index b14ddfee..81205f20 100644 --- a/apidraft.h +++ b/database.h @@ -1,13 +1,20 @@ #include +#include #include +#include +#include // replace with proper IdString later typedef std::string IdString; +// replace with haslib later +template using pool = std::unordered_set; +template using dict = std::unordered_map; +using std::vector; + // ------------------------------------------------------- // Arch-specific declarations -#ifdef ARCH_ICE40 struct ObjId { uint8_t tile_x = 0, tile_y = 0; @@ -18,16 +25,34 @@ struct ObjId } } __attribute__((packed)); +namespace std +{ + template<> struct hash + { + std::size_t operator()(const ObjId &obj) const noexcept + { + std::size_t result = std::hash{}(obj.index); + result ^= std::hash{}(obj.tile_x) + 0x9e3779b9 + (result << 6) + (result >> 2); + result ^= std::hash{}(obj.tile_y) + 0x9e3779b9 + (result << 6) + (result >> 2); + return result; + } + }; +} + struct ObjIterator { - // ... - ObjId operator*() const; + ObjId *ptr = nullptr; + + void operator++() { ptr++; } + bool operator!=(const ObjIterator &other) const { return ptr != other.ptr; } + ObjId operator*() const { return *ptr; } }; struct ObjRange { - ObjIterator begin(); - ObjIterator end(); + ObjIterator b, e; + ObjIterator begin() const { return b; } + ObjIterator end() const { return e; } }; struct BelPin @@ -38,14 +63,18 @@ struct BelPin struct BelPinIterator { - // ... - BelPin operator*() const; + BelPin *ptr = nullptr; + + void operator++() { ptr++; } + bool operator!=(const BelPinIterator &other) const { return ptr != other.ptr; } + BelPin operator*() const { return *ptr; } }; struct BelPinRange { - BelPinIterator begin(); - BelPinIterator end(); + BelPinIterator b, e; + BelPinIterator begin() const { return b; } + BelPinIterator end() const { return e; } }; struct GuiLine @@ -84,7 +113,6 @@ struct Chip BelPin getBelPinUphill(ObjId wire) const; BelPinRange getBelPinsDownhill(ObjId wire) const; }; -#endif // ------------------------------------------------------- // Generic declarations @@ -132,12 +160,12 @@ struct CellInfo struct Design { - struct Chip; + struct Chip chip; - Design(std::string chipCfg) : Chip(chipCfg) { + Design(std::string chipCfg) : chip(chipCfg) { // ... } - dict nets; - dict cells; + dict nets; + dict cells; }; diff --git a/demo.cc b/demo.cc new file mode 100644 index 00000000..3a5ca0c0 --- /dev/null +++ b/demo.cc @@ -0,0 +1,13 @@ +// clang -o demo -Wall -std=c++11 demo.cc database.cc -lstdc++ + +#include "database.h" + +int main() +{ + Design design("default"); + + for (auto bel : design.chip.getBels()) + printf("%s\n", design.chip.getObjName(bel).c_str()); + + return 0; +}