Project

General

Profile

Revision 6a6abd76

View differences:

src/c_backend.ml
601 601
  let array_mem = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
602 602
  let inst = mk_instance m in
603 603
  let attr = mk_attribute m in
604
  fprintf fmt "@[<v 2>#define %a(%s, %a%tinst)\\@,%s %a inst;\\@,%a%t%a;@,@]"
604
  fprintf fmt "@[<v 2>#define %a(%s, %a%t%s)\\@,%s %a %s;\\@,%a%t%a;@,@]"
605 605
    pp_machine_static_declare_name m.mname.node_id
606 606
    attr
607 607
    (Utils.fprintf_list ~sep:", " (pp_c_var_read m)) m.mstatic
608 608
    (Utils.pp_final_char_if_non_empty ", " m.mstatic)
609
    inst
609 610
    attr
610 611
    pp_machine_memtype_name m.mname.node_id
612
    inst
611 613
    (Utils.fprintf_list ~sep:";\\@," pp_c_decl_local_var) array_mem
612 614
    (Utils.pp_final_char_if_non_empty ";\\@," array_mem)
613 615
    (Utils.fprintf_list ~sep:";\\@,"
......
858 860
let print_main_header fmt =
859 861
  fprintf fmt "#include <stdio.h>@.#include <unistd.h>@.#include \"%s/include/lustrec/io_frontend.h\"@." Version.prefix
860 862

  
861
let rec pp_c_type_decl filename cpt var fmt tdecl =
863
let rec pp_c_struct_type_field filename cpt var fmt (label, tdesc) =
864
  fprintf fmt "%a %a" (pp_c_type_decl filename cpt var) tdesc pp_print_string label
865
and pp_c_type_decl filename cpt var fmt tdecl =
862 866
  match tdecl with
863 867
  | Tydec_any           -> assert false
864 868
  | Tydec_int           -> fprintf fmt "int %s" var
......
873 877
      incr cpt;
874 878
      fprintf fmt "enum _enum_%s_%d { %a } %s" filename !cpt (Utils.fprintf_list ~sep:", " pp_print_string) tl var
875 879
    end
880
  | Tydec_struct fl ->
881
    begin
882
      incr cpt;
883
      fprintf fmt "struct _struct_%s_%d { %a } %s" filename !cpt (Utils.fprintf_list ~sep:"; " (pp_c_struct_type_field filename cpt var)) fl var
884
    end
876 885

  
877 886
let print_type_definitions fmt filename =
878 887
  let cpt_type = ref 0 in
src/corelang.ml
348 348
                     | Tydec_enum tl -> tl
349 349
                     | _             -> assert false)
350 350
 | _            -> assert false
351
(*
351

  
352 352
let get_struct_type_fields cty =
353 353
 match cty with
354 354
 | Tydec_const _ -> (match Hashtbl.find type_table cty with
355 355
                     | Tydec_struct fl -> fl
356 356
                     | _               -> assert false)
357 357
 | _            -> assert false
358
 *)
358

  
359 359
let const_of_bool b =
360 360
 Const_tag (if b then tag_true else tag_false)
361 361

  
src/corelang.mli
180 180
val tag_true: label
181 181
val tag_false: label
182 182
val tag_table: (label, type_dec_desc) Hashtbl.t
183
val field_table: (label, type_dec_desc) Hashtbl.t
183 184

  
184 185
val get_enum_type_tags: type_dec_desc -> label list
185 186

  
187
val get_struct_type_fields: type_dec_desc -> (label * type_dec_desc) list
188

  
186 189
val const_of_bool: bool -> constant
187 190
val const_is_bool: constant -> bool
188 191
val const_negation: constant -> constant
src/lustreSpec.ml
33 33
  | Tydec_clock of type_dec_desc
34 34
  | Tydec_const of ident
35 35
  | Tydec_enum of ident list
36
(*  | Tydec_struct of (ident * type_dec_desc) list *)
36
  | Tydec_struct of (ident * type_dec_desc) list
37 37
  | Tydec_array of Dimension.dim_expr * type_dec_desc
38 38

  
39 39
type clock_dec =
src/parser_lustre.mly
225 225
      Hashtbl.add type_table (Tydec_const $2) (Corelang.get_repr_type $4)
226 226
    with Not_found-> raise (Corelang.Unbound_type ($4, Location.symbol_rloc())) }
227 227
| TYPE IDENT EQ ENUM LCUR tag_list RCUR { Hashtbl.add type_table (Tydec_const $2) (Tydec_enum ($6 (Tydec_const $2))) }
228
| TYPE IDENT EQ STRUCT LCUR field_list RCUR { Hashtbl.add type_table (Tydec_const $2) Tydec_any }
228
| TYPE IDENT EQ STRUCT LCUR field_list RCUR { Hashtbl.add type_table (Tydec_const $2) (Tydec_struct ($6 (Tydec_const $2))) }
229 229

  
230 230
array_typ_decl:
231 231
                            { fun typ -> typ }
......
243 243
tag_list:
244 244
  IDENT
245 245
  { (fun t -> if Hashtbl.mem tag_table $1
246
             then raise (Corelang.Already_bound_label ($1, t, Location.symbol_rloc ()))
247
             else (Hashtbl.add tag_table $1 t; $1 :: [])) }
246
              then raise (Corelang.Already_bound_label ($1, t, Location.symbol_rloc ()))
247
              else (Hashtbl.add tag_table $1 t; $1 :: [])) }
248 248
| tag_list COMMA IDENT
249 249
  { (fun t -> if Hashtbl.mem tag_table $3
250
             then raise (Corelang.Already_bound_label ($3, t, Location.symbol_rloc ()))
251
             else (Hashtbl.add tag_table $3 t; $3 :: ($1 t))) }
250
              then raise (Corelang.Already_bound_label ($3, t, Location.symbol_rloc ()))
251
              else (Hashtbl.add tag_table $3 t; $3 :: ($1 t))) }
252 252

  
253 253
field_list:
254
   { [] }
255
| IDENT COL typeconst SCOL field_list { ($1, $3) :: $5 }
254
  { (fun t -> []) }
255
| field_list IDENT COL typeconst SCOL
256
  { (fun t -> if Hashtbl.mem field_table $2
257
              then raise (Corelang.Already_bound_label ($2, t, Location.symbol_rloc ()))
258
              else (Hashtbl.add field_table $2 t; ($2, $4) :: ($1 t))) }
256 259

  
257 260
eq_list:
258 261
  { [], [], [] }
src/printers.ml
118 118
let pp_node_args = fprintf_list ~sep:"; " pp_node_var 
119 119

  
120 120
let pp_var_type_dec fmt ty =
121
  let rec pp_var_type_dec_desc fmt tdesc =
121
  let rec pp_var_struct_type_field fmt (label, tdesc) =
122
    fprintf fmt "%a : %a" pp_var_type_dec_desc tdesc pp_print_string label
123
  and pp_var_type_dec_desc fmt tdesc =
122 124
  match tdesc with 
123 125
    | Tydec_any -> fprintf fmt "<any>"
124 126
    | Tydec_int -> fprintf fmt "int"
......
128 130
    | Tydec_clock t -> fprintf fmt "%a clock" pp_var_type_dec_desc t
129 131
    | Tydec_const t -> fprintf fmt "%s" t
130 132
    | Tydec_enum id_list -> fprintf fmt "enum {%a }" (fprintf_list ~sep:", " pp_print_string) id_list
133
    | Tydec_struct f_list -> fprintf fmt "struct {%a }" (fprintf_list ~sep:"; " pp_var_struct_type_field) f_list
131 134
    | Tydec_array (s, t) -> fprintf fmt "%a^%a" pp_var_type_dec_desc t Dimension.pp_dimension s
132 135
in pp_var_type_dec_desc fmt ty.ty_dec_desc
133 136

  
src/typing.ml
111 111
  | Tydec_clock ty -> Type_predef.type_clock (type_coretype type_dim ty)
112 112
  | Tydec_const c -> Type_predef.type_const c
113 113
  | Tydec_enum tl -> Type_predef.type_enum tl
114
  | Tydec_struct fl -> assert false (*Type_predef.type_struct fl*)
114 115
  | Tydec_array (d, ty) ->
115 116
    begin
116 117
      type_dim d;

Also available in: Unified diff