mirror of https://github.com/YosysHQ/yosys.git
gzip: simplify uncompressed interface
This commit is contained in:
parent
094ab8c017
commit
0b96aa1923
|
@ -96,15 +96,17 @@ gzip_istream::ibuf::~ibuf() {
|
|||
|
||||
// Takes a successfully opened ifstream. If it's gzipped, returns an istream. Otherwise,
|
||||
// returns the original ifstream, rewound to the start.
|
||||
std::istream* uncompressed(std::ifstream* f, const std::string filename) {
|
||||
if (!f)
|
||||
return nullptr;
|
||||
std::istream& uncompressed(const std::string filename, std::ios_base::openmode mode) {
|
||||
std::ifstream& f = *new std::ifstream();
|
||||
f.open(filename, mode);
|
||||
if (f.fail())
|
||||
return f;
|
||||
// Check for gzip magic
|
||||
unsigned char magic[3];
|
||||
int n = 0;
|
||||
while (n < 3)
|
||||
{
|
||||
int c = f->get();
|
||||
int c = f.get();
|
||||
if (c != EOF) {
|
||||
magic[n] = (unsigned char) c;
|
||||
}
|
||||
|
@ -116,15 +118,16 @@ std::istream* uncompressed(std::ifstream* f, const std::string filename) {
|
|||
if (magic[2] != 8)
|
||||
log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n",
|
||||
filename.c_str(), unsigned(magic[2]));
|
||||
delete f;
|
||||
gzip_istream* s = new gzip_istream();
|
||||
return s->open(filename.c_str()) ? s : nullptr;
|
||||
gzip_istream& s = *new gzip_istream();
|
||||
delete &f;
|
||||
s.open(filename.c_str());
|
||||
return s;
|
||||
#else
|
||||
log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
|
||||
#endif // YOSYS_ENABLE_ZLIB
|
||||
} else {
|
||||
f->clear();
|
||||
f->seekg(0, std::ios::beg);
|
||||
f.clear();
|
||||
f.seekg(0, std::ios::beg);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ private:
|
|||
|
||||
#endif // YOSYS_ENABLE_ZLIB
|
||||
|
||||
std::istream* uncompressed(std::ifstream* f, const std::string filename);
|
||||
std::istream& uncompressed(const std::string filename, std::ios_base::openmode mode = std::ios_base::in);
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
|
|
|
@ -469,14 +469,8 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
|
|||
next_args.insert(next_args.end(), args.begin(), args.begin()+argidx);
|
||||
next_args.insert(next_args.end(), filenames.begin()+1, filenames.end());
|
||||
}
|
||||
std::ifstream *ff = new std::ifstream;
|
||||
ff->open(filename.c_str(), bin_input ? std::ifstream::binary : std::ifstream::in);
|
||||
yosys_input_files.insert(filename);
|
||||
if (ff->fail()) {
|
||||
delete ff;
|
||||
ff = nullptr;
|
||||
}
|
||||
f = uncompressed(ff, filename);
|
||||
f = &uncompressed(filename, bin_input ? std::ifstream::binary : std::ifstream::in);
|
||||
}
|
||||
if (f == NULL)
|
||||
log_cmd_error("Can't open input file `%s' for reading: %s\n", filename.c_str(), strerror(errno));
|
||||
|
|
|
@ -631,14 +631,12 @@ struct DfflibmapPass : public Pass {
|
|||
|
||||
LibertyMergedCells merged;
|
||||
for (auto path : liberty_files) {
|
||||
std::ifstream f;
|
||||
f.open(path.c_str());
|
||||
std::istream* ff = uncompressed(&f, path);
|
||||
if (ff->fail())
|
||||
std::istream& f = uncompressed(path);
|
||||
if (f.fail())
|
||||
log_cmd_error("Can't open liberty file `%s': %s\n", path.c_str(), strerror(errno));
|
||||
LibertyParser p(*ff);
|
||||
LibertyParser p(f);
|
||||
merged.merge(p);
|
||||
delete ff;
|
||||
delete &f;
|
||||
}
|
||||
|
||||
find_cell(merged.cells, ID($_DFF_N_), false, false, false, false, false, false, dont_use_cells);
|
||||
|
|
Loading…
Reference in New Issue