Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / importer / vhdl_deriving_yojson.ml @ d77323b8

History | View | Annotate | Download (8.61 KB)

1 55963629 Arnaud Dieumegard
let base_types = ["integer"; "character"; "bit"; "real"; "natural"; "positive"; "std_logic"; "std_logic_vector" ]
2
3
type vhdl_type_t =
4
  | Base of string
5 d77323b8 Arnaud Dieumegard
  | Range of string option * int * int [@name "RANGE_WITH_DIRECTION"]
6 55963629 Arnaud Dieumegard
  | Bit_vector of int * int
7
  | Array of int * int * vhdl_type_t
8
  | Enumerated of string list
9 d77323b8 Arnaud Dieumegard
  | Void
10
[@@deriving yojson];;
11 55963629 Arnaud Dieumegard
  
12
(************************************************************************************)		   
13
(*                     Constants                                                    *)
14
(************************************************************************************)		   
15
16
(* Std_logic values :
17
    'U': uninitialized. This signal hasn't been set yet.
18
    'X': unknown. Impossible to determine this value/result.
19
    '0': logic 0
20
    '1': logic 1
21
    'Z': High Impedance
22
    'W': Weak signal, can't tell if it should be 0 or 1.
23
    'L': Weak signal that should probably go to 0
24
    'H': Weak signal that should probably go to 1
25
    '-': Don't care. *)			       
26
let std_logic_cst = ["U"; "X"; "0"; "1"; "Z"; "W"; "L"; "H"; "-" ]
27
28
(* TODO: do we need more constructors ? *)
29
type cst_val_t = CstInt of int | CstStdLogic of string
30
[@@deriving yojson {strict = false}];;
31
32 d77323b8 Arnaud Dieumegard
type vhdl_subtype_indication_t =
33
  {
34
    name : string;
35
    definition: vhdl_type_t option [@default Some (Void)];
36
  }
37
[@@deriving yojson {strict = false}];;
38
39 55963629 Arnaud Dieumegard
(* TODO ? Shall we merge definition / declaration  *)
40
type vhdl_definition_t =
41 d77323b8 Arnaud Dieumegard
  | Type of {name : string ; definition: vhdl_type_t} [@name "TYPE_DECLARATION"]
42
  | Subtype of {name : string ; typ : vhdl_subtype_indication_t} [@name "SUBTYPE_DECLARATION"]
43 55963629 Arnaud Dieumegard
[@@deriving yojson {strict = false}];;
44
					
45
type vhdl_declaration_t =
46 d77323b8 Arnaud Dieumegard
  | VarDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "VARIABLE_DECLARATION"]
47
  | CstDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t  } [@name "CONSTANT_DECLARATION"]
48
  | SigDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "SIGNAL_DECLARATION"]
49 55963629 Arnaud Dieumegard
[@@deriving yojson {strict = false}];;
50
51
(************************************************************************************)		   
52
(*            Attributes for types, arrays, signals and strings                     *)
53
(************************************************************************************)		   
54
55
type 'basetype vhdl_type_attributes_t =
56
  | TAttNoArg of { id: string }
57
  | TAttIntArg of { id: string; arg: int }
58
  | TAttValArg of { id: string; arg: 'basetype }
59
  | TAttStringArg of { id: string; arg: string }
60
[@@deriving yojson {strict = false}];;
61
62
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"]
63
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"]
64
let typ_att_valarg = ["image"]
65
let typ_att_stringarg = ["value"]
66
  
67
type vhdl_array_attributes_t = AAttInt of { id: string; arg: int; } | AAttAscending
68
[@@deriving yojson {strict = false}];;
69
70
let array_att_intarg = ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"]  
71
72
type vhdl_signal_attributes_t = SigAtt of string
73
[@@deriving yojson {strict = false}];;
74
75
type vhdl_string_attributes_t = StringAtt of string
76
[@@deriving yojson {strict = false}];;
77
78
(************************************************************************************)		   
79
(*                        Expressions  / Statements                                 *)
80
(************************************************************************************)		   
81
82
(* TODO: call to functions? procedures? *)  
83
type vhdl_expr_t =
84
  | Var of string (* a signal or a variable *)
85
  | Op of { id: string; args: vhdl_expr_t list } 
86
[@@deriving yojson {strict = false}];;
87
					     
88
let arith_funs = ["+";"-";"*";"/";"mod"; "rem";"abs";"**"]
89
let bool_funs  = ["and"; "or"; "nand"; "nor"; "xor"; "not"]
90
let rel_funs   = ["<";">";"<=";">=";"/=";"="]
91
92
type vhdl_sequential_stmt_t = 
93
  | VarAssign of { lhs: string; rhs: vhdl_expr_t }
94
(*  | Case of { guard: vhdl_expr_t; branches: { case: }
95
	    | Case of { guard: vhdl_expr_t; branches 
96
 *)
97
[@@deriving yojson {strict = false}];;
98
				    
99
type signal_condition_t =
100
  {                            
101
    expr: vhdl_expr_t;              (* when expression *)
102
    else_case: vhdl_expr_t option;  (* optional else case expression. 
103
                                             If None, could be a latch  *)
104
  }
105
[@@deriving yojson {strict = false}];;
106
107
type signal_selection_t =
108
  {
109
    sel_lhs: string [@default ""];
110
    expr : vhdl_expr_t;
111
    when_sel: vhdl_expr_t option;
112
  }
113
[@@deriving yojson {strict = false}];;
114
115
type conditional_signal_t =
116
  {
117
      lhs: string [@default ""];        (* assigned signal *)
118
      rhs: vhdl_expr_t;                   (* expression *)
119
      cond: signal_condition_t option     (* conditional signal statement *)
120
  }
121
[@@deriving yojson {strict = false}];;
122
123
type process_t =
124
  { 
125
    id: string option [@default None];
126
    active_sigs: string list [@default []];
127
    body: vhdl_sequential_stmt_t list [@default []]
128
  }
129
[@@deriving yojson {strict = false}];;
130
131
type selected_signal_t = 
132
  { 
133
    sel: vhdl_expr_t;  
134
    branches: signal_selection_t list [@default []];
135
  }
136
[@@deriving yojson {strict = false}];;
137
			   
138
type vhdl_concurrent_stmt_t =
139
  | SigAssign of conditional_signal_t 
140
  | Process of process_t 
141
  | SelectedSig of selected_signal_t
142
[@@deriving yojson {strict = false}];;
143
  (*
144
type vhdl_statement_t =
145
  
146
  (* | DeclarationStmt of declaration_stmt_t *)
147
  | ConcurrentStmt of vhdl_concurrent_stmt_t
148
  | SequentialStmt of vhdl_sequential_stmt_t
149
   *)
150
		     
151
(************************************************************************************)		   
152
(*                     Entities                                                     *)
153
(************************************************************************************)		   
154
			     
155
(* TODO? Seems to appear optionally in entities *)
156
type vhdl_generic_t = unit
157
[@@deriving yojson {strict = false}];;
158
			      
159
type vhdl_port_kind_t = 
160
    InPort     [@name "in"]
161
  | OutPort    [@name "out"]
162
  | InoutPort  [@name "inout"]
163
  | BufferPort [@name "buffer"]
164
[@@deriving yojson];;
165
	     
166
type vhdl_port_t =
167
  {
168
    names: string list [@default []];
169
    kind: vhdl_port_kind_t;
170
    typ : string;
171
(*    typ: vhdl_type_t; *)
172
  }
173
[@@deriving yojson {strict = false}];;
174
175
type vhdl_entity_t =
176
  {
177
    name: string [@default ""];
178
    generics: vhdl_generic_t list option [@key "GENERIC_CLAUSE"] [@default Some []];
179
    ports: vhdl_port_t list [@key "PORT_CLAUSE"] [@default []];
180
  }
181
[@@deriving yojson {strict = false}];;
182
183
(************************************************************************************)		   
184
(*                    Packages / Library loading                                    *)
185
(************************************************************************************)		   
186
				
187
(* Optional. Describes shared definitions *)
188
type vhdl_package_t =
189
  {
190
    name: string [@default ""];
191
    shared_defs: vhdl_definition_t list [@default []];
192
  }
193
[@@deriving yojson {strict = false}];;
194
195
type vhdl_load_t = 
196
    Library of string list [@name "LIBRARY_CLAUSE"] [@default ""]
197
  | Use of string list [@name "USE_CLAUSE"] [@default []]
198
[@@deriving yojson];;
199
200
(************************************************************************************)		   
201
(*                        Architecture / VHDL Design                                *)
202
(************************************************************************************)		   
203
				       
204
type vhdl_architecture_t =
205
  {
206
    name: string [@default ""];
207
    entity: string [@default ""];
208 d77323b8 Arnaud Dieumegard
    declarations: vhdl_declaration_t list option [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default Some []];
209
    body: vhdl_concurrent_stmt_t list option [@key "ARCHITECTURE_STATEMENT_PART"] [@default Some []]; 
210 55963629 Arnaud Dieumegard
  }
211
[@@deriving yojson {strict = false}];;
212
    
213
(* TODO. Configuration is optional *)
214
type vhdl_configuration_t = unit
215
[@@deriving yojson {strict = false}];;
216
217
type vhdl_design_t =
218
  {
219
    packages: vhdl_package_t list [@key "PACKAGE_DECLARATION"] [@default []];
220
    libraries: vhdl_load_t list option [@key "CONTEXT_CLAUSE"] [@default Some []];
221
    entities: vhdl_entity_t list [@key "ENTITY_DECLARATION"] [@default []];
222
    architectures: vhdl_architecture_t list [@key "ARCHITECTURE_BODY"] [@default []];
223
    configuration: vhdl_configuration_t option [@key "CONFIGURATION_DECLARATION"] [@default Some ()];
224
  }
225
[@@deriving yojson {strict = false}];;
226
227
type vhdl_design_file_t =
228
  {
229
    design_unit: vhdl_design_t list [@key "DESIGN_UNIT"] [@default []];
230
  }
231
[@@deriving yojson {strict = false}];;
232
233
type vhdl_file_t = 
234
  {
235
    design_file: vhdl_design_file_t [@key "DESIGN_FILE"];
236
  }
237
[@@deriving yojson];;