Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug of issue #871 #907

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
([PR #890](https://github.com/jasmin-lang/jasmin/pull/890);
fixes [#662](https://github.com/jasmin-lang/jasmin/issues/662)).

- Adding label to global variables in assembly generation to avoid name conflicts
([PR #907](https://github.com/jasmin-lang/jasmin/pull/907);
fixes [#871](https://github.com/jasmin-lang/jasmin/issues/871)).

## Other changes

- The deprecated legacy interface to the LATEX pretty-printer has been removed
Expand Down
13 changes: 10 additions & 3 deletions compiler/src/printASM.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ let print_asm_lines fmt lns =
let string_of_label name p =
Format.asprintf "L%s$%d" (escape name) (Conv.int_of_pos p)

let string_of_glob x =
Format.asprintf "G$%s" (escape x.v_name)
let string_of_glob occurrences x =
Hash.modify_def (-1) x.v_name Stdlib.Int.succ occurrences;
let count = Hash.find occurrences x.v_name in
(* Adding the number of occurrences to the label to avoid names conflict *)
let suffix = if count > 0 then Format.asprintf "$%d" count else "" in
Format.asprintf "G$%s%s" (escape x.v_name) suffix


(* -------------------------------------------------------------------- *)
let format_glob_data globs names =
(* Creating a Hashtable to count occurrences of a label name*)
let occurrences = Hash.create 42 in
let names =
List.map (fun ((x, _), p) -> (Conv.var_of_cvar x, Conv.z_of_cz p)) names
in
Expand All @@ -39,5 +46,5 @@ let format_glob_data globs names =
let b = LByte (Z.to_string (Conv.z_of_int8 b)) in
match List.find (fun (_, p) -> Z.equal (Z.of_int i) p) names with
| exception Not_found -> [ b ]
| x, _ -> [ LLabel (string_of_glob x); b ])
| x, _ -> [ LLabel (string_of_glob occurrences x); b ])
globs)
16 changes: 16 additions & 0 deletions compiler/tests/success/common/bug_871.jazz
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
inline fn get(inline u32 i) -> reg u32 {
reg u32 r;
global u32 g;
g = i;
r = g;
return r;
}

export
fn main() -> reg u32 {
reg u32 a b;
a = get(0xa);
b = get(0xb);
b += a;
return b;
}