From 7b3fe404ab30767a8b65f61fa2a6eebbe9019641 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Fri, 31 Jan 2020 18:20:22 -0300 Subject: $readmem[hb] file inclusion is now relative to the Verilog file Signed-off-by: Rodrigo Alejandro Melo --- frontends/ast/simplify.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'frontends/ast/simplify.cc') 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()) -- cgit v1.2.3 From d74b9604e332fc89bd314f6df0d909f91f0db04a Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Fri, 31 Jan 2020 22:10:51 -0300 Subject: 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(-) (limited to 'frontends/ast/simplify.cc') 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()); -- cgit v1.2.3 From b4c30cfc8d49c9028b67f7ba5710ed959f6f8f57 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Sat, 1 Feb 2020 17:03:56 -0300 Subject: 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(-) (limited to 'frontends/ast/simplify.cc') 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); -- cgit v1.2.3 From 71f3afb9a26e7bad2a9e9d59877a94cbd757cad4 Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Mon, 3 Feb 2020 10:30:33 -0300 Subject: 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(-) (limited to 'frontends/ast/simplify.cc') 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); -- cgit v1.2.3 From da485dc007b4dd9f72b8682a6809627e1f04513a Mon Sep 17 00:00:00 2001 From: Rodrigo Alejandro Melo Date: Thu, 6 Feb 2020 10:10:29 -0300 Subject: 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(-) (limited to 'frontends/ast/simplify.cc') 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 { -- cgit v1.2.3