aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/register.cc
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-07-26 10:23:58 +0100
committerDavid Shah <dave@ds0.me>2019-07-26 10:23:58 +0100
commit933db0410e096286c21772f5a2f44b03d2ed0b57 (patch)
tree2934bfb6d1cb472d1b3100099307c2f9e25d96aa /kernel/register.cc
parentd6a289d3e3a09d1f11ec1588a4b4e9d6846517e8 (diff)
downloadyosys-933db0410e096286c21772f5a2f44b03d2ed0b57.tar.gz
yosys-933db0410e096286c21772f5a2f44b03d2ed0b57.tar.bz2
yosys-933db0410e096286c21772f5a2f44b03d2ed0b57.zip
Add support for reading gzip'd input files
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'kernel/register.cc')
-rw-r--r--kernel/register.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/kernel/register.cc b/kernel/register.cc
index 26da96b95..4f1501330 100644
--- a/kernel/register.cc
+++ b/kernel/register.cc
@@ -25,6 +25,26 @@
#include <stdio.h>
#include <errno.h>
+#ifdef YOSYS_ENABLE_ZLIB
+#include <zlib.h>
+
+PRIVATE_NAMESPACE_BEGIN
+#define GZ_BUFFER_SIZE 8192
+void decompress_gzip(const std::string &filename, std::stringstream &out)
+{
+ char buffer[GZ_BUFFER_SIZE];
+ int bytes_read;
+ gzFile gzf = gzopen(filename.c_str(), "rb");
+ while(!gzeof(gzf)) {
+ bytes_read = gzread(gzf, reinterpret_cast<void *>(buffer), GZ_BUFFER_SIZE);
+ out.write(buffer, bytes_read);
+ }
+ gzclose(gzf);
+}
+PRIVATE_NAMESPACE_END
+
+#endif
+
YOSYS_NAMESPACE_BEGIN
#define MAX_REG_COUNT 1000
@@ -436,6 +456,26 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
delete ff;
else
f = ff;
+ // Check for gzip magic
+ unsigned char magic[3];
+ int n = readsome(*ff, reinterpret_cast<char*>(magic), 3);
+ if (n == 3 && magic[0] == 0x1f && magic[1] == 0x8b) {
+#ifdef YOSYS_ENABLE_ZLIB
+ log("Found gzip magic in file `%s', decompressing using zlib.\n", filename.c_str());
+ if (magic[2] != 8)
+ log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n",
+ filename.c_str(), unsigned(magic[2]));
+ delete ff;
+ std::stringstream *df = new std::stringstream();
+ decompress_gzip(filename, *df);
+ f = df;
+#else
+ log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
+#endif
+ } else {
+ ff->clear();
+ ff->seekg(0, std::ios::beg);
+ }
}
if (f == NULL)
log_cmd_error("Can't open input file `%s' for reading: %s\n", filename.c_str(), strerror(errno));