From 7b3fe404ab30767a8b65f61fa2a6eebbe9019641 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Fri, 31 Jan 2020 18:20:22 -0300 Subject: [PATCH 01/11] $readmem[hb] file inclusion is now relative to the Verilog file Signed-off-by: Rodrigo Alejandro Melo --- CHANGELOG | 3 ++- frontends/ast/simplify.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 481ba266e..4abfeec06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -53,12 +53,13 @@ Yosys 0.9 .. Yosys 0.9-dev - Added support for flip-flops with synchronous reset to synth_xilinx - Added support for flip-flops with reset and enable to synth_xilinx - Added "check -mapped" - - Added checking of SystemVerilog always block types (always_comb, + - Added checking of SystemVerilog always block types (always_comb, always_latch and always_ff) - Added "xilinx_dffopt" pass - Added "scratchpad" pass - Added "abc9 -dff" - Added "synth_xilinx -dff" + - Improved support of $readmem[hb] file inclusion which is now relative to the Verilog file Yosys 0.8 .. Yosys 0.9 ---------------------- diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index b94a8d710..f7364b9a8 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2886,7 +2886,8 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m int meminit_size=0; std::ifstream f; - f.open(mem_filename.c_str()); + std::string path = filename.substr(0, filename.find_last_of("\\/")+1); + f.open(path + mem_filename.c_str()); yosys_input_files.insert(mem_filename); if (f.fail()) From d74b9604e332fc89bd314f6df0d909f91f0db04a Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Fri, 31 Jan 2020 22:10:51 -0300 Subject: [PATCH 02/11] Modified the new search for files of $readmem[hb] to be backward compatible Signed-off-by: Rodrigo Alejandro Melo --- frontends/ast/simplify.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index f7364b9a8..4f105eed6 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2887,9 +2887,13 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m std::ifstream f; std::string path = filename.substr(0, filename.find_last_of("\\/")+1); - f.open(path + mem_filename.c_str()); - yosys_input_files.insert(mem_filename); - + f.open(mem_filename.c_str()); + if (f.fail()) { + f.open(path + mem_filename.c_str()); + yosys_input_files.insert(path + mem_filename); + } else { + yosys_input_files.insert(mem_filename); + } if (f.fail()) log_file_error(filename, linenum, "Can not open file `%s` for %s.\n", mem_filename.c_str(), str.c_str()); From b4c30cfc8d49c9028b67f7ba5710ed959f6f8f57 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sat, 1 Feb 2020 17:03:56 -0300 Subject: [PATCH 03/11] Fixed a bug in the new feature of $readmem[hb] when an empty string is provided Signed-off-by: Rodrigo Alejandro Melo --- frontends/ast/simplify.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 4f105eed6..310f6fc32 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2894,7 +2894,7 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m } else { yosys_input_files.insert(mem_filename); } - if (f.fail()) + if (f.fail() || strlen(mem_filename.c_str()) == 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); From 43396fae2c03b876557a73d3f3c19f4cd5161251 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sat, 1 Feb 2020 17:41:10 -0300 Subject: [PATCH 04/11] Added a test for the Memory Content File inclusion using $readmemb Signed-off-by: Rodrigo Alejandro Melo --- tests/memfile/.gitignore | 1 + tests/memfile/memory.v | 23 +++++++++++++++++++++++ tests/memfile/run-test.sh | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/memfile/.gitignore create mode 100644 tests/memfile/memory.v create mode 100755 tests/memfile/run-test.sh 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/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..3a88b81de --- /dev/null +++ b/tests/memfile/run-test.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +echo "* Creating Memory Content Files" + +for i in {1..64} +do + echo "00001111000000001111111100000000" >> tempfile1.dat +done + +mkdir -p temp +cp tempfile1.dat temp/tempfile2.dat + +cd .. + +echo "* Running from the parent directory" +echo " * Memory Content File: tempfile1.dat" +../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" +echo " * Memory Content File: temp/tempfile2.dat" +../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" + +cd memfile + +echo "* Running from the same directory" +echo " * Memory Content File: tempfile1.dat" +../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" +echo " * Memory Content File: temp/tempfile2.dat" +../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" + +cd temp + +echo "* Running from a child directory" +echo " * Memory Content File: tempfile1.dat" +../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" +echo " * Memory Content File: temp/tempfile2.dat" +../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" +echo " * Memory Content File: tempfile2.dat" +../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" + +echo "* Done" From eaaba6e09132c07b85bdae418a2b7f46b57e019e Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sat, 1 Feb 2020 22:44:06 -0300 Subject: [PATCH 05/11] Added tests/memfile to 'make test' with an extra testcase Signed-off-by: Rodrigo Alejandro Melo --- Makefile | 1 + tests/memfile/run-test.sh | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) 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/tests/memfile/run-test.sh b/tests/memfile/run-test.sh index 3a88b81de..2bbc162e7 100755 --- a/tests/memfile/run-test.sh +++ b/tests/memfile/run-test.sh @@ -1,9 +1,6 @@ #!/bin/bash -echo "* Creating Memory Content Files" - -for i in {1..64} -do +for i in {1..64}; do echo "00001111000000001111111100000000" >> tempfile1.dat done @@ -12,28 +9,25 @@ cp tempfile1.dat temp/tempfile2.dat cd .. -echo "* Running from the parent directory" -echo " * Memory Content File: tempfile1.dat" +echo "Running from the parent directory with tempfile1.dat" ../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" -echo " * Memory Content File: temp/tempfile2.dat" +echo "Running from the parent directory with temp/tempfile2.dat" ../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" +echo "Running from the parent directory with memfile/temp/tempfile2.dat" +../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"memfile/temp/tempfile2.dat\" memory; synth -top memory" cd memfile -echo "* Running from the same directory" -echo " * Memory Content File: tempfile1.dat" +echo "Running from the same directory with tempfile1.dat" ../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" -echo " * Memory Content File: temp/tempfile2.dat" +echo "Running from the same directory with temp/tempfile2.dat" ../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" cd temp -echo "* Running from a child directory" -echo " * Memory Content File: tempfile1.dat" +echo "Running from a child directory with tempfile1.dat" ../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" -echo " * Memory Content File: temp/tempfile2.dat" +echo "Running from a child directory with temp/tempfile2.dat" ../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" -echo " * Memory Content File: tempfile2.dat" +echo "Running from a child directory with tempfile2.dat" ../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" - -echo "* Done" From 2774aae0f2395e121457a666dc16bedb4c3bba06 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sat, 1 Feb 2020 22:48:03 -0300 Subject: [PATCH 06/11] Removed a line jump into the CHANGELOG Signed-off-by: Rodrigo Alejandro Melo --- CHANGELOG | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4abfeec06..a908096e3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -53,13 +53,12 @@ Yosys 0.9 .. Yosys 0.9-dev - Added support for flip-flops with synchronous reset to synth_xilinx - Added support for flip-flops with reset and enable to synth_xilinx - Added "check -mapped" - - Added checking of SystemVerilog always block types (always_comb, - always_latch and always_ff) + - Added checking of SystemVerilog always block types (always_comb, always_latch and always_ff) - Added "xilinx_dffopt" pass - Added "scratchpad" pass - Added "abc9 -dff" - Added "synth_xilinx -dff" - - Improved support of $readmem[hb] file inclusion which is now relative to the Verilog file + - Improved support of $readmem[hb] Memory Content File inclusion Yosys 0.8 .. Yosys 0.9 ---------------------- From 9b49f1bc469867500a1745fb3c427d813ce3aada Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sun, 2 Feb 2020 12:18:34 -0300 Subject: [PATCH 07/11] Added content1.dat into tests/memfile Modified run-test.sh to use it. Signed-off-by: Rodrigo Alejandro Melo --- tests/memfile/content1.dat | 64 ++++++++++++++++++++++++++++++++++++++ tests/memfile/run-test.sh | 38 ++++++++++------------ 2 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 tests/memfile/content1.dat 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/run-test.sh b/tests/memfile/run-test.sh index 2bbc162e7..1684b6314 100755 --- a/tests/memfile/run-test.sh +++ b/tests/memfile/run-test.sh @@ -1,33 +1,29 @@ #!/bin/bash -for i in {1..64}; do - echo "00001111000000001111111100000000" >> tempfile1.dat -done - mkdir -p temp -cp tempfile1.dat temp/tempfile2.dat +cp content1.dat temp/content2.dat cd .. -echo "Running from the parent directory with tempfile1.dat" -../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" -echo "Running from the parent directory with temp/tempfile2.dat" -../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" -echo "Running from the parent directory with memfile/temp/tempfile2.dat" -../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"memfile/temp/tempfile2.dat\" memory; synth -top memory" +echo "Running from the parent directory with content1.dat" +../yosys -qp "read_verilog -defer memfile/memory.v; chparam -set MEMFILE \"content1.dat\" memory; synth -top 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; synth -top 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; synth -top memory" cd memfile -echo "Running from the same directory with tempfile1.dat" -../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" -echo "Running from the same directory with temp/tempfile2.dat" -../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" +echo "Running from the same directory with content1.dat" +../../yosys -qp "read_verilog -defer memory.v; chparam -set MEMFILE \"content1.dat\" memory; synth -top 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; synth -top memory" cd temp -echo "Running from a child directory with tempfile1.dat" -../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"tempfile1.dat\" memory; synth -top memory" -echo "Running from a child directory with temp/tempfile2.dat" -../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" -echo "Running from a child directory with tempfile2.dat" -../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/tempfile2.dat\" memory; synth -top memory" +echo "Running from a child directory with content1.dat" +../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"content1.dat\" memory; synth -top 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; synth -top memory" +echo "Running from a child directory with content2.dat" +../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory; synth -top memory" From 8217f579b7450f282f1baa8d6fe1fbefc002a534 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sun, 2 Feb 2020 12:33:34 -0300 Subject: [PATCH 08/11] Removed 'synth' into tests/memfile/run-test.sh Signed-off-by: Rodrigo Alejandro Melo --- tests/memfile/run-test.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/memfile/run-test.sh b/tests/memfile/run-test.sh index 1684b6314..f25a8e0b1 100755 --- a/tests/memfile/run-test.sh +++ b/tests/memfile/run-test.sh @@ -6,24 +6,24 @@ 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; synth -top memory" +../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; synth -top memory" +../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; synth -top memory" +../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; synth -top memory" +../../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; synth -top memory" +../../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; synth -top memory" +../../../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; synth -top memory" +../../../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; synth -top memory" +../../../yosys -qp "read_verilog -defer ../memory.v; chparam -set MEMFILE \"temp/content2.dat\" memory" From 71f3afb9a26e7bad2a9e9d59877a94cbd757cad4 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Mon, 3 Feb 2020 10:30:33 -0300 Subject: [PATCH 09/11] Replaced strlen by GetSize into simplify.cc As recommended in CodingReadme. Signed-off-by: Rodrigo Alejandro Melo --- frontends/ast/simplify.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 310f6fc32..1b6618cd8 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2886,15 +2886,15 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m int meminit_size=0; std::ifstream f; - std::string path = filename.substr(0, filename.find_last_of("\\/")+1); f.open(mem_filename.c_str()); if (f.fail()) { + std::string path = filename.substr(0, filename.find_last_of("\\/")+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() || strlen(mem_filename.c_str()) == 0) + 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); From da485dc007b4dd9f72b8682a6809627e1f04513a Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Thu, 6 Feb 2020 10:10:29 -0300 Subject: [PATCH 10/11] Modified $readmem[hb] to use '\' or '/' according the OS Signed-off-by: Rodrigo Alejandro Melo --- frontends/ast/simplify.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 52f157c6e..fe0412699 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2904,7 +2904,12 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m std::ifstream f; f.open(mem_filename.c_str()); if (f.fail()) { - std::string path = filename.substr(0, filename.find_last_of("\\/")+1); +#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 { From 9da5936c0555de28fc9d254242bd2a33b3399ad6 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Thu, 6 Feb 2020 10:45:40 -0300 Subject: [PATCH 11/11] Added 'set -e' into tests/memfile/run-test.sh Also added two checks for situations where the execution must fail. Signed-off-by: Rodrigo Alejandro Melo --- tests/memfile/run-test.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/memfile/run-test.sh b/tests/memfile/run-test.sh index f25a8e0b1..e43ddd093 100755 --- a/tests/memfile/run-test.sh +++ b/tests/memfile/run-test.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + mkdir -p temp cp content1.dat temp/content2.dat @@ -27,3 +29,21 @@ 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