mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	Merge pull request #5073 from YosysHQ/emil/fix-uncompressed-missing-file-error
gzip: refactor file open failure errors
This commit is contained in:
		
						commit
						11f2348246
					
				
					 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,
 | 
			
		||||
// 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());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -472,8 +472,6 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
 | 
			
		|||
			yosys_input_files.insert(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));
 | 
			
		||||
 | 
			
		||||
		for (size_t i = argidx+1; i < args.size(); i++)
 | 
			
		||||
			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());
 | 
			
		||||
	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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue