1
|
open Vhdl_ast
|
2
|
open Mini_vhdl_ast
|
3
|
|
4
|
let mini_vhdl_declaration_t_names decl=
|
5
|
match decl with
|
6
|
| SigDecl { names; typ; init_val } -> names
|
7
|
| _ -> []
|
8
|
|
9
|
let rec get_ports: vhdl_port_t list -> vhdl_port_mode_t -> vhdl_port_t list=
|
10
|
fun l -> fun m -> match l with
|
11
|
| [] -> []
|
12
|
| hd::tl -> if hd.mode = m then hd::(get_ports tl m) else get_ports tl m
|
13
|
|
14
|
let get_names : vhdl_port_t -> vhdl_name_t list= fun x -> x.names
|
15
|
|
16
|
let rec duplicates l1=
|
17
|
match l1 with
|
18
|
| [] -> []
|
19
|
| hd::tl -> if List.mem hd tl then hd::(duplicates (List.filter (fun x -> List.mem x tl) tl)) else duplicates tl
|
20
|
|
21
|
let equals n1 n2=
|
22
|
match (n1,n2) with
|
23
|
| (Simple a, Identifier b) -> a = b
|
24
|
| (Identifier a, Simple b) -> a = b
|
25
|
| (Simple a, Selected ((Simple b)::[])) -> a = b
|
26
|
| (Simple a, Selected ((Identifier b)::[])) -> a = b
|
27
|
| (Identifier a, Selected ((Simple b)::[])) -> a = b
|
28
|
| (Identifier a, Selected ((Identifier b)::[])) -> a = b
|
29
|
| (Selected ((Simple b)::[]), Simple a) -> a = b
|
30
|
| (Selected ((Identifier b)::[]), Simple a) -> a = b
|
31
|
| (Selected ((Simple b)::[]), Identifier a) -> a = b
|
32
|
| (Selected ((Identifier b)::[]), Identifier a) -> a = b
|
33
|
| (a,b) -> a = b
|
34
|
|
35
|
let find_vhdl_name_t l x =
|
36
|
let rec find_vhdl_name_t_aux x l index =
|
37
|
match l with
|
38
|
| [] -> -1
|
39
|
| hd::tl -> if (equals x hd) then index else find_vhdl_name_t_aux x tl (index+1) in
|
40
|
find_vhdl_name_t_aux x l 0
|
41
|
|
42
|
let rec vhdl_name_t_mem x l =
|
43
|
match l with
|
44
|
| [] -> false
|
45
|
| hd::tl -> equals x hd || vhdl_name_t_mem x tl
|
46
|
|
47
|
let rec diff l1 l2 to_string_name =
|
48
|
match l1 with
|
49
|
| [] -> []
|
50
|
| hd::tl ->
|
51
|
if vhdl_name_t_mem hd l2 then diff tl l2 to_string_name else hd::(diff tl l2 to_string_name)
|
52
|
|