forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmmgen_state.ml
66 lines (51 loc) · 2.29 KB
/
cmmgen_state.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* Mark Shinwell, Jane Street Europe *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* Copyright 2019 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
[@@@ocaml.warning "+a-4-30-40-41-42"]
module S = Misc.Stdlib.String
type is_global = Global | Local
type constant =
| Const_closure of is_global * Clambda.ufunction list * Clambda.uconstant list
| Const_table of is_global * Cmm.data_item list
type t = {
mutable constants : constant S.Map.t;
mutable data_items : Cmm.data_item list list;
functions : Clambda.ufunction Queue.t;
}
let empty = {
constants = S.Map.empty;
data_items = [];
functions = Queue.create ();
}
let state = empty
let reset () =
state.constants <- S.Map.empty;
state.data_items <- [];
Queue.clear state.functions
let add_constant sym cst =
state.constants <- S.Map.add sym cst state.constants
let add_data_items items =
state.data_items <- items :: state.data_items
let add_function func =
Queue.add func state.functions
let constants () = state.constants
let data_items () = List.concat (List.rev state.data_items)
let next_function () =
match Queue.take state.functions with
| exception Queue.Empty -> None
| func -> Some func
let no_more_functions () =
Queue.is_empty state.functions