Skip to content

Commit 441b774

Browse files
authored
Merge pull request #20 from zmr-233/pr-zmr233
Implement Register Allocation AnalysisPr zmr233
2 parents 12affe1 + b7c7292 commit 441b774

File tree

6 files changed

+960
-482
lines changed

6 files changed

+960
-482
lines changed

src/label.ml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
<https://www.moonbitlang.com/licenses/moonbit-public-source-license-v1>.
1313
*)
1414

15-
1615
module Label = struct
17-
type t = { name : string; [@ceh.ignore] stamp : int }
16+
type t =
17+
{ name : string [@ceh.ignore]
18+
; stamp : int
19+
}
1820

1921
include struct
2022
let _ = fun (_ : t) -> ()
@@ -24,33 +26,36 @@ module Label = struct
2426
let bnds__001_ = ([] : _ Stdlib.List.t) in
2527
let bnds__001_ =
2628
let arg__005_ = Moon_sexp_conv.sexp_of_int stamp__004_ in
27-
(S.List [ S.Atom "stamp"; arg__005_ ] :: bnds__001_
28-
: _ Stdlib.List.t)
29+
(S.List [ S.Atom "stamp"; arg__005_ ] :: bnds__001_ : _ Stdlib.List.t)
2930
in
3031
let bnds__001_ =
3132
let arg__003_ = Moon_sexp_conv.sexp_of_string name__002_ in
3233
(S.List [ S.Atom "name"; arg__003_ ] :: bnds__001_ : _ Stdlib.List.t)
3334
in
3435
S.List bnds__001_
35-
: t -> S.t)
36+
: t -> S.t)
37+
;;
3638

3739
let _ = sexp_of_t
3840

3941
let equal =
4042
(fun a__006_ b__007_ ->
41-
if Stdlib.( == ) a__006_ b__007_ then true
43+
if Stdlib.( == ) a__006_ b__007_
44+
then true
4245
else Stdlib.( = ) (a__006_.stamp : int) b__007_.stamp
43-
: t -> t -> bool)
46+
: t -> t -> bool)
47+
;;
4448

4549
let _ = equal
4650

4751
let (hash_fold_t : Ppx_base.state -> t -> Ppx_base.state) =
48-
fun hsv arg ->
52+
fun hsv arg ->
4953
let hsv =
5054
let hsv = hsv in
5155
hsv
5256
in
5357
Ppx_base.hash_fold_int hsv arg.stamp
58+
;;
5459

5560
let _ = hash_fold_t
5661

@@ -61,14 +66,17 @@ module Label = struct
6166
hash_fold_t hsv arg)
6267
in
6368
fun x -> func x
69+
;;
6470

6571
let _ = hash
6672

6773
let compare =
6874
(fun a__008_ b__009_ ->
69-
if Stdlib.( == ) a__008_ b__009_ then 0
75+
if Stdlib.( == ) a__008_ b__009_
76+
then 0
7077
else Stdlib.compare (a__008_.stamp : int) b__009_.stamp
71-
: t -> t -> int)
78+
: t -> t -> int)
79+
;;
7280

7381
let _ = compare
7482
end
@@ -82,14 +90,31 @@ let rename t = { name = t.name; stamp = Basic_uuid.next () }
8290

8391
let to_wasm_name (t : t) =
8492
Stdlib.String.concat "" [ "$"; t.name; "/"; Int.to_string t.stamp ]
93+
;;
8594

8695
let to_wasm_label_loop t =
8796
let x = t.stamp in
8897
("$loop:" ^ Int.to_string x : Stdlib.String.t)
98+
;;
8999

90100
let to_wasm_label_break t =
91101
let x = t.stamp in
92102
("$break:" ^ Int.to_string x : Stdlib.String.t)
103+
;;
104+
105+
(** Used for generating function label in RISCV asm. *)
106+
let to_riscv_label_func t =
107+
let fun_name = t.name in
108+
let fun_version = t.stamp in
109+
("_" ^ fun_name ^ Int.to_string fun_version : Stdlib.String.t)
110+
;;
111+
112+
(** Used for generating block label in RISCV asm. *)
113+
let to_riscv_label_block t =
114+
let bl_name = t.name in
115+
let bl_num = t.stamp in
116+
("." ^ bl_name ^ Int.to_string bl_num : Stdlib.String.t)
117+
;;
93118

94119
module Hash = Basic_hashf.Make (Label)
95120
module Hashset = Basic_hashsetf.Make (Label)

0 commit comments

Comments
 (0)