Project

General

Profile

Download (8.57 KB) Statistics
| Branch: | Tag: | Revision:
1
(********************************************************************)
2
(*                                                                  *)
3
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
4
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
5
(*                                                                  *)
6
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
7
(*  under the terms of the GNU Lesser General Public License        *)
8
(*  version 2.1.                                                    *)
9
(*                                                                  *)
10
(********************************************************************)
11

    
12
open Format
13
open Lustre_types
14

    
15
(**************************************************************************)
16
(*     Printing spec for c *)
17

    
18
(**************************************************************************)
19
(* OLD STUFF ???
20

    
21

    
22
let pp_acsl_type var fmt t =
23
  let rec aux t pp_suffix =
24
  match (Types.repr t).Types.tdesc with
25
  | Types.Tclock t'       -> aux t' pp_suffix
26
  | Types.Tbool           -> fprintf fmt "int %s%a" var pp_suffix ()
27
  | Types.Treal           -> fprintf fmt "real %s%a" var pp_suffix ()
28
  | Types.Tint            -> fprintf fmt "int %s%a" var pp_suffix ()
29
  | Types.Tarray (d, t')  ->
30
    let pp_suffix' fmt () = fprintf fmt "%a[%a]" pp_suffix () pp_c_dimension d in
31
    aux t' pp_suffix'
32
  (* | Types.Tstatic (_, t') -> fprintf fmt "const "; aux t' pp_suffix *)
33
  (* | Types.Tconst ty       -> fprintf fmt "%s %s" ty var *)
34
  (* | Types.Tarrow (_, _)   -> fprintf fmt "void (\*%s)()" var *)
35
  | _                     -> eprintf "internal error: pp_acsl_type %a@." Types.print_ty t; assert false
36
  in aux t (fun fmt () -> ())
37

    
38
let pp_acsl_var_decl fmt id =
39
  pp_acsl_type id.var_id fmt id.var_type
40

    
41

    
42
let rec pp_eexpr is_output fmt eexpr = 
43
  let pp_eexpr = pp_eexpr is_output in
44
  match eexpr.eexpr_desc with
45
    | EExpr_const c -> Printers.pp_econst fmt c
46
    | EExpr_ident id -> 
47
      if is_output id then pp_print_string fmt ("*" ^ id) else pp_print_string fmt id
48
    | EExpr_tuple el -> Utils.fprintf_list ~sep:"," pp_eexpr fmt el
49
    | EExpr_arrow (e1, e2) -> fprintf fmt "%a -> %a" pp_eexpr e1 pp_eexpr e2
50
    | EExpr_fby (e1, e2) -> fprintf fmt "%a fby %a" pp_eexpr e1 pp_eexpr e2
51
    (* | EExpr_concat (e1, e2) -> fprintf fmt "%a::%a" pp_eexpr e1 pp_eexpr e2 *)
52
    (* | EExpr_tail e -> fprintf fmt "tail %a" pp_eexpr e *)
53
    | EExpr_pre e -> fprintf fmt "pre %a" pp_eexpr e
54
    | EExpr_when (e, id) -> fprintf fmt "%a when %s" pp_eexpr e id
55
    | EExpr_merge (id, e1, e2) -> 
56
      fprintf fmt "merge (%s, %a, %a)" id pp_eexpr e1 pp_eexpr e2
57
    | EExpr_appl (id, e, r) -> pp_eapp is_output fmt id e r
58
    | EExpr_forall (vars, e) -> fprintf fmt "forall %a; %a" Printers.pp_node_args vars pp_eexpr e 
59
    | EExpr_exists (vars, e) -> fprintf fmt "exists %a; %a" Printers.pp_node_args vars pp_eexpr e 
60

    
61

    
62
    (* | EExpr_whennot _ *)
63
    (* | EExpr_uclock _ *)
64
    (* | EExpr_dclock _ *)
65
    (* | EExpr_phclock _ -> assert false *)
66
and pp_eapp is_output fmt id e r =
67
  let pp_eexpr = pp_eexpr is_output in
68
  match r with
69
  | None ->
70
    (match id, e.eexpr_desc with
71
    | "+", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a + %a)" pp_eexpr e1 pp_eexpr e2
72
    | "uminus", _ -> fprintf fmt "(- %a)" pp_eexpr e
73
    | "-", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a - %a)" pp_eexpr e1 pp_eexpr e2
74
    | "*", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a * %a)" pp_eexpr e1 pp_eexpr e2
75
    | "/", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a / %a)" pp_eexpr e1 pp_eexpr e2
76
    | "mod", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a mod %a)" pp_eexpr e1 pp_eexpr e2
77
    | "&&", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a && %a)" pp_eexpr e1 pp_eexpr e2
78
    | "||", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a || %a)" pp_eexpr e1 pp_eexpr e2
79
    | "xor", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a ^^ %a)" pp_eexpr e1 pp_eexpr e2
80
    | "impl", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a ==> %a)" pp_eexpr e1 pp_eexpr e2
81
    | "<", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a < %a)" pp_eexpr e1 pp_eexpr e2
82
    | "<=", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a <= %a)" pp_eexpr e1 pp_eexpr e2
83
    | ">", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a > %a)" pp_eexpr e1 pp_eexpr e2
84
    | ">=", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a >= %a)" pp_eexpr e1 pp_eexpr e2
85
    | "!=", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a != %a)" pp_eexpr e1 pp_eexpr e2
86
    | "=", EExpr_tuple([e1;e2]) -> fprintf fmt "(%a == %a)" pp_eexpr e1 pp_eexpr e2
87
    | "not", _ -> fprintf fmt "(! %a)" pp_eexpr e
88
    | "ite", EExpr_tuple([e1;e2;e3]) -> fprintf fmt "(if %a then %a else %a)" pp_eexpr e1 pp_eexpr e2 pp_eexpr e3
89
    | _ -> fprintf fmt "%s (%a)" id pp_eexpr e)
90
  | Some x -> fprintf fmt "%s (%a) every %s" id pp_eexpr e x 
91

    
92
let pp_ensures is_output fmt e =
93
  match e with
94
    | EnsuresExpr e -> fprintf fmt "ensures %a;@ " (pp_eexpr is_output) e
95
    | SpecObserverNode (name, args) -> fprintf fmt "observer %s (%a);@ " name (Utils.fprintf_list ~sep:", " (pp_eexpr is_output)) args
96

    
97
let pp_acsl_spec outputs fmt spec =
98
  let is_output = fun oid -> List.exists (fun v -> v.var_id = oid) outputs in
99
  let pp_eexpr = pp_eexpr is_output in
100
  fprintf fmt "@[<v 2>/*@@ ";
101
  Utils.fprintf_list ~sep:"" (fun fmt r -> fprintf fmt "requires %a;@ " pp_eexpr r) fmt spec.requires;
102
  Utils.fprintf_list ~sep:"" (pp_ensures is_output) fmt spec.ensures;
103
  fprintf fmt "@ ";
104
  (* fprintf fmt "assigns *self%t%a;@ "  *)
105
  (*   (fun fmt -> if List.length outputs > 0 then fprintf fmt ", ") *)
106
  (*   (fprintf_list ~sep:"," (fun fmt v -> fprintf fmt "*%s" v.var_id)) outputs; *)
107
  Utils.fprintf_list ~sep:"@ " (fun fmt (name, assumes, requires) -> 
108
    fprintf fmt "behavior %s:@[@ %a@ %a@]" 
109
      name
110
      (Utils.fprintf_list ~sep:"@ " (fun fmt r -> fprintf fmt "assumes %a;" pp_eexpr r)) assumes
111
      (Utils.fprintf_list ~sep:"@ " (pp_ensures is_output)) requires
112
  ) fmt spec.behaviors;
113
  fprintf fmt "@]@ */@.";
114
  ()
115

    
116

    
117

    
118

    
119
let print_machine_decl_prefix fmt m =
120
   (* Print specification if any *)
121
   (match m.mspec with
122
  | None -> ()
123
  | Some spec -> 
124
    pp_acsl_spec m.mstep.step_outputs fmt spec
125
  )
126

    
127
  *)
128

    
129
(* TODO ACSL
130
   mspec are function body annotations, sush as loop invariants, acsl asserts ... *) 
131
let pp_mspec _ _ = ()
132

    
133
   (* TODO ACSL 
134
   Return updates machines (eg with local annotations) and acsl preamble *)
135
let preprocess_acsl machines = machines, []
136
                          
137
(* TODO: This preamble shall be a list of types, axiomatics, predicates, theorems *)
138
let pp_acsl_preamble fmt preamble =
139
  Format.fprintf fmt "";
140
  ()
141
(**************************************************************************)
142
(*                              MAKEFILE                                  *)
143
(**************************************************************************)
144

    
145
let makefile_targets fmt basename _nodename dependencies =
146
  fprintf fmt "FRAMACEACSL=`frama-c -print-share-path`/e-acsl@.";
147
  (* EACSL version of library file . c *)
148
  fprintf fmt "%s_eacsl.c: %s.c %s.h@." basename basename basename;
149
  fprintf fmt 
150
    "\tframa-c -e-acsl-full-mmodel -machdep x86_64 -e-acsl %s.c -then-on e-acsl -print -ocode %s_eacsl.c@." 
151
    basename basename; 
152
  fprintf fmt "@.";
153
  fprintf fmt "@.";
154

    
155
  (* EACSL version of library file . c + main .c  *)
156
  fprintf fmt "%s_main_eacsl.c: %s.c %s.h %s_main.c@." basename basename basename basename;
157
  fprintf fmt "\tframa-c -e-acsl-full-mmodel -machdep x86_64 -e-acsl %s.c %s_main.c -then-on e-acsl -print -ocode %s_main_eacsl.i@." 
158
    basename basename basename; 
159
  (* Ugly hack to deal with eacsl bugs *)
160
  fprintf fmt "\tgrep -v _fc_stdout %s_main_eacsl.i > %s_main_eacsl.c" basename basename;
161
  fprintf fmt "@.";
162
  fprintf fmt "@.";
163

    
164
  (* EACSL version of binary *)
165
  fprintf fmt "%s_main_eacsl: %s_main_eacsl.c@." basename basename;
166
  fprintf fmt "\t${GCC} -Wno-attributes -I${INC} -I. -c %s_main_eacsl.c@." basename; (* compiling instrumented lib + main *)
167
  C_backend_makefile.fprintf_dependencies fmt dependencies; 
168
  fprintf fmt "\t${GCC} -Wno-attributes -o %s_main_eacsl io_frontend.o %a %s %s_main_eacsl.o %a@." 
169
    basename 
170
    (Utils.fprintf_list ~sep:" " (fun fmt dep -> Format.fprintf fmt "%s.o" dep.name)) 
171
    (C_backend_makefile.compiled_dependencies dependencies)
172
    ("${FRAMACEACSL}/e_acsl.c " 
173
     ^ "${FRAMACEACSL}/memory_model/e_acsl_bittree.c " 
174
     ^ "${FRAMACEACSL}/memory_model/e_acsl_mmodel.c")
175
    basename 
176
    (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) 
177
    (C_backend_makefile.lib_dependencies dependencies)
178
  ;
179
  fprintf fmt "@.";
180

    
181
module MakefileMod =
182
struct
183
  let other_targets = makefile_targets
184
    
185
end
186

    
187
(* Local Variables: *)
188
(* compile-command:"make -C ../../.." *)
189
(* End: *)
(9-9/10)