Source file host.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
(**********************************************************************)
(*                                                                    *)
(*              This file is part of the RFSM package                 *)
(*                                                                    *)
(*  Copyright (c) 2018-present, Jocelyn SEROT.  All rights reserved.  *)
(*                                                                    *)
(*  This source code is licensed under the license found in the       *)
(*  LICENSE file in the root directory of this source tree.           *)
(*                                                                    *)
(**********************************************************************)

(**{1 Host language definition} *)


(** Output signature of the functor {!Host.Make} *)
module type T = sig
  module Guest: Guest.T
  module Syntax: Syntax.SYNTAX 
  module Typing: Typing.TYPING
  module Static: Static.T 
  module Dot: Dot.DOT with module Static = Static
  module Dynamic: Dynamic.DYNAMIC with module Syntax = Syntax and module Static = Static
  module Vcd: Vcd.VCD 
  module Ctask: Ctask.CTASK with module Static = Static
  module Systemc: Systemc.SYSTEMC with module Static = Static
  module Vhdl: Vhdl.VHDL with module Static = Static
  val type_program: Typing.env -> Syntax.program -> Typing.typed_program
  val type_fragment: Syntax.fragment -> unit
  val scan_fragment: Syntax.fragment -> Ident.t list * Ident.t list  (* List of rd symbols, list of wr symbols *)
  val elab: Typing.typed_program -> Syntax.program -> Static.t
  val run: ?vcd_file:string -> Syntax.program -> Static.t -> unit
  val pp_program: Format.formatter -> Syntax.program -> unit
  val pp_fragment: Format.formatter -> Syntax.fragment -> unit
  val pp_tenv: Format.formatter -> Typing.env -> unit
end

(** Functor building the host language implementation given a guest language implementation *)
module Make (G: Guest.T)
       : T with module Guest = G
            and module Syntax = Syntax.Make(G.Syntax) =
struct
    module Guest = G
    module Syntax = Syntax.Make(G.Syntax)
    module Typing = Typing.Make(Syntax)(G.Typing)(G.Static)
    module Static = Static.Make(Syntax)(Typing)(G.Value)(G.Static)
    module Dot = Dot.Make(Static)
    module Dynamic = Dynamic.Make(Syntax)(Static)(G.Eval)
    module Vcd = Vcd.Make(Dynamic.EvSeq)
    module Cmodel = Cmodel.Make(Static)
    module Ctask = Ctask.Make(Static)(G.Ctask)
    module Systemc = Systemc.Make(Static)(G.Systemc)
    module Vhdl = Vhdl.Make(Static)(G.Vhdl)

    let type_program tenv p = Typing.type_program tenv p
    let type_fragment p = Typing.type_fragment p

    let scan_fragment p = Syntax.check_fragment p

    let elab tp p = Static.build tp p

    let run ?(vcd_file="") p s =
      let rs = Dynamic.run p s in
      if vcd_file <> "" then begin
          Vcd.output ~fname:vcd_file rs;
          Printf.fprintf stdout "Wrote %s\n" vcd_file
        end

    let pp_program p = Syntax.pp_program p
    let pp_fragment p = Syntax.pp_fragment p
    let pp_tenv fmt te = Typing.pp_env fmt te
  end