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.backend_sim/build.ml.html

Source file build.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
module Sim = Runtime.Sim.Signature
open Error

let gen_p4 arch =
  match arch with
  | "v1model" ->
      (module Make.Make (Interface.P4) (V1model.Pipe.Make)
                (Interp_al.Interp.Make)
                (Interp_sl.Interp.Make)
                (Interp_pl.Interp.Make) : Sim.SIM)
  | "ebpf" ->
      (module Make.Make (Interface.P4) (Ebpf.Pipe.Make) (Interp_al.Interp.Make)
                (Interp_sl.Interp.Make)
                (Interp_pl.Interp.Make) : Sim.SIM)
  | "psa" ->
      (module Make.Make (Interface.P4) (Psa.Pipe.Make) (Interp_al.Interp.Make)
                (Interp_sl.Interp.Make)
                (Interp_pl.Interp.Make) : Sim.SIM)
  | _ ->
      Format.asprintf "architecture %s is not supported" arch |> error_no_region

let gen_p4_placeholder () =
  (module Make.Make (Interface.P4) (Placeholder.Make) (Interp_al.Interp.Make)
            (Interp_sl.Interp.Make)
            (Interp_pl.Interp.Make) : Sim.SIM)

let build ?(cache = true) ?(det = false) ?(guard = false)
    ?(arch : string option) ~(final : bool) (mode : Sim.mode)
    (paths_spec : string list) =
  let spec_sim =
    match mode with
    | AL_mode ->
        let spec_al = Pass.algo paths_spec in
        (AL spec_al : Sim.spec)
    | SL_mode ->
        let spec_sl = Pass.structure ~final paths_spec in
        (SL spec_sl : Sim.spec)
    | PL_mode ->
        let spec_pl = Pass.annotate paths_spec in
        (PL spec_pl : Sim.spec)
    | Empty_mode -> assert false
  in
  let (module Simulator) =
    match arch with Some arch -> gen_p4 arch | None -> gen_p4_placeholder ()
  in
  Simulator.init ~cache ~det ~guard spec_sim;
  (spec_sim, (module Simulator : Sim.SIM))