Project

General

Profile

« Previous | Next » 

Revision 57ecad58

Added by Christophe Garion almost 6 years ago

parser-json: clean main program + add pp for vars

View differences:

src/tools/stateflow/common/datatype.ml
150 150
      name
151 151
      (pp_src pp_sffunction) component_list
152 152

  
153
  let pp_prog fmt (Program (name, component_list, _)) =
154
    Format.fprintf fmt "Main node name: %s@ %a@ "
153
  let pp_vars fmt src =
154
    Format.fprintf fmt "@[<v>%a@ @]"
155
      (Utils.fprintf_list ~sep:"@ " Printers.pp_var)
156
    src
157

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

  
158 164
  let pp_scope fmt src =
159 165
    Format.fprintf fmt (match src with
......
162 168
        | Local     -> "Local"
163 169
        | Output    -> "Output"
164 170
        | Parameter -> "Parameter")
165

  
166
  let pp_vars fmt src =
167
    Format.fprintf fmt "@[<v>%a@ @]"
168
      (Utils.fprintf_list ~sep:"@ "
169
         (fun fmt src -> match src with
170
	    | (name, scope, Bool b) -> Format.fprintf fmt "%s: %a %s := %s"
171
                                  name
172
                                  pp_scope scope
173
                                  "Bool" (string_of_bool b)
174
	    | (name, scope, Real f) -> Format.fprintf fmt "%s: %a %s := %s"
175
                                  name
176
                                  pp_scope scope
177
                                  "Real" (string_of_float f)
178
	    | (name, scope, Int i)  -> Format.fprintf fmt "%s: %a %s := %s"
179
                                  name
180
                                  pp_scope scope
181
                                  "Int" (string_of_int i)
182
         ))
183
    src
184 171
end
src/tools/stateflow/main_with_json.ml
1
open Env
2 1
open Basetypes
3 2
open Datatype
4
(* open Interpreter *)
5 3
open Parser_json
6
(* open Transformer *)
7
open Theta
8
open CPS_ccode_generator
9
open CPS_interpreter
10
open CPS_transformer
4
open Sys
11 5

  
12 6
module ParseExt =
13 7
struct
......
18 12

  
19 13
module Parse = Parser (ParseExt)
20 14

  
21
module Prog =
22
struct
23
  let json                       = Yojson.Basic.from_file "GPCA_Alarm_Alarm_SFIR_pp.json"
24
  let Program (init, defs, vars) = Parse.parse_prog json
25
  let prog                       = Parse.parse_prog json
26
  (* let user_vars                  = Parse.parse_variables json *)
27
  (*let _ = Format.printf "Model definitions@.%a@.####" Simulink.pp_src defs; ()*)
28
end
29

  
30
module Transformer =
31
  (* CPS_ccode_generator.LustrePrinter (Program) *)
32
  CodeGenerator
33
  (* CPS_ccode_generator.Evaluator *)
34

  
35
module Interp = Interpreter (Transformer)
36

  
37
module KenvTheta = KenvTheta (Transformer)
38

  
39
module Modularity : KenvTheta.ModularType =
40
struct
41
  let modular : type b. (path_t, b, bool) tag_t -> path_t -> b =
42
    fun tag ->
43
    match tag with
44
    | E -> (fun p p' f -> true)
45
    | D -> (fun p      -> true)
46
    | X -> (fun p f    -> true)
47
end
48

  
49
module Tables = KenvTheta.MemoThetaTables ()
50

  
51
module Thetaify = KenvTheta.ModularThetaify (Tables) (Modularity)
52

  
53
module EvalProg = Interp.Evaluation (Thetaify) (Prog)
54

  
55 15
let main ()  =
56 16
  begin
57
    SF.pp_prog Format.std_formatter (Parse.parse_prog Prog.json);
58
    (* SF.pp_vars Format.std_formatter (Parse.parse_variables Prog.json); *)
17
    let json = Yojson.Basic.from_file Sys.argv.(1) in
18
    SF.pp_prog Format.std_formatter (Parse.parse_prog json);
59 19
  end
60 20

  
61 21
let _ = main ()
src/tools/stateflow/parser-json/parser_json.ml
12 12
module type ParseExt =
13 13
sig
14 14
  val parse_condition : json -> Condition.t
15
  val parse_action : json -> Action.t
16
  val parse_event : json -> Basetypes.event_t
15
  val parse_action    : json -> Action.t
16
  val parse_event     : json -> Basetypes.event_t
17 17
end
18 18

  
19 19
module Parser (Ext : ParseExt) =
......
40 40
        (fun res -> SFFunction (parse_prog res))),
41 41
      json |> member "data"        |> to_list |> List.map parse_variable
42 42
    )
43
  (* and parse_variables json = *)
44
  (*    (\*Format.printf "parse_variables@.";*\) *)
45 43
  (*   json |> member "data"       |> to_list |> List.map parse_variable *)
46 44
  and parse_state json =
47 45
    (*Format.printf "parse_state@.";*)
......
150 148
      ( json |> member "name" |> to_string,
151 149
        {ty_dec_desc = datatype;  ty_dec_loc = location},
152 150
        {ck_dec_desc = Ckdec_any; ck_dec_loc = location},
153
        false,
151
        true,
154 152
        Some initial_value
155 153
      )
156 154
end

Also available in: Unified diff