diff options
author | Kaj Tuomi <kaj.tuomi@siru.fi> | 2016-09-02 12:50:23 +0300 |
---|---|---|
committer | Kaj Tuomi <kaj.tuomi@siru.fi> | 2016-09-02 12:50:23 +0300 |
commit | 2343dda946e5ff335573c6b047d299bb90c98b1e (patch) | |
tree | 2851c7e2c90e50bd1cb891a88e1468faaff30cb9 /backends/smt2/smtio.py | |
parent | 279298c0b85250fd0c4e3637d10f9cf24e832259 (diff) | |
download | yosys-2343dda946e5ff335573c6b047d299bb90c98b1e.tar.gz yosys-2343dda946e5ff335573c6b047d299bb90c98b1e.tar.bz2 yosys-2343dda946e5ff335573c6b047d299bb90c98b1e.zip |
Use dict lookup instead of many ifs.
Diffstat (limited to 'backends/smt2/smtio.py')
-rw-r--r-- | backends/smt2/smtio.py | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/backends/smt2/smtio.py b/backends/smt2/smtio.py index e5c8b231c..8db283bf7 100644 --- a/backends/smt2/smtio.py +++ b/backends/smt2/smtio.py @@ -292,25 +292,14 @@ class smtio: if v.startswith("#b"): return v[2:] if v.startswith("#x"): - digits = [] - for d in v[2:]: - if d == "0": digits.append("0000") - if d == "1": digits.append("0001") - if d == "2": digits.append("0010") - if d == "3": digits.append("0011") - if d == "4": digits.append("0100") - if d == "5": digits.append("0101") - if d == "6": digits.append("0110") - if d == "7": digits.append("0111") - if d == "8": digits.append("1000") - if d == "9": digits.append("1001") - if d in ("a", "A"): digits.append("1010") - if d in ("b", "B"): digits.append("1011") - if d in ("c", "C"): digits.append("1100") - if d in ("d", "D"): digits.append("1101") - if d in ("e", "E"): digits.append("1110") - if d in ("f", "F"): digits.append("1111") - return "".join(digits) + hex_dict = { + "0":"0000", "1":"0001", "2":"0010", "3":"0011", + "4":"0100", "5":"0101", "6":"0110", "7":"0111", + "8":"1000", "9":"1001", "A":"1010", "B":"1011", + "C":"1100", "D":"1101", "E":"1110", "F":"1111", + "a":"1010", "b":"1011", "c":"1100", "d":"1101", + "e":"1110", "f":"1111"} + return "".join(hex_dict.get(x) for x in v[2:]) assert False def bv2int(self, v): |