Project

General

Profile

« Previous | Next » 

Revision 62b6a61c

Added by Arnaud Dieumegard about 6 years ago

Functional VHDL importer

View differences:

src/tools/importer/main_lustre_importer.ml
14 14
open Vhdl_test
15 15
  *)
16 16
open Yojson.Safe
17
open Vhdl_deriving_yojson
18
open Vhdl_json_lib
17
open Vhdl_ast
19 18
open Printf
20 19

  
21 20
let _ =
22
(*
23 21
  (* 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 22
  let vhdl_json = from_file Sys.argv.(1) in
34
  Format.printf "Original file:\n%s\n\n" (pretty_to_string vhdl_json);
35 23

  
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
*)
24
  (* Create VHDL values *)
25
  let vhdl = vhdl_file_t_of_yojson vhdl_json in
66 26

  
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))
27
  match vhdl with
28
    Ok x ->
29
      Format.printf "Parsed VHDL: \n%s\n" (pretty_to_string (vhdl_file_t_to_yojson x))
69 30
  | Error e -> Format.printf "Error: %s\n" e;

Also available in: Unified diff