Skip to content

Commit

Permalink
gzip: back to pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Jan 9, 2025
1 parent fa8642b commit b85dda9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions kernel/gzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/gzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class gzip_istream final : public std::istream {

#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

Expand Down
2 changes: 1 addition & 1 deletion kernel/register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
next_args.insert(next_args.end(), filenames.begin()+1, filenames.end());
}
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));
Expand Down
8 changes: 4 additions & 4 deletions passes/techmap/clockgate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ struct ClockgatePass : public Pass {
if (!liberty_files.empty()) {
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;
}
std::tie(pos_icg_desc, neg_icg_desc) =
find_icgs(merged.cells, dont_use_cells);
Expand Down
8 changes: 4 additions & 4 deletions passes/techmap/dfflibmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b85dda9

Please sign in to comment.