Skip to content

Commit 31cd072

Browse files
committed
Use internal name in Lem register state functions
The previous name `v` could clash with register declarations. Fixes #1335.
1 parent 5794bf1 commit 31cd072

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/lib/state.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ let regval_base_convs typ =
331331

332332
let add_regval_conv ctx env id typ defs =
333333
let typ_str = Document.to_string (doc_typ typ) in
334-
let v_exp = mk_exp (E_id (mk_id "v")) in
334+
let v_exp = mk_exp (E_id (mk_id "v#")) in
335335
let base_typ = regval_base_typ env typ in
336336
(* Create a function that converts from regval to the target type. *)
337337
let from_name, to_name = regval_base_convs typ in
@@ -343,13 +343,13 @@ let add_regval_conv ctx env id typ defs =
343343
| Some id ->
344344
let base_exp = mk_exp (E_app (mk_id from_base, [v_exp])) in
345345
let result_exp = Bitfield.construct_bitfield_struct id v_exp in
346-
let some_clause = "Some(v) => Some(" ^ string_of_exp result_exp ^ ")" in
346+
let some_clause = "Some(v#) => Some(" ^ string_of_exp result_exp ^ ")" in
347347
let clauses = " { " ^ some_clause ^ ", None() => None() }" in
348-
"function " ^ from_name ^ " v = match " ^ string_of_exp base_exp ^ clauses
348+
"function " ^ from_name ^ " v# = match " ^ string_of_exp base_exp ^ clauses
349349
| _ ->
350350
String.concat "\n"
351351
[
352-
Printf.sprintf "function %s Regval_%s(v) = Some(v)" from_name constr_name;
352+
Printf.sprintf "function %s Regval_%s(v#) = Some(v#)" from_name constr_name;
353353
Printf.sprintf "and %s _ = None()" from_name;
354354
]
355355
in
@@ -360,7 +360,7 @@ let add_regval_conv ctx env id typ defs =
360360
if is_bitfield_typ env typ then mk_exp (E_app (mk_id to_base, [Bitfield.get_bits_field v_exp]))
361361
else mk_exp (E_app (mk_id ("Regval_" ^ constr_name), [v_exp]))
362362
in
363-
let to_function = Printf.sprintf "function %s v = %s" to_name (string_of_exp to_exp) in
363+
let to_function = Printf.sprintf "function %s v# = %s" to_name (string_of_exp to_exp) in
364364
let to_defs = if is_defined defs to_name then [] else [to_val; to_function] in
365365
let cdefs = List.concat (List.map (fun s -> fst (defs_of_string __POS__ ctx s)) (from_defs @ to_defs)) in
366366
defs @ cdefs

test/typecheck/pass/issue1335.sail

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
default Order dec
2+
$include <prelude.sail>
3+
4+
register v : vector(8, bits(8)) = vector_init(0x00)
5+
6+
function main() -> unit = {
7+
print_endline(bits_str(v[7]));
8+
print_endline(dec_str(length(v)));
9+
print_endline(if v[4][4] == bitone then "one" else "zero");
10+
}

0 commit comments

Comments
 (0)