package p4spectec

  1. Overview
  2. Docs
P4-SpecTec: A mechanization toolchain for the P4 Programming Language

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.2.tar.gz
md5=1a3bc0a385fe1ecf403c019f49aa6de6
sha512=5d20b5821f33e2a3a5419b208606f27c01511994c2b3b1e1cdf4c077056dfd0aa81682af0720e1060ee2bfb0341918fcc4c53159820205a2bc32b725e5c1a714

doc/src/p4spectec.runner/make.ml.html

Source file make.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
module Value = Runtime.Value
open Runtime.Dynamic_Runner.Signature

module Make_rec
    (Interface : INTERFACE)
    (MakeExtern : functor
      (Interp_AL : INTERP_AL)
      (Interp_SL : INTERP_SL)
      (Interp_PL : INTERP_PL)
      -> EXTERN)
    (MakeInterp_AL : functor
      (Interface : INTERFACE)
      (Extern : EXTERN)
      ()
      -> INTERP_AL)
    (MakeInterp_SL : functor
      (Interface : INTERFACE)
      (Extern : EXTERN)
      ()
      -> INTERP_SL)
    (MakeInterp_PL : functor
      (Interface : INTERFACE)
      (Extern : EXTERN)
      ()
      -> INTERP_PL) : RUNNER = struct
  module Interface = Interface

  (* Recursive instantiations *)

  module rec Extern : EXTERN = struct
    include MakeExtern (Interp_AL) (Interp_SL) (Interp_PL)
  end

  and Interp_AL : INTERP_AL = struct
    include MakeInterp_AL (Interface) (Extern) ()
  end

  and Interp_SL : INTERP_SL = struct
    include MakeInterp_SL (Interface) (Extern) ()
  end

  and Interp_PL : INTERP_PL = struct
    include MakeInterp_PL (Interface) (Extern) ()
  end

  (* Shared state *)

  let mode : mode ref = ref Empty_mode
  let init_mode (mode_ : mode) : unit = mode := mode_

  (* Interpreter *)

  module Interp = struct
    let eval_program (relname : string) (includes : string list) (path : string)
        : program_result =
      match !mode with
      | AL_mode -> Interp_AL.eval_program relname includes path
      | SL_mode -> Interp_SL.eval_program relname includes path
      | PL_mode -> Interp_PL.eval_program relname includes path
      | Empty_mode -> assert false

    let eval_rel (relname : string) (values : Value.t list) : rel_result =
      match !mode with
      | AL_mode -> Interp_AL.eval_rel relname values
      | SL_mode -> Interp_SL.eval_rel relname values
      | PL_mode -> Interp_PL.eval_rel relname values
      | Empty_mode -> assert false

    let eval_func (funcname : string) (typs : Typ.t list)
        (values : Value.t list) : func_result =
      match !mode with
      | AL_mode -> Interp_AL.eval_func funcname typs values
      | SL_mode -> Interp_SL.eval_func funcname typs values
      | PL_mode -> Interp_PL.eval_func funcname typs values
      | Empty_mode -> assert false

    (* Cache management *)

    module Cache = struct
      let cache_on () =
        Interp_AL.Cache.cache_on ();
        Interp_SL.Cache.cache_on ();
        Interp_PL.Cache.cache_on ()

      let cache_off () =
        Interp_AL.Cache.cache_off ();
        Interp_SL.Cache.cache_off ();
        Interp_PL.Cache.cache_off ()
    end

    (* Clear the cache *)

    let clear () : unit =
      Interp_AL.clear ();
      Interp_SL.clear ();
      Interp_PL.clear ();
      Extern.clear ()
  end

  (* Initialization *)

  let init ?(cache = true) ?(det = false) ?(guard = false) (spec_ : spec) : unit
      =
    Interface.init spec_;
    (match spec_ with
    | AL spec_al ->
        init_mode AL_mode;
        Interp_AL.init ~cache ~det ~guard spec_al
    | SL spec_sl ->
        init_mode SL_mode;
        Interp_SL.init ~cache ~det ~guard spec_sl
    | PL spec_pl ->
        init_mode PL_mode;
        Interp_PL.init ~cache ~det ~guard spec_pl
    | Empty -> assert false);
    Extern.init_mode !mode

  (* Cache management *)

  let clear () : unit =
    Extern.clear ();
    Interp.clear ()

  module Cache = struct
    let cache_on () =
      Interp_AL.Cache.cache_on ();
      Interp_SL.Cache.cache_on ();
      Interp_PL.Cache.cache_on ()

    let cache_off () =
      Interp_AL.Cache.cache_off ();
      Interp_SL.Cache.cache_off ();
      Interp_PL.Cache.cache_off ()
  end
end

(* Variant for externs that do not depend on the interpreters.
   Because there is no Extern↔Interp circular dependency, no module rec is needed. *)

module Make_nonrec
    (Interface : INTERFACE)
    (MakeExtern : functor () -> EXTERN)
    (MakeInterp_AL : functor
      (Interface : INTERFACE)
      (Extern : EXTERN)
      ()
      -> INTERP_AL)
    (MakeInterp_SL : functor
      (Interface : INTERFACE)
      (Extern : EXTERN)
      ()
      -> INTERP_SL)
    (MakeInterp_PL : functor
      (Interface : INTERFACE)
      (Extern : EXTERN)
      ()
      -> INTERP_PL) : RUNNER = struct
  module Interface = Interface

  (* Sequential instantiations: Extern is independent of the interpreters *)

  module Extern : EXTERN = MakeExtern ()
  module Interp_AL : INTERP_AL = MakeInterp_AL (Interface) (Extern) ()
  module Interp_SL : INTERP_SL = MakeInterp_SL (Interface) (Extern) ()
  module Interp_PL : INTERP_PL = MakeInterp_PL (Interface) (Extern) ()

  (* Shared state *)

  let mode : mode ref = ref Empty_mode
  let init_mode (mode_ : mode) : unit = mode := mode_

  (* Interpreter *)

  module Interp = struct
    let eval_program (relname : string) (includes : string list) (path : string)
        : program_result =
      match !mode with
      | AL_mode -> Interp_AL.eval_program relname includes path
      | SL_mode -> Interp_SL.eval_program relname includes path
      | PL_mode -> Interp_PL.eval_program relname includes path
      | Empty_mode -> assert false

    let eval_rel (relname : string) (values : Value.t list) : rel_result =
      match !mode with
      | AL_mode -> Interp_AL.eval_rel relname values
      | SL_mode -> Interp_SL.eval_rel relname values
      | PL_mode -> Interp_PL.eval_rel relname values
      | Empty_mode -> assert false

    let eval_func (funcname : string) (typs : Typ.t list)
        (values : Value.t list) : func_result =
      match !mode with
      | AL_mode -> Interp_AL.eval_func funcname typs values
      | SL_mode -> Interp_SL.eval_func funcname typs values
      | PL_mode -> Interp_PL.eval_func funcname typs values
      | Empty_mode -> assert false

    (* Cache management *)

    module Cache = struct
      let cache_on () =
        Interp_AL.Cache.cache_on ();
        Interp_SL.Cache.cache_on ();
        Interp_PL.Cache.cache_on ()

      let cache_off () =
        Interp_AL.Cache.cache_off ();
        Interp_SL.Cache.cache_off ();
        Interp_PL.Cache.cache_off ()
    end

    (* Clear the cache *)

    let clear () : unit =
      Interp_AL.clear ();
      Interp_SL.clear ();
      Interp_PL.clear ();
      Extern.clear ()
  end

  (* Initialization *)

  let init ?(cache = true) ?(det = false) ?(guard = false) (spec_ : spec) : unit
      =
    Interface.init spec_;
    (match spec_ with
    | AL spec_al ->
        init_mode AL_mode;
        Interp_AL.init ~cache ~det ~guard spec_al
    | SL spec_sl ->
        init_mode SL_mode;
        Interp_SL.init ~cache ~det ~guard spec_sl
    | PL spec_pl ->
        init_mode PL_mode;
        Interp_PL.init ~cache ~det ~guard spec_pl
    | Empty -> assert false);
    Extern.init_mode !mode

  (* Cache management *)

  let clear () : unit =
    Extern.clear ();
    Interp.clear ()

  module Cache = struct
    let cache_on () =
      Interp_AL.Cache.cache_on ();
      Interp_SL.Cache.cache_on ();
      Interp_PL.Cache.cache_on ()

    let cache_off () =
      Interp_AL.Cache.cache_off ();
      Interp_SL.Cache.cache_off ();
      Interp_PL.Cache.cache_off ()
  end
end