mirror of
https://github.com/YosysHQ/yosys
synced 2025-05-04 06:15:47 +00:00
gzip: refactor file open failure errors
This commit is contained in:
parent
ab614b1271
commit
adb1986dc1
5 changed files with 3 additions and 10 deletions
|
@ -100,11 +100,12 @@ gzip_istream::ibuf::~ibuf() {
|
||||||
|
|
||||||
// Takes a successfully opened ifstream. If it's gzipped, returns an istream. Otherwise,
|
// Takes a successfully opened ifstream. If it's gzipped, returns an istream. Otherwise,
|
||||||
// returns the original ifstream, rewound to the start.
|
// 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::istream* uncompressed(const std::string filename, std::ios_base::openmode mode) {
|
||||||
std::ifstream* f = new std::ifstream();
|
std::ifstream* f = new std::ifstream();
|
||||||
f->open(filename, mode);
|
f->open(filename, mode);
|
||||||
if (f->fail())
|
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
|
// Check for gzip magic
|
||||||
unsigned char magic[3];
|
unsigned char magic[3];
|
||||||
int n = 0;
|
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]));
|
filename.c_str(), unsigned(magic[2]));
|
||||||
gzip_istream* s = new gzip_istream();
|
gzip_istream* s = new gzip_istream();
|
||||||
delete f;
|
delete f;
|
||||||
s->open(filename.c_str());
|
log_assert(s->open(filename.c_str()));
|
||||||
return s;
|
return s;
|
||||||
#else
|
#else
|
||||||
log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
|
log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename.c_str());
|
||||||
|
|
|
@ -472,8 +472,6 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
|
||||||
yosys_input_files.insert(filename);
|
yosys_input_files.insert(filename);
|
||||||
f = uncompressed(filename, bin_input ? std::ifstream::binary : std::ifstream::in);
|
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));
|
|
||||||
|
|
||||||
for (size_t i = argidx+1; i < args.size(); i++)
|
for (size_t i = argidx+1; i < args.size(); i++)
|
||||||
if (args[i].compare(0, 1, "-") == 0)
|
if (args[i].compare(0, 1, "-") == 0)
|
||||||
|
|
|
@ -350,8 +350,6 @@ void read_liberty_cellarea(dict<IdString, cell_area_t> &cell_area, string libert
|
||||||
{
|
{
|
||||||
std::istream* f = uncompressed(liberty_file.c_str());
|
std::istream* f = uncompressed(liberty_file.c_str());
|
||||||
yosys_input_files.insert(liberty_file);
|
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);
|
LibertyParser libparser(*f, liberty_file);
|
||||||
delete f;
|
delete f;
|
||||||
|
|
||||||
|
|
|
@ -310,8 +310,6 @@ struct ClockgatePass : public Pass {
|
||||||
LibertyMergedCells merged;
|
LibertyMergedCells merged;
|
||||||
for (auto path : liberty_files) {
|
for (auto path : liberty_files) {
|
||||||
std::istream* f = uncompressed(path);
|
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);
|
LibertyParser p(*f, path);
|
||||||
merged.merge(p);
|
merged.merge(p);
|
||||||
delete f;
|
delete f;
|
||||||
|
|
|
@ -635,8 +635,6 @@ struct DfflibmapPass : public Pass {
|
||||||
LibertyMergedCells merged;
|
LibertyMergedCells merged;
|
||||||
for (auto path : liberty_files) {
|
for (auto path : liberty_files) {
|
||||||
std::istream* f = uncompressed(path);
|
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);
|
LibertyParser p(*f, path);
|
||||||
merged.merge(p);
|
merged.merge(p);
|
||||||
delete f;
|
delete f;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue