aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormyrtle <gatecat@ds0.me>2023-02-18 16:37:53 +0100
committerGitHub <noreply@github.com>2023-02-18 16:37:53 +0100
commitd20a5e9001f46262bf0cef220f1a6943946e421d (patch)
tree6ec76a7b9146145cd9117d7b6a4e244487d77d79
parent5991092f5179b9bccdb7fa8d46a0bc0245b0996f (diff)
parentdd2dce84c4e3d895671a559a7ccb8b96e01587e8 (diff)
downloadicestorm-d20a5e9001f46262bf0cef220f1a6943946e421d.tar.gz
icestorm-d20a5e9001f46262bf0cef220f1a6943946e421d.tar.bz2
icestorm-d20a5e9001f46262bf0cef220f1a6943946e421d.zip
Merge pull request #311 from YosysHQ/fix-wasm-compatHEADmaster
icebram: fix WebAssembly compatibility
-rw-r--r--icebram/icebram.cc28
1 files changed, 15 insertions, 13 deletions
diff --git a/icebram/icebram.cc b/icebram/icebram.cc
index 86ca11e..edebb9f 100644
--- a/icebram/icebram.cc
+++ b/icebram/icebram.cc
@@ -19,9 +19,9 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <limits.h>
#include <unistd.h>
#include <sys/time.h>
-#include <bits/stdc++.h>
#include <cstring>
#include <fstream>
@@ -67,7 +67,7 @@ private:
size_t m_word_size;
std::vector<bool> parse_digits(std::vector<int> &digits) const;
- void parse_line(std::string &line);
+ bool parse_line(std::string &line);
public:
HexFile(const char *filename, bool pad_words);
virtual ~HexFile() { };
@@ -87,17 +87,15 @@ HexFile::HexFile(const char *filename, bool pad_words=false)
if (!stream.is_open()) {
fprintf(stderr, "Failed to open file %s\n", filename);
- throw std::runtime_error("Unable to open input file");
+ exit(1);
}
// Parse file
std::string line;
for (int i=1; std::getline(stream, line); i++)
- try {
- this->parse_line(line);
- } catch (std::exception &e) {
+ if (!this->parse_line(line)) {
fprintf(stderr, "Can't parse line %d of %s: %s\n", i, filename, line.c_str());
- throw std::runtime_error("Invalid input file");
+ exit(1);
}
// Check word size
@@ -107,7 +105,7 @@ HexFile::HexFile(const char *filename, bool pad_words=false)
{
if ((w.size() != this->m_word_size) && !pad_words) {
fprintf(stderr, "Inconsistent word sizes in %s\n", filename);
- throw std::runtime_error("Invalid input file");
+ exit(1);
}
if (w.size() > this->m_word_size)
this->m_word_size = w.size();
@@ -129,7 +127,7 @@ HexFile::parse_digits(std::vector<int> &digits) const
return line_data;
}
-void
+bool
HexFile::parse_line(std::string &line)
{
std::vector<int> digits;
@@ -152,12 +150,14 @@ HexFile::parse_line(std::string &line)
digits.clear();
}
} else {
- throw std::runtime_error("Invalid char");
+ return false;
}
}
if (digits.size())
this->m_data.push_back(this->parse_digits(digits));
+
+ return true;
}
void
@@ -197,7 +197,7 @@ HexFile::generate_pattern(HexFile &to) const
if (pattern_from.size() == 256) {
if (pattern.count(pattern_from)) {
fprintf(stderr, "Conflicting from pattern for bit slice from_hexfile[%d:%d][%d]!\n", j, j-255, i);
- throw std::runtime_error("Non-unique source pattern");
+ exit(1);
}
pattern[pattern_from] = std::make_pair(pattern_to, 0);
pattern_from.clear(), pattern_to.clear();
@@ -283,8 +283,10 @@ EBRData::load_data()
digit = 10 + c - 'a';
else if ('A' <= c && c <= 'F')
digit = 10 + c - 'A';
- else
- throw std::runtime_error("Invalid char");
+ else {
+ fprintf(stderr, "Invalid char in BRAM data\n");
+ exit(1);
+ }
idx -= 4;