-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
922332f
commit 26fd7f1
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type id = int | ||
type ir_array = Ir.t BatDynArray.t | ||
|
||
type t = { | ||
id : id; | ||
contents : ir_array; | ||
} | ||
|
||
let id_gen = | ||
let id = ref 0 in | ||
fun () -> | ||
let result = !id in | ||
id := !id + 1; | ||
result | ||
|
||
let make () = { id = id_gen (); contents = BatDynArray.create () } | ||
let id_of basic_block = basic_block.id | ||
let label_of basic_block = ".L" ^ string_of_int basic_block.id | ||
let add basic_block ir = BatDynArray.add basic_block.contents ir | ||
let to_list basic_block = BatDynArray.to_list basic_block.contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(** [id] is unique identifier of the basic block. *) | ||
type id | ||
|
||
(** [t] is a basic block.. *) | ||
type t | ||
|
||
(** [make ()] is a new basic block. *) | ||
val make : unit -> t | ||
|
||
(** [id_of basic_block] is the identifier of [basic_block]. *) | ||
val id_of : t -> id | ||
|
||
(** [label_of basic_block] is the label of [basic_block] suitable for emission | ||
in an object file as a symbol. *) | ||
val label_of : t -> string | ||
|
||
(** [add basic_block ir] adds [ir] to the end of [basic_block]. *) | ||
val add : t -> Ir.t -> unit | ||
|
||
(** [to_list basic_block] are the IR operations in [basic_block] in order as a | ||
list. *) | ||
val to_list : t -> Ir.t list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Variable : sig | ||
(** The type of an IR variable. *) | ||
type t | ||
|
||
(** [to_string var] is [var] as a string. *) | ||
val to_string : t -> string | ||
end = struct | ||
open Util | ||
|
||
type t = int | ||
|
||
let to_string = string_of_int >> ( ^ ) "i" | ||
end | ||
|
||
type constant = int | ||
|
||
(* todo *) | ||
type t = | ||
| Add of Variable.t * Variable.t | ||
| IAdd of Variable.t * constant | ||
| Store of Variable.t * Variable.t | ||
| IStore of Variable.t * constant | ||
| Load of Variable.t * Variable.t | ||
| ILoad of Variable.t * constant | ||
| Param of Variable.t | ||
| IParam of constant | ||
| Jump of Basic_block.id | ||
| Call of Basic_block.id |
Empty file.
Empty file.