aboutsummaryrefslogtreecommitdiffstats
path: root/common/kernel/embed.cc
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2022-04-08 14:32:33 +0100
committerGitHub <noreply@github.com>2022-04-08 14:32:33 +0100
commit57681e69ce75c781142908cf128bc3f3f59e2f6b (patch)
treeea642e20bc07441a800944390e1f904e6ce5b113 /common/kernel/embed.cc
parente42e22575f20b59634f88b5cf694efdb413ff0a0 (diff)
parent49f178ed94b5fad00d25dbd12adea0bf4732f803 (diff)
downloadnextpnr-57681e69ce75c781142908cf128bc3f3f59e2f6b.tar.gz
nextpnr-57681e69ce75c781142908cf128bc3f3f59e2f6b.tar.bz2
nextpnr-57681e69ce75c781142908cf128bc3f3f59e2f6b.zip
Merge pull request #973 from YosysHQ/gatecat/folder-tidy
Split up common into kernel,place,route
Diffstat (limited to 'common/kernel/embed.cc')
-rw-r--r--common/kernel/embed.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/common/kernel/embed.cc b/common/kernel/embed.cc
new file mode 100644
index 00000000..70bbc6fb
--- /dev/null
+++ b/common/kernel/embed.cc
@@ -0,0 +1,49 @@
+#if defined(WIN32)
+#include <windows.h>
+#endif
+#include <boost/filesystem.hpp>
+#include <boost/iostreams/device/mapped_file.hpp>
+#include "embed.h"
+#include "nextpnr.h"
+
+NEXTPNR_NAMESPACE_BEGIN
+
+#if defined(EXTERNAL_CHIPDB_ROOT)
+
+const void *get_chipdb(const std::string &filename)
+{
+ static std::map<std::string, boost::iostreams::mapped_file> files;
+ if (!files.count(filename)) {
+ std::string full_filename = EXTERNAL_CHIPDB_ROOT "/" + filename;
+ if (boost::filesystem::exists(full_filename))
+ files[filename].open(full_filename, boost::iostreams::mapped_file::priv);
+ }
+ if (files.count(filename))
+ return files.at(filename).data();
+ return nullptr;
+}
+
+#elif defined(WIN32)
+
+const void *get_chipdb(const std::string &filename)
+{
+ HRSRC rc = ::FindResource(nullptr, filename.c_str(), RT_RCDATA);
+ HGLOBAL rcData = ::LoadResource(nullptr, rc);
+ return ::LockResource(rcData);
+}
+
+#else
+
+EmbeddedFile *EmbeddedFile::head = nullptr;
+
+const void *get_chipdb(const std::string &filename)
+{
+ for (EmbeddedFile *file = EmbeddedFile::head; file; file = file->next)
+ if (file->filename == filename)
+ return file->content;
+ return nullptr;
+}
+
+#endif
+
+NEXTPNR_NAMESPACE_END