Source file rtl_attribute.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
open! Core0

module Value = struct
  module T = struct
    type t =
      | Int of int
      | String of string
      | Bool of bool
    [@@deriving bin_io, sexp_of, compare ~localize, equal ~localize, hash]
  end

  include T
  include Comparator.Make (T)
end

module Applies_to = struct
  module T = struct
    type t =
      | Non_wires
      | Regs
      | Memories
      | Instantiations
    [@@deriving bin_io, sexp_of, compare ~localize, equal ~localize, hash]
  end

  include T
  include Comparator.Make (T)
end

module T = struct
  type t =
    { name : string
    ; value : Value.t option
    ; applies_to : Applies_to.t list
    }
  [@@deriving bin_io, sexp_of, compare ~localize, equal ~localize, hash]
end

include T
include Comparator.Make (T)

let create ?(applies_to = []) ?value name = { name; value; applies_to }
let name t = t.name
let value t = t.value
let applies_to t = t.applies_to

module Vivado = struct
  (* see ug901 vivado synthesis guide chapter 2. *)

  let true_or_false_string : _ -> Value.t = function
    | true -> String "TRUE"
    | false -> String "FALSE"
  ;;

  let yes_or_no_string : _ -> Value.t = function
    | true -> String "yes"
    | false -> String "no"
  ;;

  let async_reg b =
    create "ASYNC_REG" ~applies_to:[ Regs ] ~value:(true_or_false_string b)
  ;;

  let user_sll_reg b =
    create "USER_SLL_REG" ~applies_to:[ Regs ] ~value:(true_or_false_string b)
  ;;

  let dont_touch b = create "dont_touch" ~value:(true_or_false_string b)

  let keep_hierarchy b =
    create "keep_hierarchy" ~applies_to:[ Instantiations ] ~value:(yes_or_no_string b)
  ;;

  let use_dsp b = create "USE_DSP" ~value:(yes_or_no_string b)

  let fsm_encoding enc =
    create
      "fsm_encoding"
      ~applies_to:[ Regs ]
      ~value:
        (String
           (match enc with
            | `one_hot -> "one_hot"
            | `sequential -> "sequential"
            | `johnson -> "johnson"
            | `gray -> "gray"
            | `auto -> "auto"
            | `none -> "none"))
  ;;

  let mark_debug b = create "mark_debug" ~value:(true_or_false_string b)
  let keep b = create "keep" ~value:(true_or_false_string b)

  let io_buffer_type typ =
    create
      "io_buffer_type"
      ~value:
        (Value.String
           (match typ with
            | `IBUF -> "IBUF"
            | `OBUF -> "OBUF"
            | `None -> "none"))
  ;;

  let max_fanout n = create "max_fanout" ~value:(Value.Int n)
  let retiming_forward n = create "retiming_forward" ~value:(Value.Int n)
  let retiming_backward n = create "retiming_backward" ~value:(Value.Int n)

  let extract_enable b =
    create "extract_enable" ~applies_to:[ Regs ] ~value:(true_or_false_string b)
  ;;

  let extract_reset b =
    create "extract_reset" ~applies_to:[ Regs ] ~value:(true_or_false_string b)
  ;;

  let critical_sig_opt b =
    create "critical_sig_opt" ~applies_to:[ Regs ] ~value:(true_or_false_string b)
  ;;

  let cascade_height x = create "CASCADE_HEIGHT" ~applies_to:[ Memories ] ~value:(Int x)

  module Ram_style = struct
    let block = create "RAM_STYLE" ~applies_to:[ Memories ] ~value:(String "block")

    let distributed =
      create "RAM_STYLE" ~applies_to:[ Memories ] ~value:(String "distributed")
    ;;

    let registers =
      create "RAM_STYLE" ~applies_to:[ Memories ] ~value:(String "registers")
    ;;

    let ultra = create "RAM_STYLE" ~applies_to:[ Memories ] ~value:(String "ultra")
  end

  module Srl_style = struct
    let register =
      create "SRL_STYLE" ~applies_to:[ Regs; Instantiations ] ~value:(String "register")
    ;;

    let srl =
      create "SRL_STYLE" ~applies_to:[ Regs; Instantiations ] ~value:(String "srl")
    ;;

    let srl_reg =
      create "SRL_STYLE" ~applies_to:[ Regs; Instantiations ] ~value:(String "srl_reg")
    ;;

    let reg_srl =
      create "SRL_STYLE" ~applies_to:[ Regs; Instantiations ] ~value:(String "reg_srl")
    ;;

    let reg_srl_reg =
      create
        "SRL_STYLE"
        ~applies_to:[ Regs; Instantiations ]
        ~value:(String "reg_srl_reg")
    ;;

    let block =
      create "SRL_STYLE" ~applies_to:[ Regs; Instantiations ] ~value:(String "block")
    ;;
  end
end