diff options
author | Clifford Wolf <clifford@clifford.at> | 2016-10-22 10:17:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-22 10:17:49 +0200 |
commit | 9b722cd06294deb62703df2d560d347bc46b1a41 (patch) | |
tree | 851f5564da459d9f92c3fd63ed03eb7bb8a89daf | |
parent | 3b6e7368f52507d8aa2e2d1ece37f569884d62b4 (diff) | |
parent | e046ad3a4f634ef58a84d803c0b4de71cfbe9f2a (diff) | |
download | icestorm-9b722cd06294deb62703df2d560d347bc46b1a41.tar.gz icestorm-9b722cd06294deb62703df2d560d347bc46b1a41.tar.bz2 icestorm-9b722cd06294deb62703df2d560d347bc46b1a41.zip |
Merge pull request #59 from zeldin/icebram_parser
Improve input parsing of icebram
-rw-r--r-- | icebram/icebram.cc | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/icebram/icebram.cc b/icebram/icebram.cc index fbb237b..245a0ab 100644 --- a/icebram/icebram.cc +++ b/icebram/icebram.cc @@ -43,6 +43,18 @@ uint64_t xorshift64star(void) { return x * UINT64_C(2685821657736338717); } +void push_back_bitvector(vector<vector<bool>> &hexfile, const vector<int> &digits) +{ + if (digits.empty()) + return; + + hexfile.push_back(vector<bool>(digits.size() * 4)); + + for (int i = 0; i < int(digits.size()) * 4; i++) + if ((digits.at(digits.size() - i/4 -1) & (1 << (i%4))) != 0) + hexfile.back().at(i) = true; +} + void parse_hexfile_line(const char *filename, int linenr, vector<vector<bool>> &hexfile, string &line) { vector<int> digits; @@ -54,14 +66,18 @@ void parse_hexfile_line(const char *filename, int linenr, vector<vector<bool>> & digits.push_back(10 + c - 'a'); else if ('A' <= c && c <= 'F') digits.push_back(10 + c - 'A'); - else goto error; + else if ('x' == c || 'X' == c || + 'z' == c || 'Z' == c) + digits.push_back(0); + else if ('_' == c) + ; + else if (' ' == c || '\t' == c || '\r' == c) { + push_back_bitvector(hexfile, digits); + digits.clear(); + } else goto error; } - hexfile.push_back(vector<bool>(digits.size() * 4)); - - for (int i = 0; i < int(digits.size()) * 4; i++) - if ((digits.at(digits.size() - i/4 -1) & (1 << (i%4))) != 0) - hexfile.back().at(i) = true; + push_back_bitvector(hexfile, digits); return; @@ -181,6 +197,15 @@ int main(int argc, char **argv) for (int i = 1; getline(to_hexfile_f, line); i++) parse_hexfile_line(to_hexfile_n, i, to_hexfile, line); + if (to_hexfile.size() > 0 && from_hexfile.size() > to_hexfile.size()) { + if (verbose) + fprintf(stderr, "Padding to_hexfile from %d words to %d\n", + int(to_hexfile.size()), int(from_hexfile.size())); + do + to_hexfile.push_back(vector<bool>(to_hexfile.at(0).size())); + while (from_hexfile.size() > to_hexfile.size()); + } + if (from_hexfile.size() != to_hexfile.size()) { fprintf(stderr, "Hexfiles have different number of words! (%d vs. %d)\n", int(from_hexfile.size()), int(to_hexfile.size())); exit(1); |