## lustrec / src / backends / VHDL / mini_vhdl_utils.ml @ 40ac0ede

History | View | Annotate | Download (2.09 KB)

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 = |

48 |
match l1 with |

49 |
| [] -> [] |

50 |
| hd::tl -> |

51 |
if vhdl_name_t_mem hd l2 then diff tl l2 else hd::(diff tl l2) |

52 | |

53 |
let n_intersection ll = |

54 |
let rec n_intersection_aux e_inter l = |

55 |
match e_inter with |

56 |
| [] -> l |

57 |
| hd::tl -> if (vhdl_name_t_mem hd l) then hd::(n_intersection_aux tl l) else n_intersection_aux tl l |

58 |
in |

59 |
List.fold_left n_intersection_aux [] ll |

60 | |

61 |
let rec times : 'a list list -> 'a list list -> 'a list list= |

62 |
fun a -> |

63 |
fun b -> |

64 |
match a with |

65 |
| [] -> b |

66 |
| hda::tla -> match b with |

67 |
| [] -> a |

68 |
| hdb::tlb -> [hdb@hda]@(times tla tlb) |