1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Luc Maranget, projet Moscova, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 2000 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (*
17 This module transforms generic switches in combinations
18 of if tests and switches.
19 *)
20
21 (* For detecting action sharing, object style *)
22
23 (* Store for actions in object style:
24 act_store : store an action, returns index in table
25 In case an action with equal key exists, returns index
26 of the stored action. Otherwise add entry in table.
27 act_store_shared : This stored action will always be shared.
28 act_get : retrieve table
29 act_get_shared : retrieve table, with sharing explicit
30 *)
31
32 type 'a shared = Shared of 'a | Single of 'a
33
34 type ('a, 'ctx) t_store =
35 {act_get : unit -> 'a array ;
36 act_get_shared : unit -> 'a shared array ;
37 act_store : 'ctx -> 'a -> int ;
38 act_store_shared : 'ctx -> 'a -> int ; }
39
40 exception Not_simple
41
42 module type Stored = sig
43 type t
44 type key
45 val compare_key : key -> key -> int
46 val make_key : t -> key option
47 end
48
49 module type CtxStored = sig
50 include Stored
51 type context
52 val make_key : context -> t -> key option
53 end
54
55 module CtxStore(A:CtxStored) :
56 sig
57 val mk_store : unit -> (A.t, A.context) t_store
58 end
59
60 module Store(A:Stored) :
61 sig
62 val mk_store : unit -> (A.t, unit) t_store
63 end
64
65 (* Arguments to the Make functor *)
66 module type S =
67 sig
68 (* type of basic tests *)
69 type primitive
70 (* basic tests themselves *)
71 val eqint : primitive
72 val neint : primitive
73 val leint : primitive
74 val ltint : primitive
75 val geint : primitive
76 val gtint : primitive
77 (* type of actions *)
78 type act
79
80 (* Various constructors, for making a binder,
81 adding one integer, etc. *)
82 val bind : act -> (act -> act) -> act
83 val make_const : int -> act
84 val make_offset : act -> int -> act
85 val make_prim : primitive -> act list -> act
86 val make_isout : act -> act -> act
87 val make_isin : act -> act -> act
88 val make_if : act -> act -> act -> act
89 (* construct an actual switch :
90 make_switch arg cases acts
91 NB: cases is in the value form *)
92 val make_switch :
93 Location.t -> act -> int array -> act array -> act
94 (* Build last minute sharing of action stuff *)
95 val make_catch : act -> int * (act -> act)
96 val make_exit : int -> act
97
98 end
99
100
101 (*
102 Make.zyva arg low high cases actions where
103 - arg is the argument of the switch.
104 - low, high are the interval limits.
105 - cases is a list of sub-interval and action indices
106 - actions is an array of actions.
107
108 All these arguments specify a switch construct and zyva
109 returns an action that performs the switch.
110 *)
111 module Make :
112 functor (Arg : S) ->
113 sig
114 (* Standard entry point, sharing is tracked *)
115 val zyva :
116 Location.t ->
117 (int * int) ->
118 Arg.act ->
119 (int * int * int) array ->
120 (Arg.act, _) t_store ->
121 Arg.act
122
123 (* Output test sequence, sharing tracked *)
124 val test_sequence :
125 Arg.act ->
126 (int * int * int) array ->
127 (Arg.act, _) t_store ->
128 Arg.act
129 end
130