aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-11 11:36:22 +0200
committerClifford Wolf <clifford@clifford.at>2014-10-11 11:36:22 +0200
commit8263f6a74a822579f3c1da7d8b128ea8ab7b4d79 (patch)
treedbeedfef238d40f2c882779cb6128346998dce71
parenta32e067e5c96bacc1f0280f9f1bfd979af2171db (diff)
downloadyosys-8263f6a74a822579f3c1da7d8b128ea8ab7b4d79.tar.gz
yosys-8263f6a74a822579f3c1da7d8b128ea8ab7b4d79.tar.bz2
yosys-8263f6a74a822579f3c1da7d8b128ea8ab7b4d79.zip
Fixed win32 troubles with f.readsome()
-rw-r--r--frontends/ilang/lexer.l2
-rw-r--r--frontends/verilog/lexer.l2
-rw-r--r--frontends/verilog/preproc.cc2
-rw-r--r--kernel/yosys.cc16
-rw-r--r--kernel/yosys.h1
-rw-r--r--passes/cmds/write_file.cc2
6 files changed, 21 insertions, 4 deletions
diff --git a/frontends/ilang/lexer.l b/frontends/ilang/lexer.l
index 292321e88..9669f0924 100644
--- a/frontends/ilang/lexer.l
+++ b/frontends/ilang/lexer.l
@@ -35,7 +35,7 @@
USING_YOSYS_NAMESPACE
#define YY_INPUT(buf,result,max_size) \
- result = ILANG_FRONTEND::lexin->readsome(buf, max_size);
+ result = readsome(*ILANG_FRONTEND::lexin, buf, max_size);
%}
diff --git a/frontends/verilog/lexer.l b/frontends/verilog/lexer.l
index c9302aba8..98f360885 100644
--- a/frontends/verilog/lexer.l
+++ b/frontends/verilog/lexer.l
@@ -64,7 +64,7 @@ YOSYS_NAMESPACE_END
return TOK_ID;
#define YY_INPUT(buf,result,max_size) \
- result = lexin->readsome(buf, max_size);
+ result = readsome(*lexin, buf, max_size);
%}
diff --git a/frontends/verilog/preproc.cc b/frontends/verilog/preproc.cc
index 7e14fcb84..b4e77c31b 100644
--- a/frontends/verilog/preproc.cc
+++ b/frontends/verilog/preproc.cc
@@ -202,7 +202,7 @@ static void input_file(std::istream &f, std::string filename)
auto it = input_buffer.begin();
input_buffer.insert(it, "`file_push " + filename + "\n");
- while ((rc = f.readsome(buffer, sizeof(buffer)-1)) > 0) {
+ while ((rc = readsome(f, buffer, sizeof(buffer)-1)) > 0) {
buffer[rc] = 0;
input_buffer.insert(it, buffer);
}
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index 921f2b383..a40ad4372 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -166,6 +166,22 @@ bool patmatch(const char *pattern, const char *string)
return false;
}
+int readsome(std::istream &f, char *s, int n)
+{
+ int rc = f.readsome(s, n);
+
+ // win32 sometimes returns 0 on a non-empty stream..
+ if (rc == 0) {
+ int c = f.get();
+ if (c != EOF) {
+ *s = c;
+ rc = 1;
+ }
+ }
+
+ return rc;
+}
+
int GetSize(RTLIL::Wire *wire)
{
return wire->width;
diff --git a/kernel/yosys.h b/kernel/yosys.h
index 919e3bb98..d38e60ceb 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -86,6 +86,7 @@ std::string stringf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))
std::string vstringf(const char *fmt, va_list ap);
std::string next_token(std::string &text, const char *sep);
bool patmatch(const char *pattern, const char *string);
+int readsome(std::istream &f, char *s, int n);
template<typename T> int GetSize(const T &obj) { return obj.size(); }
int GetSize(RTLIL::Wire *wire);
diff --git a/passes/cmds/write_file.cc b/passes/cmds/write_file.cc
index 9f22861a5..3f4419724 100644
--- a/passes/cmds/write_file.cc
+++ b/passes/cmds/write_file.cc
@@ -70,7 +70,7 @@ struct WriteFileFrontend : public Frontend {
char buffer[64 * 1024];
size_t bytes;
- while (0 < (bytes = f->readsome(buffer, sizeof(buffer))))
+ while (0 < (bytes = readsome(*f, buffer, sizeof(buffer))))
fwrite(buffer, bytes, 1, of);
fclose(of);