Source file hierarchy.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
open! Import

module With_interface (I : Interface.S) (O : Interface.S) = struct
  module Inst = Instantiation.With_interface (I) (O)
  module Circ = Circuit.With_interface (I) (O)

  let create =
    Circuit.with_create_options
      (fun create_options
        ?port_checks
        ?add_phantom_inputs
        ?instance
        db
        ~name
        create_fn
        inputs
        ->
          let circuit =
            Circuit.call_with_create_options
              Circ.create_exn
              create_options
              ?port_checks
              ?add_phantom_inputs
              ~name
              create_fn
          in
          let name = Circuit_database.insert db circuit in
          Inst.create ?instance ~name inputs)
  ;;
end

module In_scope (I : Interface.S) (O : Interface.S) = struct
  type create = Scope.t -> Signal.t Interface.Create_fn(I)(O).t

  module Hierarchy = With_interface (I) (O)

  let create ~scope ~name create_fn inputs =
    create_fn (Scope.sub_scope scope name) inputs
  ;;

  let hierarchical =
    Circuit.with_create_options
      (fun create_options
        ?port_checks
        ?add_phantom_inputs
        ?instance
        ~(scope : Scope.t)
        ~name
        create_fn
        inputs
        ->
          let sub_scope_name =
            match instance with
            | None -> name
            | Some name -> name
          in
          if Scope.flatten_design scope
          then create ~scope ~name:sub_scope_name create_fn inputs
          else
            Circuit.call_with_create_options
              Hierarchy.create
              create_options
              ?port_checks
              ?add_phantom_inputs
              ?instance
              (Scope.circuit_database scope)
              ~name
              (create_fn (Scope.sub_scope scope sub_scope_name))
              inputs)
  ;;
end