aboutsummaryrefslogtreecommitdiffstats
path: root/frontends/ast
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-26 23:29:36 +0100
committerClifford Wolf <clifford@clifford.at>2014-10-26 23:29:36 +0100
commitc4a2b3c1e9be01a0b7cf7d2cc8b91aea72d7830c (patch)
tree67ccc13aac98e1a6713b15ddee21db022106783e /frontends/ast
parent70b2efdb05f24eb7a9f3e2f456e5452fff94a15e (diff)
downloadyosys-c4a2b3c1e9be01a0b7cf7d2cc8b91aea72d7830c.tar.gz
yosys-c4a2b3c1e9be01a0b7cf7d2cc8b91aea72d7830c.tar.bz2
yosys-c4a2b3c1e9be01a0b7cf7d2cc8b91aea72d7830c.zip
Improvements in $readmem[bh] implementation
Diffstat (limited to 'frontends/ast')
-rw-r--r--frontends/ast/simplify.cc21
1 files changed, 13 insertions, 8 deletions
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;
}