My working unpac repository
at opam/upstream/seq 153 lines 5.2 kB view raw
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 32type 'a shared = Shared of 'a | Single of 'a 33 34type ('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 40module type Stored = sig 41 type t 42 type key 43 val compare_key : key -> key -> int 44 val make_key : t -> key option 45end 46 47module type CtxStored = sig 48 include Stored 49 type context 50 val make_key : context -> t -> key option 51end 52 53module CtxStore(A:CtxStored) : 54 sig 55 val mk_store : unit -> (A.t, A.context) t_store 56 end 57 58module Store(A:Stored) : 59 sig 60 val mk_store : unit -> (A.t, unit) t_store 61 end 62 63(* Arguments to the Make functor *) 64module type S = 65 sig 66 (* type of basic tests *) 67 type primitive 68 (* basic tests themselves *) 69 val eqint : primitive 70 val neint : primitive 71 val leint : primitive 72 val ltint : primitive 73 val geint : primitive 74 val gtint : primitive 75 76 (* type of source locations *) 77 type loc 78 (* type of switch scrutinees *) 79 type arg 80 (* type of tests on scrutinees *) 81 type test 82 (* type of actions *) 83 type act 84 85 (* Various constructors, for making a binder, 86 adding one integer, etc. *) 87 88 (* [bind arg cont] should bind the expression arg to a variable, 89 then call [cont] on that variable, and return the term made of 90 the binding and the result of the call. *) 91 val bind : arg -> (arg -> act) -> act 92 (* [make_const n] generates a term for the integer constant [n] *) 93 val make_const : int -> arg 94 (* [make_offset arg n] generates a term for adding the constant 95 integer [n] to the term [arg] *) 96 val make_offset : arg -> int -> arg 97 (* [make_prim p args] generates a test using the primitive operation [p] 98 applied to arguments [args] *) 99 val make_prim : primitive -> arg list -> test 100 (* [make_isout h arg] generates a test that holds when [arg] is out of 101 the interval [0, h] *) 102 val make_isout : arg -> arg -> test 103 (* [make_isin h arg] generates a test that holds when [arg] is in 104 the interval [0, h] *) 105 val make_isin : arg -> arg -> test 106 (* [make_is_nonzero arg] generates a test that holds when [arg] is any 107 value except 0 *) 108 val make_is_nonzero : arg -> test 109 (* [arg_as_test arg] casts [arg], known to be either 0 or 1, 110 to a boolean test *) 111 val arg_as_test : arg -> test 112 (* [make_if cond ifso ifnot] generates a conditional branch *) 113 val make_if : test -> act -> act -> act 114 (* construct an actual switch : 115 make_switch arg cases acts 116 NB: cases is in the value form *) 117 val make_switch : loc -> arg -> int array -> act array -> act 118 119 (* Build last minute sharing of action stuff *) 120 val make_catch : act -> int * (act -> act) 121 val make_exit : int -> act 122 end 123 124 125(* 126 Make.zyva arg low high cases actions where 127 - arg is the argument of the switch. 128 - low, high are the interval limits. 129 - cases is a list of sub-interval and action indices 130 - actions is an array of actions. 131 132 All these arguments specify a switch construct and zyva 133 returns an action that performs the switch. 134*) 135module Make : 136 functor (Arg : S) -> 137 sig 138(* Standard entry point, sharing is tracked *) 139 val zyva : 140 Arg.loc -> 141 (int * int) -> 142 Arg.arg -> 143 (int * int * int) array -> 144 (Arg.act, _) t_store -> 145 Arg.act 146 147(* Output test sequence, sharing tracked *) 148 val test_sequence : 149 Arg.arg -> 150 (int * int * int) array -> 151 (Arg.act, _) t_store -> 152 Arg.act 153 end