Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / importer / main_lustre_importer.ml @ 55963629

History | View | Annotate | Download (1.9 KB)

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
                   to_list_str "ARCHITECTURE_BODY" |>
48
                   to_list_str "ARCHITECTURE_DECLARATIVE_PART" |>
49
                   to_list_str "ARCHITECTURE_STATEMENT_PART" |>
50
                   to_list_str "ENTITY_DECLARATION" |>
51
                   to_list_str "PACKAGE_DECLARATION" in
52
  Format.printf "Preprocessed json:\n";
53
  Format.printf "%s\n\n" (pretty_to_string vhdl1_json);
54
  List.iter (Format.printf "%s\n") (print_depth vhdl1_json 5 "");
55

    
56
  to_file (Sys.argv.(1)^".out.json") vhdl1_json;
57

    
58
  match vhdl_file_t_of_yojson vhdl1_json with
59
    Ok x -> Format.printf "Parsed VHDL: \n%s\n" (pretty_to_string (vhdl_file_t_to_yojson x))
60
  | Error e -> failwith e;