summaryrefslogtreecommitdiff
path: root/passes
diff options
context:
space:
mode:
Diffstat (limited to 'passes')
-rw-r--r--passes/cmds/show.cc8
-rw-r--r--passes/cmds/write_file.cc4
-rw-r--r--passes/techmap/dfflibmap.cc7
-rw-r--r--passes/techmap/extract.cc9
-rw-r--r--passes/techmap/libparse.cc40
-rw-r--r--passes/techmap/libparse.h4
-rw-r--r--passes/techmap/techmap.cc13
7 files changed, 47 insertions, 38 deletions
diff --git a/passes/cmds/show.cc b/passes/cmds/show.cc
index fc6e972e..3468eae7 100644
--- a/passes/cmds/show.cc
+++ b/passes/cmds/show.cc
@@ -720,13 +720,13 @@ struct ShowPass : public Pass {
}
for (auto filename : libfiles) {
- FILE *f = fopen(filename.c_str(), "rt");
- if (f == NULL)
+ std::ifstream f;
+ f.open(filename.c_str());
+ if (f.fail())
log_error("Can't open lib file `%s'.\n", filename.c_str());
RTLIL::Design *lib = new RTLIL::Design;
- Frontend::frontend_call(lib, f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) == ".il") ? "ilang" : "verilog");
+ Frontend::frontend_call(lib, &f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) == ".il") ? "ilang" : "verilog");
libs.push_back(lib);
- fclose(f);
}
if (libs.size() > 0)
diff --git a/passes/cmds/write_file.cc b/passes/cmds/write_file.cc
index a7cd7b43..813e215b 100644
--- a/passes/cmds/write_file.cc
+++ b/passes/cmds/write_file.cc
@@ -41,7 +41,7 @@ struct WriteFileFrontend : public Frontend {
log(" EOT\n");
log("\n");
}
- virtual void execute(FILE *&f, std::string filename, std::vector<std::string> args, RTLIL::Design*)
+ virtual void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design*)
{
bool append_mode = false;
std::string output_filename;
@@ -67,7 +67,7 @@ struct WriteFileFrontend : public Frontend {
char buffer[64 * 1024];
size_t bytes;
- while (0 < (bytes = fread(buffer, 1, sizeof(buffer), f)))
+ while (0 < (bytes = f->readsome(buffer, sizeof(buffer))))
fwrite(buffer, bytes, 1, of);
fclose(of);
diff --git a/passes/techmap/dfflibmap.cc b/passes/techmap/dfflibmap.cc
index 6ce771ac..7e39040c 100644
--- a/passes/techmap/dfflibmap.cc
+++ b/passes/techmap/dfflibmap.cc
@@ -463,11 +463,12 @@ struct DfflibmapPass : public Pass {
if (liberty_file.empty())
log_cmd_error("Missing `-liberty liberty_file' option!\n");
- FILE *f = fopen(liberty_file.c_str(), "r");
- if (f == NULL)
+ std::ifstream f;
+ f.open(liberty_file.c_str());
+ if (f.fail())
log_cmd_error("Can't open liberty file `%s': %s\n", liberty_file.c_str(), strerror(errno));
LibertyParser libparser(f);
- fclose(f);
+ f.close();
find_cell(libparser.ast, "$_DFF_N_", false, false, false, false);
find_cell(libparser.ast, "$_DFF_P_", true, false, false, false);
diff --git a/passes/techmap/extract.cc b/passes/techmap/extract.cc
index eaa0f9fa..221e9e49 100644
--- a/passes/techmap/extract.cc
+++ b/passes/techmap/extract.cc
@@ -609,13 +609,14 @@ struct ExtractPass : public Pass {
}
else
{
- FILE *f = fopen(filename.c_str(), "rt");
- if (f == NULL) {
+ std::ifstream f;
+ f.open(filename.c_str());
+ if (f.fail()) {
delete map;
log_cmd_error("Can't open map file `%s'.\n", filename.c_str());
}
- Frontend::frontend_call(map, f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) == ".il") ? "ilang" : "verilog");
- fclose(f);
+ Frontend::frontend_call(map, &f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) == ".il") ? "ilang" : "verilog");
+ f.close();
if (filename.size() <= 3 || filename.substr(filename.size()-3) != ".il") {
Pass::call(map, "proc");
diff --git a/passes/techmap/libparse.cc b/passes/techmap/libparse.cc
index 2ff55153..612fa111 100644
--- a/passes/techmap/libparse.cc
+++ b/passes/techmap/libparse.cc
@@ -21,6 +21,10 @@
#include <stdlib.h>
#include <string.h>
+#include <istream>
+#include <fstream>
+#include <iostream>
+
#ifndef FILTERLIB
#include "kernel/log.h"
#endif
@@ -85,19 +89,19 @@ int LibertyParser::lexer(std::string &str)
int c;
do {
- c = fgetc(f);
+ c = f.get();
} while (c == ' ' || c == '\t' || c == '\r');
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.') {
str = c;
while (1) {
- c = fgetc(f);
+ c = f.get();
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.')
str += c;
else
break;
}
- ungetc(c, f);
+ f.unget();
// fprintf(stderr, "LEX: identifier >>%s<<\n", str.c_str());
return 'v';
}
@@ -105,7 +109,7 @@ int LibertyParser::lexer(std::string &str)
if (c == '"') {
str = c;
while (1) {
- c = fgetc(f);
+ c = f.get();
if (c == '\n')
line++;
str += c;
@@ -117,34 +121,34 @@ int LibertyParser::lexer(std::string &str)
}
if (c == '/') {
- c = fgetc(f);
+ c = f.get();
if (c == '*') {
int last_c = 0;
while (c > 0 && (last_c != '*' || c != '/')) {
last_c = c;
- c = fgetc(f);
+ c = f.get();
if (c == '\n')
line++;
}
return lexer(str);
} else if (c == '/') {
while (c > 0 && c != '\n')
- c = fgetc(f);
+ c = f.get();
line++;
return lexer(str);
}
- ungetc(c, f);
+ f.unget();
// fprintf(stderr, "LEX: char >>/<<\n");
return '/';
}
if (c == '\\') {
- c = fgetc(f);
+ c = f.get();
if (c == '\r')
- c = fgetc(f);
+ c = f.get();
if (c == '\n')
return lexer(str);
- ungetc(c, f);
+ f.unget();
return '\\';
}
@@ -608,16 +612,20 @@ int main(int argc, char **argv)
}
}
- FILE *f = stdin;
+ std::istream *f = &std::cin;
+
if (argc == 3) {
- f = fopen(argv[2], "r");
- if (f == NULL) {
+ std::ifstream *ff = new std::ifstream;
+ ff->open(argv[2]);
+ if (ff->fail()) {
+ delete ff;
fprintf(stderr, "Can't open liberty file `%s'.\n", argv[2]);
usage();
}
+ f = ff;
}
- LibertyParser parser(f);
+ LibertyParser parser(*f);
if (parser.ast) {
if (flag_verilogsim)
gen_verilogsim(parser.ast);
@@ -626,7 +634,7 @@ int main(int argc, char **argv)
}
if (argc == 3)
- fclose(f);
+ delete f;
return 0;
}
diff --git a/passes/techmap/libparse.h b/passes/techmap/libparse.h
index eff268bb..24748742 100644
--- a/passes/techmap/libparse.h
+++ b/passes/techmap/libparse.h
@@ -41,10 +41,10 @@ namespace PASS_DFFLIBMAP
struct LibertyParser
{
- FILE *f;
+ std::istream &f;
int line;
LibertyAst *ast;
- LibertyParser(FILE *f) : f(f), line(1), ast(parse()) {}
+ LibertyParser(std::istream &f) : f(f), line(1), ast(parse()) {}
~LibertyParser() { if (ast) delete ast; }
int lexer(std::string &str);
LibertyAst *parse();
diff --git a/passes/techmap/techmap.cc b/passes/techmap/techmap.cc
index d9d8ddd6..beacdfa6 100644
--- a/passes/techmap/techmap.cc
+++ b/passes/techmap/techmap.cc
@@ -869,9 +869,8 @@ struct TechmapPass : public Pass {
RTLIL::Design *map = new RTLIL::Design;
if (map_files.empty()) {
- FILE *f = fmemopen(stdcells_code, strlen(stdcells_code), "rt");
- Frontend::frontend_call(map, f, "<techmap.v>", verilog_frontend);
- fclose(f);
+ std::istringstream f(stdcells_code);
+ Frontend::frontend_call(map, &f, "<techmap.v>", verilog_frontend);
} else
for (auto &fn : map_files)
if (fn.substr(0, 1) == "%") {
@@ -883,11 +882,11 @@ struct TechmapPass : public Pass {
if (!map->has(mod->name))
map->add(mod->clone());
} else {
- FILE *f = fopen(fn.c_str(), "rt");
- if (f == NULL)
+ std::ifstream f;
+ f.open(fn.c_str());
+ if (f.fail())
log_cmd_error("Can't open map file `%s'\n", fn.c_str());
- Frontend::frontend_call(map, f, fn, (fn.size() > 3 && fn.substr(fn.size()-3) == ".il") ? "ilang" : verilog_frontend);
- fclose(f);
+ Frontend::frontend_call(map, &f, fn, (fn.size() > 3 && fn.substr(fn.size()-3) == ".il") ? "ilang" : verilog_frontend);
}
std::map<RTLIL::IdString, RTLIL::Module*> modules_new;