1
|
(* An application that loads json provided input and produces Lustre
|
2
|
|
3
|
Usage:
|
4
|
lustrei -vhdl myvhdl.json
|
5
|
lustrei -scade myscademodel.json
|
6
|
will produce a lustre file that can be compiled and analyzed
|
7
|
|
8
|
VHDL is handled in a double way: as a backend and as an import language
|
9
|
In a first step, lustrei -vhdl -print myvhdl.json shall print the VHDL model in stdout
|
10
|
|
11
|
*)
|
12
|
(*
|
13
|
open Vhdl_ast
|
14
|
open Vhdl_test
|
15
|
*)
|
16
|
open Yojson.Safe
|
17
|
open Vhdl_deriving_yojson
|
18
|
open Vhdl_json_lib
|
19
|
open Printf
|
20
|
|
21
|
let _ =
|
22
|
(*
|
23
|
(* Load model with Yojson *)
|
24
|
let json = xx in
|
25
|
|
26
|
(* Create VHDL values *)
|
27
|
let vhdl : vhdl_design_t = xxxx json in
|
28
|
|
29
|
(* Printing result *)
|
30
|
Format.printf "Loaded VHDL:@.%a@." pp_vhdl_design vhdl
|
31
|
*)
|
32
|
|
33
|
let vhdl_json = from_file Sys.argv.(1) in
|
34
|
Format.printf "Original file:\n%s\n\n" (pretty_to_string vhdl_json);
|
35
|
|
36
|
(*let vhdl = design1 in
|
37
|
Format.printf "Loaded VHDL:@.%a@." pp_vhdl_design vhdl;*)
|
38
|
|
39
|
let vhdl1_json = vhdl_json |>
|
40
|
prune_str "TOKEN" |>
|
41
|
prune_str "IDENTIFIER" |>
|
42
|
prune_str "SUBTYPE_INDICATION" |>
|
43
|
prune_null_assoc |>
|
44
|
to_list_content_str "DESIGN_UNIT" |>
|
45
|
to_list_content_str "INTERFACE_VARIABLE_DECLARATION" |>
|
46
|
flatten_ivd |>
|
47
|
flatten_numeric_literal |>
|
48
|
to_list_str "ENTITY_DECLARATION" |>
|
49
|
to_list_str "ARCHITECTURE_BODY" |>
|
50
|
to_list_str "PACKAGE_DECLARATION" in
|
51
|
Format.printf "Preprocessed json:\n";
|
52
|
Format.printf "%s\n\n" (pretty_to_string vhdl1_json);
|
53
|
(* List.iter (Format.printf "%s\n") (print_depth vhdl1_json 7 ""); *)
|
54
|
|
55
|
to_file (Sys.argv.(1)^".out.json") vhdl1_json;
|
56
|
|
57
|
(*
|
58
|
let typ = {name = "type"; definition = (Some (Range (Some "toto", 7, 0)))} in
|
59
|
Format.printf "\nModel to string\n%s\n\n" (pretty_to_string (vhdl_subtype_indication_t_to_yojson typ));
|
60
|
|
61
|
let elem = "[\"SUBTYPE_DECLARATION\", {\"name\": \"byte\", \"typ\": { \"name\": \"bit_vector\", \"definition\": [ \"RANGE_WITH_DIRECTION\", \"downto\", 7, 0 ]}}]" in
|
62
|
match vhdl_definition_t_of_yojson (from_string elem) with
|
63
|
Ok x -> Format.printf "\nString to string\n%s\n\n" (pretty_to_string (vhdl_definition_t_to_yojson x));
|
64
|
| Error e -> Format.printf "Error: %s\n" e;
|
65
|
*)
|
66
|
|
67
|
match vhdl_file_t_of_yojson vhdl1_json with
|
68
|
Ok x -> Format.printf "Parsed VHDL: \n%s\n" (pretty_to_string (vhdl_file_t_to_yojson x))
|
69
|
| Error e -> Format.printf "Error: %s\n" e;
|