diff options
| author | Clifford Wolf <clifford@clifford.at> | 2018-05-23 17:58:57 +0200 | 
|---|---|---|
| committer | Clifford Wolf <clifford@clifford.at> | 2018-05-23 17:58:57 +0200 | 
| commit | 22558704460b19425d28cc91b2565c7964ed7a19 (patch) | |
| tree | 600f3477c33837df80ad4a114017fdee8f953de0 | |
| parent | daa48858201d1f4851efcb6754e44b95e8fae656 (diff) | |
| download | nextpnr-22558704460b19425d28cc91b2565c7964ed7a19.tar.gz nextpnr-22558704460b19425d28cc91b2565c7964ed7a19.tar.bz2 nextpnr-22558704460b19425d28cc91b2565c7964ed7a19.zip  | |
Create compile-able demo that doesn't do anything
Signed-off-by: Clifford Wolf <clifford@clifford.at>
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | database.cc | 15 | ||||
| -rw-r--r-- | database.h (renamed from apidraft.h) | 56 | ||||
| -rw-r--r-- | demo.cc | 13 | 
4 files changed, 71 insertions, 14 deletions
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*"; +} @@ -1,13 +1,20 @@  #include <stdint.h> +#include <vector>  #include <string> +#include <unordered_set> +#include <unordered_map>  // replace with proper IdString later  typedef std::string IdString; +// replace with haslib later +template<typename T> using pool = std::unordered_set<T>; +template<typename T, typename U> using dict = std::unordered_map<T, U>; +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<ObjId> +        { +		std::size_t operator()(const ObjId &obj) const noexcept +		{ +			std::size_t result = std::hash<int>{}(obj.index); +			result ^= std::hash<int>{}(obj.tile_x) + 0x9e3779b9 + (result << 6) + (result >> 2); +			result ^= std::hash<int>{}(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<IdString, *NetInfo> nets; -	dict<IdString, *CellInfo> cells; +	dict<IdString, NetInfo*> nets; +	dict<IdString, CellInfo*> 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; +}  | 
