diff --git a/kernel/gzip.cc b/kernel/gzip.cc index f31d535df..d44b03517 100644 --- a/kernel/gzip.cc +++ b/kernel/gzip.cc @@ -100,17 +100,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(const std::string filename, std::ios_base::openmode mode) { - std::ifstream& f = *new std::ifstream(); - f.open(filename, mode); - if (f.fail()) +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; } @@ -122,16 +122,16 @@ std::istream& uncompressed(const std::string filename, std::ios_base::openmode m if (magic[2] != 8) log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n", filename.c_str(), unsigned(magic[2])); - gzip_istream& s = *new gzip_istream(); - delete &f; - s.open(filename.c_str()); + 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; } } diff --git a/kernel/gzip.h b/kernel/gzip.h index 57eac73c8..aac5340de 100644 --- a/kernel/gzip.h +++ b/kernel/gzip.h @@ -71,7 +71,7 @@ private: #endif // YOSYS_ENABLE_ZLIB -std::istream& uncompressed(const std::string filename, std::ios_base::openmode mode = std::ios_base::in); +std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode = std::ios_base::in); YOSYS_NAMESPACE_END diff --git a/kernel/register.cc b/kernel/register.cc index 040cc6207..7add24601 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -470,7 +470,7 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vectorfail()) log_cmd_error("Can't open liberty file `%s': %s\n", path.c_str(), strerror(errno)); - LibertyParser p(f); + LibertyParser p(*f); merged.merge(p); - delete &f; + delete f; } std::tie(pos_icg_desc, neg_icg_desc) = find_icgs(merged.cells, dont_use_cells); diff --git a/passes/techmap/dfflibmap.cc b/passes/techmap/dfflibmap.cc index df2bfa88f..fe4f8aada 100644 --- a/passes/techmap/dfflibmap.cc +++ b/passes/techmap/dfflibmap.cc @@ -631,12 +631,12 @@ struct DfflibmapPass : public Pass { LibertyMergedCells merged; for (auto path : liberty_files) { - std::istream& f = uncompressed(path); - if (f.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(f); + LibertyParser p(*f); merged.merge(p); - delete &f; + delete f; } find_cell(merged.cells, ID($_DFF_N_), false, false, false, false, false, false, dont_use_cells);