From: Clifford Wolf Date: Sun, 26 Oct 2014 22:29:36 +0000 (+0100) Subject: Improvements in $readmem[bh] implementation X-Git-Tag: yosys-0.4~20 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c4a2b3c1e9be01a0b7cf7d2cc8b91aea72d7830c;p=yosys.git Improvements in $readmem[bh] implementation --- diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index f16c3d067..75a2a2364 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2039,13 +2039,19 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m if (f.fail()) log_error("Can not open file `%s` for %s at %s:%d.\n", mem_filename.c_str(), str.c_str(), filename.c_str(), linenum); - // log_assert(GetSize(memory->children) == 2 && memory->children[0]->type == AST_RANGE && memory->children[0]->range_valid); - // int wordsize_left = memory->children[0]->range_left, wordsize_right = memory->children[0]->range_right; - // int wordsize = std::max(wordsize_left, wordsize_right) - std::min(wordsize_left, wordsize_right) + 1; + log_assert(GetSize(memory->children) == 2 && memory->children[1]->type == AST_RANGE && memory->children[1]->range_valid); + int range_left = memory->children[1]->range_left, range_right = memory->children[1]->range_right; + int range_min = std::min(range_left, range_right), range_max = std::max(range_left, range_right); + + if (start_addr < 0) + start_addr = range_min; + + if (finish_addr < 0) + finish_addr = range_max; bool in_comment = false; - int increment = (start_addr < finish_addr) || (start_addr < 0) || (finish_addr < 0) ? +1 : -1; - int cursor = start_addr < 0 ? 0 : start_addr; + int increment = start_addr <= finish_addr ? +1 : -1; + int cursor = start_addr; while (!f.eof()) { @@ -2087,16 +2093,15 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m block->children.back()->children[0]->str = memory->str; block->children.back()->children[0]->id2ast = memory; - if (cursor == finish_addr) + if ((cursor == finish_addr) || (increment > 0 && cursor >= range_max) || (increment < 0 && cursor <= range_min)) break; cursor += increment; } - if (cursor == finish_addr) + if ((cursor == finish_addr) || (increment > 0 && cursor >= range_max) || (increment < 0 && cursor <= range_min)) break; } - // fixme return block; }