aboutsummaryrefslogtreecommitdiff
path: root/model/riscv_csr_map.sail
diff options
context:
space:
mode:
authorAlasdair <alasdair.armstrong@gmail.com>2019-06-28 03:45:36 +0100
committerAlasdair <alasdair.armstrong@gmail.com>2019-06-28 03:45:36 +0100
commit2258d7d974a560a7bc385446d619047c542c6db1 (patch)
tree5a0af4b52a7e01713846f0477bc4c3f1df4442dc /model/riscv_csr_map.sail
parent83c3ec61ffb62d618cdf5c1682bb605c4887584b (diff)
downloadsail-riscv-2258d7d974a560a7bc385446d619047c542c6db1.zip
sail-riscv-2258d7d974a560a7bc385446d619047c542c6db1.tar.gz
sail-riscv-2258d7d974a560a7bc385446d619047c542c6db1.tar.bz2
Avoid implicit casts to string
Can have unintended consequences, due to how overloading interacts with casts. For example, x : X == y : X can be interpreted as eq_string(cast(x), cast(y)) if x and y are both castable to string, even when there is an equality function (X, X) -> bool. Sail->SMT can't handle strings very well so it's best to just ensure that this can never occur. Rather than implicitly casting in logging statements like: print("xyz" ^ x ^ " foo " ^ y) it's now print("xyz" ^ to_str(x) ^ " foo " ^ to_str(y)) which ensures that the conversion to strings only happens where intended. I also added a warning to Sail itself to try to catch these cases in future.
Diffstat (limited to 'model/riscv_csr_map.sail')
-rw-r--r--model/riscv_csr_map.sail4
1 files changed, 3 insertions, 1 deletions
diff --git a/model/riscv_csr_map.sail b/model/riscv_csr_map.sail
index f484d8d..09b89ad 100644
--- a/model/riscv_csr_map.sail
+++ b/model/riscv_csr_map.sail
@@ -1,6 +1,6 @@
/* Mapping of csr addresses to their names. */
-val cast csr_name : csreg -> string
+val csr_name : csreg -> string
function csr_name(csr) = {
match (csr) {
/* user trap setup */
@@ -76,6 +76,8 @@ function csr_name(csr) = {
}
}
+overload to_str = {csr_name}
+
mapping csr_name_map : csreg <-> string = {
/* user trap setup */
0x000 <-> "ustatus",