Project

General

Profile

Revision d77323b8

View differences:

src/tools/importer/main_lustre_importer.ml
44 44
                   to_list_content_str "DESIGN_UNIT" |>
45 45
                   to_list_content_str "INTERFACE_VARIABLE_DECLARATION" |>
46 46
                   flatten_ivd |>
47
                   to_list_str "ARCHITECTURE_BODY" |>
48
                   to_list_str "ARCHITECTURE_DECLARATIVE_PART" |>
49
                   to_list_str "ARCHITECTURE_STATEMENT_PART" |>
47
                   flatten_numeric_literal |>
50 48
                   to_list_str "ENTITY_DECLARATION" |>
49
                   to_list_str "ARCHITECTURE_BODY" |>
51 50
                   to_list_str "PACKAGE_DECLARATION" in
52 51
  Format.printf "Preprocessed json:\n";
53 52
  Format.printf "%s\n\n" (pretty_to_string vhdl1_json);
54
  List.iter (Format.printf "%s\n") (print_depth vhdl1_json 5 "");
53
(*  List.iter (Format.printf "%s\n") (print_depth vhdl1_json 7 ""); *)
55 54

  
56 55
  to_file (Sys.argv.(1)^".out.json") vhdl1_json;
57 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

  
58 67
  match vhdl_file_t_of_yojson vhdl1_json with
59 68
    Ok x -> Format.printf "Parsed VHDL: \n%s\n" (pretty_to_string (vhdl_file_t_to_yojson x))
60
  | Error e -> failwith e;
69
  | Error e -> Format.printf "Error: %s\n" e;
src/tools/importer/vhdl_deriving_yojson.ml
2 2

  
3 3
type vhdl_type_t =
4 4
  | Base of string
5
  | Range of string option * int * int
5
  | Range of string option * int * int [@name "RANGE_WITH_DIRECTION"]
6 6
  | Bit_vector of int * int
7 7
  | Array of int * int * vhdl_type_t
8 8
  | Enumerated of string list
9
[@@deriving yojson {strict = false}];;
9
  | Void
10
[@@deriving yojson];;
10 11
  
11 12
(************************************************************************************)		   
12 13
(*                     Constants                                                    *)
......
28 29
type cst_val_t = CstInt of int | CstStdLogic of string
29 30
[@@deriving yojson {strict = false}];;
30 31

  
32
type vhdl_subtype_indication_t =
33
  {
34
    name : string;
35
    definition: vhdl_type_t option [@default Some (Void)];
36
  }
37
[@@deriving yojson {strict = false}];;
38

  
31 39
(* TODO ? Shall we merge definition / declaration  *)
32 40
type vhdl_definition_t =
33
  | Type of {name : string ; definition: vhdl_type_t} [@name "Type"]
34
  | Subtype of {name : string ; definition: vhdl_type_t} [@name "Subtype"]
41
  | Type of {name : string ; definition: vhdl_type_t} [@name "TYPE_DECLARATION"]
42
  | Subtype of {name : string ; typ : vhdl_subtype_indication_t} [@name "SUBTYPE_DECLARATION"]
35 43
[@@deriving yojson {strict = false}];;
36 44
					
37 45
type vhdl_declaration_t =
38
  | VarDecl of { name : string; typ : vhdl_type_t; init_val : cst_val_t option } [@name "VarDecl"]
39
  | CstDecl of { name : string; typ : vhdl_type_t; init_val : cst_val_t  } [@name "CstDecl"]
40
  | SigDecl of { name : string; typ : vhdl_type_t; init_val : cst_val_t option } [@name "SigDecl"]
46
  | VarDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "VARIABLE_DECLARATION"]
47
  | CstDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t  } [@name "CONSTANT_DECLARATION"]
48
  | SigDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "SIGNAL_DECLARATION"]
41 49
[@@deriving yojson {strict = false}];;
42 50

  
43 51
(************************************************************************************)		   
......
197 205
  {
198 206
    name: string [@default ""];
199 207
    entity: string [@default ""];
200
 (*   declarations: vhdl_declaration_t list option [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default Some []];
201
    body: vhdl_concurrent_stmt_t list option [@key "ARCHITECTURE_STATEMENT_PART"] [@default Some []]; *)
208
    declarations: vhdl_declaration_t list option [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default Some []];
209
    body: vhdl_concurrent_stmt_t list option [@key "ARCHITECTURE_STATEMENT_PART"] [@default Some []]; 
202 210
  }
203 211
[@@deriving yojson {strict = false}];;
204 212
    
src/tools/importer/vhdl_json_lib.ml
163 163
    `List ((map_all (f hd) f)::(map_list map_all tl f))
164 164
  | x -> x
165 165

  
166
let numeric_literal_simpl json =
167
  match json with
168
  | `Assoc (("NUMERIC_LITERAL", `Assoc (("TOKEN", `Assoc (("text", `String(x))::[]))::[]))::[]) -> `String (x)
169
  | x -> x
170

  
171
let flatten_numeric_literal json =
172
  map_all json (numeric_literal_simpl)
173

  
166 174
let to_list_str str json =
167 175
  map_all json (assoc_elem_as_list str)
168 176

  
......
199 207
    | `List (hd::tl) ->
200 208
      List.append (print_depth hd depth indent)
201 209
                  (print_depth (`List (tl)) depth indent)
210
    | `String (s) -> (indent^s)::[]
202 211
    | _ -> []
203 212
  else
204 213
    []

Also available in: Unified diff