diff --git a/kernel/gzip.cc b/kernel/gzip.cc index d44b03517..4567fe03b 100644 --- a/kernel/gzip.cc +++ b/kernel/gzip.cc @@ -100,11 +100,12 @@ 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. +// Never returns nullptr or failed state istream* 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; + log_cmd_error("Can't open input file `%s' for reading: %s\n", filename.c_str(), strerror(errno)); // Check for gzip magic unsigned char magic[3]; int n = 0; @@ -124,7 +125,7 @@ std::istream* uncompressed(const std::string filename, std::ios_base::openmode m filename.c_str(), unsigned(magic[2])); gzip_istream* s = new gzip_istream(); delete f; - s->open(filename.c_str()); + log_assert(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()); diff --git a/kernel/register.cc b/kernel/register.cc index c52bfb5b8..a82f93555 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -472,8 +472,6 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector &cell_area, string libert { std::istream* f = uncompressed(liberty_file.c_str()); yosys_input_files.insert(liberty_file); - if (f->fail()) - log_cmd_error("Can't open liberty file `%s': %s\n", liberty_file.c_str(), strerror(errno)); LibertyParser libparser(*f, liberty_file); delete f; diff --git a/passes/techmap/clockgate.cc b/passes/techmap/clockgate.cc index 2305cfc94..508e66d23 100644 --- a/passes/techmap/clockgate.cc +++ b/passes/techmap/clockgate.cc @@ -310,8 +310,6 @@ struct ClockgatePass : public Pass { LibertyMergedCells merged; for (auto path : liberty_files) { 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, path); merged.merge(p); delete f; diff --git a/passes/techmap/dfflibmap.cc b/passes/techmap/dfflibmap.cc index ae13a6ddd..d00fee83b 100644 --- a/passes/techmap/dfflibmap.cc +++ b/passes/techmap/dfflibmap.cc @@ -635,8 +635,6 @@ struct DfflibmapPass : public Pass { LibertyMergedCells merged; for (auto path : liberty_files) { 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, path); merged.merge(p); delete f;