mirror of https://github.com/YosysHQ/yosys.git
Add support for writing gzip-compressed files
Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
parent
a4b59de5d4
commit
27360ceda6
|
@ -16,6 +16,7 @@ Yosys 0.9 .. Yosys 0.9-dev
|
||||||
- "synth_xilinx" to now infer wide multiplexers (-widemux <min> to enable)
|
- "synth_xilinx" to now infer wide multiplexers (-widemux <min> to enable)
|
||||||
- Added automatic gzip decompression for frontends
|
- Added automatic gzip decompression for frontends
|
||||||
- Added $_NMUX_ cell type
|
- Added $_NMUX_ cell type
|
||||||
|
- Added automatic gzip compression (based on filename extension) for backends
|
||||||
|
|
||||||
Yosys 0.8 .. Yosys 0.8-dev
|
Yosys 0.8 .. Yosys 0.8-dev
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
|
@ -41,6 +41,45 @@ void decompress_gzip(const std::string &filename, std::stringstream &out)
|
||||||
}
|
}
|
||||||
gzclose(gzf);
|
gzclose(gzf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
An output stream that uses a stringbuf to buffer data internally,
|
||||||
|
using zlib to write gzip-compressed data every time the stream is flushed.
|
||||||
|
*/
|
||||||
|
class gzip_ostream : public std::ostream {
|
||||||
|
public:
|
||||||
|
gzip_ostream()
|
||||||
|
{
|
||||||
|
rdbuf(&outbuf);
|
||||||
|
}
|
||||||
|
bool open(const std::string &filename)
|
||||||
|
{
|
||||||
|
return outbuf.open(filename);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
class gzip_streambuf : public std::stringbuf {
|
||||||
|
public:
|
||||||
|
gzip_streambuf() { };
|
||||||
|
bool open(const std::string &filename)
|
||||||
|
{
|
||||||
|
gzf = gzopen(filename.c_str(), "wb");
|
||||||
|
return gzf != nullptr;
|
||||||
|
}
|
||||||
|
virtual int sync() override
|
||||||
|
{
|
||||||
|
gzwrite(gzf, reinterpret_cast<const void *>(str().c_str()), unsigned(str().size()));
|
||||||
|
str("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
~gzip_streambuf()
|
||||||
|
{
|
||||||
|
sync();
|
||||||
|
gzclose(gzf);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
gzFile gzf = nullptr;
|
||||||
|
} outbuf;
|
||||||
|
};
|
||||||
PRIVATE_NAMESPACE_END
|
PRIVATE_NAMESPACE_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -588,14 +627,28 @@ void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector<st
|
||||||
|
|
||||||
filename = arg;
|
filename = arg;
|
||||||
rewrite_filename(filename);
|
rewrite_filename(filename);
|
||||||
std::ofstream *ff = new std::ofstream;
|
if (filename.size() > 3 && filename.substr(filename.size()-3) == ".gz") {
|
||||||
ff->open(filename.c_str(), std::ofstream::trunc);
|
#ifdef YOSYS_ENABLE_ZLIB
|
||||||
yosys_output_files.insert(filename);
|
gzip_ostream *gf = new gzip_ostream;
|
||||||
if (ff->fail()) {
|
if (!gf->open(filename)) {
|
||||||
delete ff;
|
delete gf;
|
||||||
log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
|
log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
|
||||||
|
}
|
||||||
|
yosys_output_files.insert(filename);
|
||||||
|
f = gf;
|
||||||
|
#else
|
||||||
|
log_cmd_error("Yosys is compiled without zlib support, unable to write gzip output.\n");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
std::ofstream *ff = new std::ofstream;
|
||||||
|
ff->open(filename.c_str(), std::ofstream::trunc);
|
||||||
|
yosys_output_files.insert(filename);
|
||||||
|
if (ff->fail()) {
|
||||||
|
delete ff;
|
||||||
|
log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
|
||||||
|
}
|
||||||
|
f = ff;
|
||||||
}
|
}
|
||||||
f = ff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (called_with_fp)
|
if (called_with_fp)
|
||||||
|
|
Loading…
Reference in New Issue