Project

General

Profile

Download (2.42 KB) Statistics
| Branch: | Tag: | Revision:
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 Lustrec
17
open Yojson.Safe
18
open Vhdl_deriving_yojson
19
open Vhdl_json_lib
20
open Printf
21

    
22
let _ =
23
(*
24
  (* Load model with Yojson *)
25
  let json = xx in
26

    
27
  (* Create VHDL values *)
28
  let vhdl : vhdl_design_t = xxxx json in
29

    
30
  (* Printing result *)
31
  Format.printf "Loaded VHDL:@.%a@." pp_vhdl_design vhdl
32
 *)
33

    
34
  let vhdl_json = from_file Sys.argv.(1) in
35
  Format.printf "Original file:\n%s\n\n" (pretty_to_string vhdl_json);
36

    
37
  (*let vhdl = design1 in
38
  Format.printf "Loaded VHDL:@.%a@." pp_vhdl_design vhdl;*)
39

    
40
  let vhdl1_json = vhdl_json |> 
41
                   prune_str "TOKEN" |>
42
                   prune_str "IDENTIFIER" |>
43
                   prune_str "SUBTYPE_INDICATION" |>
44
                   prune_null_assoc |>
45
                   to_list_content_str "DESIGN_UNIT" |>
46
                   to_list_content_str "INTERFACE_VARIABLE_DECLARATION" |>
47
                   flatten_ivd |>
48
                   flatten_numeric_literal |>
49
                   to_list_str "ENTITY_DECLARATION" |>
50
                   to_list_str "ARCHITECTURE_BODY" |>
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 7 ""); *)
55

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

    
58
(*
59
  let typ = {name = "type"; definition = (Some (Range (Some "toto", 7, 0)))} in
60
  Format.printf "\nModel to string\n%s\n\n" (pretty_to_string (vhdl_subtype_indication_t_to_yojson typ));
61

    
62
  let elem = "[\"SUBTYPE_DECLARATION\", {\"name\": \"byte\", \"typ\": { \"name\": \"bit_vector\", \"definition\": [ \"RANGE_WITH_DIRECTION\", \"downto\", 7, 0 ]}}]" in
63
  match vhdl_definition_t_of_yojson (from_string elem) with
64
    Ok x -> Format.printf "\nString to string\n%s\n\n" (pretty_to_string (vhdl_definition_t_to_yojson x));
65
  | Error e -> Format.printf "Error: %s\n" e;
66
*)
67

    
68
  match vhdl_file_t_of_yojson vhdl1_json with
69
    Ok x -> Format.printf "Parsed VHDL: \n%s\n" (pretty_to_string (vhdl_file_t_to_yojson x))
70
  | Error e -> Format.printf "Error: %s\n" e;
(2-2/2)