aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--Makefile1
-rw-r--r--frontends/ast/simplify.cc16
-rw-r--r--tests/memfile/.gitignore1
-rw-r--r--tests/memfile/content1.dat64
-rw-r--r--tests/memfile/memory.v23
-rwxr-xr-xtests/memfile/run-test.sh49
7 files changed, 152 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index ca7196091..e0b0eb05e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -60,6 +60,7 @@ Yosys 0.9 .. Yosys 0.9-dev
- Added "scratchpad" pass
- Added "abc9 -dff"
- Added "synth_xilinx -dff"
+ - Improved support of $readmem[hb] Memory Content File inclusion
- Added "opt_lut_ins" pass
Yosys 0.8 .. Yosys 0.9
diff --git a/Makefile b/Makefile
index 43c4d0890..e9dfd9df0 100644
--- a/Makefile
+++ b/Makefile
@@ -728,6 +728,7 @@ test: $(TARGETS) $(EXTRA_TARGETS)
+cd tests/arch/anlogic && bash run-test.sh $(SEEDOPT)
+cd tests/arch/gowin && bash run-test.sh $(SEEDOPT)
+cd tests/rpc && bash run-test.sh
+ +cd tests/memfile && bash run-test.sh
@echo ""
@echo " Passed \"make test\"."
@echo ""
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index 8855d9954..fe0412699 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -2903,9 +2903,19 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m
std::ifstream f;
f.open(mem_filename.c_str());
- yosys_input_files.insert(mem_filename);
-
- if (f.fail())
+ if (f.fail()) {
+#ifdef _WIN32
+ char slash = '\\';
+#else
+ char slash = '/';
+#endif
+ std::string path = filename.substr(0, filename.find_last_of(slash)+1);
+ f.open(path + mem_filename.c_str());
+ yosys_input_files.insert(path + mem_filename);
+ } else {
+ yosys_input_files.insert(mem_filename);
+ }
+ if (f.fail() || GetSize(mem_filename) == 0)
log_file_error(filename, linenum, "Can not open file `%s` for %s.\n", mem_filename.c_str(), str.c_str());
log_assert(GetSize(memory->children) == 2 && memory->children[1]->type == AST_RANGE && memory->children[1]->range_valid);
diff --git a/tests/memfile/.gitignore b/tests/memfile/.gitignore
new file mode 100644
index 000000000..61b0d4264
--- /dev/null
+++ b/tests/memfile/.gitignore
@@ -0,0 +1 @@
+temp*
diff --git a/tests/memfile/content1.dat b/tests/memfile/content1.dat
new file mode 100644
index 000000000..4d1c67c26
--- /dev/null
+++ b/tests/memfile/content1.dat
@@ -0,0 +1,64 @@
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
+00001111000000001111111100000000
diff --git a/tests/memfile/memory.v b/tests/memfile/memory.v
new file mode 100644
index 000000000..57106eae8
--- /dev/null
+++ b/tests/memfile/memory.v
@@ -0,0 +1,23 @@
+// A memory initialized with an external file
+
+module memory (
+ input clk_i,
+ input we_i,
+ input [5:0] addr_i,
+ input [31:0] data_i,
+ output reg [31:0] data_o
+);
+
+parameter MEMFILE = "";
+
+reg [31:0] mem [0:63];
+
+initial $readmemb(MEMFILE,mem);
+
+always @(posedge clk_i) begin
+ if (we_i)
+ mem[addr_i] <= data_i;
+ data_o <= mem[addr_i];
+end
+
+endmodule
diff --git a/tests/memfile/run-test.sh b/tests/memfile/run-test.sh
new file mode 100755
index 000000000..e43ddd093
--- /dev/null
+++ b/tests/memfile/run-test.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+set -e
+
+mkdir -p temp
+cp content1.dat temp/content2.dat
+
+cd ..
+
+echo "Running from the parent directory with content1.dat"
+../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"content1.dat\" memory"
+echo "Running from the parent directory with temp/content2.dat"
+../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
+echo "Running from the parent directory with memfile/temp/content2.dat"
+../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"memfile/temp/content2.dat\" memory"
+
+cd memfile
+
+echo "Running from the same directory with content1.dat"
+../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content1.dat\" memory"
+echo "Running from the same directory with temp/content2.dat"
+../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
+
+cd temp
+
+echo "Running from a child directory with content1.dat"
+../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"content1.dat\" memory"
+echo "Running from a child directory with temp/content2.dat"
+../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
+echo "Running from a child directory with content2.dat"
+../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory"
+
+cd ..
+
+echo "Checking a failure when zero length filename is provided"
+if ../../yosys -qp "read_verilog memory.v"; then
+ echo "The execution should fail but it didn't happen, which is WRONG."
+ exit 1
+else
+ echo "Execution failed, which is OK."
+fi
+
+echo "Checking a failure when not existing filename is provided"
+if ../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content3.dat\" memory"; then
+ echo "The execution should fail but it didn't happen, which is WRONG."
+ exit 1
+else
+ echo "Execution failed, which is OK."
+fi