Project

General

Profile

« Previous | Next » 

Revision 9d3bcc89

Added by Pierre-Loïc Garoche 3 months ago

Adapted json-parser from stateflow tool to the new signatures

View differences:

src/tools/stateflow/common/datatype.ml
39 39
  | Junction of junction_name_t * transitions_t
40 40
  | SFFunction of 'prog_t
41 41

  
42
type prog_t = Program of state_name_t * prog_t src_components_t list * (Lustre_types.var_decl * Lustre_types.expr) list
42
type prog_t = Program of state_name_t * prog_t src_components_t list * GlobalVarDef.t list
43 43

  
44 44
type scope_t = Constant | Input | Local | Output | Parameter
45 45

  
......
152 152

  
153 153
  let pp_vars fmt src =
154 154
    Format.fprintf fmt "@[<v>%a@ @]"
155
      (Utils.fprintf_list ~sep:"@ " Printers.pp_var)
155
      (Utils.fprintf_list ~sep:"@ " (fun fmt globvar -> Printers.pp_var fmt globvar.GlobalVarDef.variable))
156 156
    src
157 157

  
158 158
  let pp_prog fmt (Program (name, component_list, vars)) =
159 159
    Format.fprintf fmt "Main node name: %s@ %a@ %a@"
160 160
      name
161 161
      (pp_src pp_sffunction) component_list
162
      pp_vars (List.map fst vars)
162
      pp_vars vars
163 163

  
164 164
  let pp_scope fmt src =
165 165
    Format.fprintf fmt (match src with
src/tools/stateflow/json-parser/json_parser.ml
1 1
open Basetypes
2 2
open Corelang
3 3
open Datatype
4
open LustreSpec
4
(*open LustreSpec*)
5
open Lustre_types
5 6
open Str
6 7
open Yojson
7 8
open Basic
......
116 117
      let l = matched_group 1 s in
117 118
      let r = matched_group 2 s in
118 119
      let e = matched_group 4 s in
119
      Const_real (Num.num_of_string (l ^ r),
120
                  String.length r + (-1 * int_of_string e),
121
                  s)
120
      Const_real (Real.create (l ^ r) 
121
                    (String.length r + (-1 * int_of_string e))
122
                    s)
122 123
    else
123 124
    if string_match real_regexp_simp s 0 then
124 125
      let l = matched_group 1 s in
125 126
      let r = matched_group 2 s in
126
      Const_real (Num.num_of_string (l ^ r), String.length r, s)
127
      Const_real (Real.create (l ^ r)  (String.length r) s)
127 128
    else
128 129
      raise (JSON_parse_error ("Invalid real constant " ^ s))
129 130
  and lustre_datatype_of_json json location =
......
150 151
    Logs.debug (fun m -> m "parse_variable %s" (json |> member "name" |> to_string));
151 152
    let location                  = Location.dummy_loc in
152 153
    let (datatype, initial_value) = lustre_datatype_of_json json location in
153
    mkvar_decl location ~orig:true
154
      ( json |> member "name" |> to_string,
155
        {ty_dec_desc = datatype;  ty_dec_loc = location},
156
        {ck_dec_desc = Ckdec_any; ck_dec_loc = location},
157
        true,
158
        Some initial_value
159
      )
154
    let vdecl = 
155
      mkvar_decl location ~orig:true
156
        ( json |> member "name" |> to_string,
157
          {ty_dec_desc = datatype;  ty_dec_loc = location},
158
          {ck_dec_desc = Ckdec_any; ck_dec_loc = location},
159
          true,
160
          Some initial_value,
161
          None (* no parentid *)
162
        )
163
    in
164
    { variable = vdecl; init_val = initial_value }
160 165
end
161 166

  
src/tools/stateflow/json-parser/main_parse_json_file.ml
104 104
let json_parse _ file pp =
105 105
  try
106 106
    let prog = JParse.parse_prog (Yojson.Basic.from_file file) in
107
    if pp then
107
    if pp then (
108 108
      SF.pp_prog Format.std_formatter prog;
109

  
109
      exit 0
110
    );    
110 111
    let module Model =
111 112
	struct
112 113
	  let model = prog
......
130 131
    let module Sem = CPS.Semantics (T) (Model) in
131 132
    let prog = Sem.code_gen modularmode in
132 133
    let header = List.map Corelang.mktop [
133
      (LustreSpec.Open (false,"lustrec_math"));
134
      (LustreSpec.Open (false,"conv"));
135
      (LustreSpec.Open (true,"locallib"));
134
      (Lustre_types.Open (false,"lustrec_math"));
135
      (Lustre_types.Open (false,"conv"));
136
      (Lustre_types.Open (true,"locallib"));
136 137
    ]
137 138
    in
138 139
    let prog =header@prog in
......
144 145
    let auto_fmt = Format.formatter_of_out_channel auto_out in
145 146
    Format.fprintf auto_fmt "%a@." Printers.pp_prog prog;
146 147
    Format.eprintf "Print initial lustre model with automaton in sf_gen_test_auto.lus@.";
147
    
148
    let prog, deps = Compiler_stages.stage1 prog "" "" in
148

  
149
    let params = Backends.get_normalization_params () in
150
    let prog, deps = Compiler_stages.stage1 params prog "" "" "lus" in
149 151

  
150 152
    (* Format.printf "%a@." Printers.pp_prog prog; *)
151 153
    let noauto_file = "sf_gen_test_noauto.lus" in (* Could be changed *)

Also available in: Unified diff