Revision 0323b9e6
Added by Pierre-Loïc Garoche almost 6 years ago
src/printers.ml | ||
---|---|---|
95 | 95 |
| [x] -> pp_print_string fmt x |
96 | 96 |
| _ -> fprintf fmt "/%a/" (fprintf_list ~sep:"/" pp_print_string) kwds |
97 | 97 |
|
98 |
let pp_kind2_when fmt (id, l) = |
|
99 |
if l = "true" then |
|
100 |
fprintf fmt "%s" id |
|
101 |
else if l = "false" then |
|
102 |
fprintf fmt "not(%s)" id |
|
103 |
else |
|
104 |
fprintf fmt "(%s=%s)" l id |
|
105 |
|
|
106 |
|
|
98 | 107 |
let rec pp_expr fmt expr = |
99 | 108 |
(match expr.expr_annot with |
100 |
| None -> fprintf fmt "%t" |
|
101 |
| Some ann -> fprintf fmt "@[(%a %t)@]" pp_expr_annot ann) |
|
109 |
| None -> fprintf fmt "%t"
|
|
110 |
| Some ann -> fprintf fmt "@[(%a %t)@]" pp_expr_annot ann)
|
|
102 | 111 |
(fun fmt -> |
103 | 112 |
match expr.expr_desc with |
104 |
| Expr_const c -> pp_const fmt c |
|
105 |
| Expr_ident id -> fprintf fmt "%s" id |
|
106 |
| Expr_array a -> fprintf fmt "[%a]" pp_tuple a |
|
107 |
| Expr_access (a, d) -> fprintf fmt "%a[%a]" pp_expr a Dimension.pp_dimension d |
|
108 |
| Expr_power (a, d) -> fprintf fmt "(%a^%a)" pp_expr a Dimension.pp_dimension d |
|
109 |
| Expr_tuple el -> fprintf fmt "(%a)" pp_tuple el |
|
110 |
| Expr_ite (c, t, e) -> fprintf fmt "@[<hov 1>(if %a then@ @[<hov 2>%a@]@ else@ @[<hov 2>%a@]@])" pp_expr c pp_expr t pp_expr e |
|
111 |
| Expr_arrow (e1, e2) -> fprintf fmt "(%a -> %a)" pp_expr e1 pp_expr e2 |
|
112 |
| Expr_fby (e1, e2) -> fprintf fmt "%a fby %a" pp_expr e1 pp_expr e2 |
|
113 |
| Expr_pre e -> fprintf fmt "pre %a" pp_expr e |
|
114 |
| Expr_when (e, id, l) -> |
|
115 |
if !Options.kind2_print then |
|
116 |
if l = "true" then |
|
117 |
fprintf fmt "%a when %s" pp_expr e id |
|
118 |
else if l = "false" then |
|
119 |
fprintf fmt "%a when not(%s)" pp_expr e id |
|
113 |
| Expr_const c -> pp_const fmt c |
|
114 |
| Expr_ident id -> fprintf fmt "%s" id |
|
115 |
| Expr_array a -> fprintf fmt "[%a]" pp_tuple a |
|
116 |
| Expr_access (a, d) -> fprintf fmt "%a[%a]" pp_expr a Dimension.pp_dimension d |
|
117 |
| Expr_power (a, d) -> fprintf fmt "(%a^%a)" pp_expr a Dimension.pp_dimension d |
|
118 |
| Expr_tuple el -> fprintf fmt "(%a)" pp_tuple el |
|
119 |
| Expr_ite (c, t, e) -> fprintf fmt "@[<hov 1>(if %a then@ @[<hov 2>%a@]@ else@ @[<hov 2>%a@]@])" pp_expr c pp_expr t pp_expr e |
|
120 |
| Expr_arrow (e1, e2) -> fprintf fmt "(%a -> %a)" pp_expr e1 pp_expr e2 |
|
121 |
| Expr_fby (e1, e2) -> fprintf fmt "%a fby %a" pp_expr e1 pp_expr e2 |
|
122 |
| Expr_pre e -> fprintf fmt "pre %a" pp_expr e |
|
123 |
| Expr_when (e, id, l) -> |
|
124 |
if !Options.kind2_print then |
|
125 |
fprintf fmt "%a when %a" pp_expr e pp_kind2_when (l, id) |
|
120 | 126 |
else |
121 |
fprintf fmt "%a when (%s=%s)" pp_expr e l id |
|
122 |
else |
|
123 |
fprintf fmt "%a when %s(%s)" pp_expr e l id |
|
124 |
| Expr_merge (id, hl) -> |
|
125 |
fprintf fmt "merge %s %a" id pp_handlers hl |
|
126 |
| Expr_appl (id, e, r) -> pp_app fmt id e r |
|
127 |
fprintf fmt "%a when %s(%s)" pp_expr e l id |
|
128 |
| Expr_merge (id, hl) -> |
|
129 |
fprintf fmt "merge %s %a" id pp_handlers hl |
|
130 |
| Expr_appl (id, e, r) -> pp_app fmt id e r |
|
127 | 131 |
) |
128 | 132 |
and pp_tuple fmt el = |
129 |
fprintf_list ~sep:"," pp_expr fmt el |
|
133 |
fprintf_list ~sep:"," pp_expr fmt el
|
|
130 | 134 |
|
131 | 135 |
and pp_handler fmt (t, h) = |
132 |
fprintf fmt "(%s -> %a)" t pp_expr h |
|
136 |
fprintf fmt "(%s -> %a)" t pp_expr h
|
|
133 | 137 |
|
134 | 138 |
and pp_handlers fmt hl = |
135 |
fprintf_list ~sep:" " pp_handler fmt hl |
|
139 |
fprintf_list ~sep:" " pp_handler fmt hl
|
|
136 | 140 |
|
137 | 141 |
and pp_app fmt id e r = |
138 |
match r with |
|
139 |
| None -> pp_call fmt id e |
|
140 |
| Some c -> |
|
141 |
if !Options.kind2_print && |
|
142 |
not (List.mem id Basic_library.internal_funs) then |
|
143 |
(* We only translate calls to nodes in kind2. The other may be |
|
142 |
if !Options.kind2_print && |
|
143 |
not (List.mem id Basic_library.internal_funs) then |
|
144 |
(* We only translate calls to nodes in kind2. The other may be |
|
144 | 145 |
rejected by Kind2 *) |
145 |
fprintf fmt "(restart %s every (%a)) (%a)" |
|
146 |
id |
|
147 |
pp_expr c |
|
148 |
pp_expr e |
|
149 |
else |
|
150 |
fprintf fmt "%t every (%a)" (fun fmt -> pp_call fmt id e) pp_expr c |
|
146 |
( (* Small local function to extract the first layer of when constructs *) |
|
147 |
let rec un_when_ed_expr e = |
|
148 |
match e.expr_desc with |
|
149 |
Expr_when (e,i,l) -> (Some (i,l)), e |
|
150 |
| Expr_tuple el -> ( |
|
151 |
let un_when_ed_el = List.map un_when_ed_expr el in |
|
152 |
if List.length un_when_ed_el < 1 then |
|
153 |
assert false; (* tuple should have at least one element*) |
|
154 |
let init_when = |
|
155 |
fst (List.hd un_when_ed_el) |
|
156 |
in |
|
157 |
let common_when = |
|
158 |
List.fold_left (fun accu (new_opt,_) -> |
|
159 |
match accu, new_opt with |
|
160 |
| Some c1, Some c2 -> |
|
161 |
if c1 = c2 then |
|
162 |
Some c1 |
|
163 |
else |
|
164 |
assert false (* should not be clocked *) |
|
165 |
| None, None -> None |
|
166 |
| _ -> assert false (* If this is not even, there |
|
167 |
should be a clocking problem*) |
|
168 |
) init_when (List.tl un_when_ed_el) |
|
169 |
in |
|
170 |
match common_when with |
|
171 |
| None -> None, e |
|
172 |
| Some _ -> common_when, { e with expr_desc = |
|
173 |
Expr_tuple (List.map snd un_when_ed_el) } |
|
174 |
) |
|
175 |
| _ -> None, e |
|
176 |
in |
|
177 |
let when_expr, unwhen_ed_e = un_when_ed_expr e in |
|
178 |
match r, when_expr with |
|
179 |
| None, None -> pp_call fmt id e |
|
180 |
| None, Some w -> |
|
181 |
fprintf fmt "(activate %s every (%a)) (%a)" |
|
182 |
id |
|
183 |
pp_kind2_when w |
|
184 |
pp_expr e |
|
185 |
| Some r, None -> |
|
186 |
fprintf fmt "(restart %s every (%a)) (%a)" |
|
187 |
id |
|
188 |
pp_expr r |
|
189 |
pp_expr e |
|
190 |
| Some r, Some w -> |
|
191 |
fprintf fmt "(activate %s every (%a) restart every (%a)) (%a)" |
|
192 |
id |
|
193 |
pp_kind2_when w |
|
194 |
pp_expr r |
|
195 |
pp_expr e |
|
196 |
) |
|
151 | 197 |
|
198 |
else ( |
|
199 |
match r with |
|
200 |
| None -> pp_call fmt id e |
|
201 |
| Some c -> |
|
202 |
fprintf fmt "%t every (%a)" (fun fmt -> pp_call fmt id e) pp_expr c |
|
203 |
) |
|
204 |
|
|
152 | 205 |
and pp_call fmt id e = |
153 | 206 |
match id, e.expr_desc with |
154 | 207 |
| "+", Expr_tuple([e1;e2]) -> fprintf fmt "(%a + %a)" pp_expr e1 pp_expr e2 |
... | ... | |
178 | 231 |
pp_expr e.eexpr_qfexpr |
179 | 232 |
|
180 | 233 |
and pp_sf_value fmt e = |
181 |
fprintf fmt "%a"
|
|
182 |
(* (Utils.fprintf_list ~sep:"; " pp_quantifiers) e.eexpr_quantifiers *)
|
|
183 |
(* (fun fmt -> match e.eexpr_quantifiers *)
|
|
184 |
(* with [] -> () *)
|
|
185 |
(* | _ -> fprintf fmt ";") *)
|
|
186 |
pp_expr e.eexpr_qfexpr
|
|
234 |
fprintf fmt "%a" |
|
235 |
(* (Utils.fprintf_list ~sep:"; " pp_quantifiers) e.eexpr_quantifiers *) |
|
236 |
(* (fun fmt -> match e.eexpr_quantifiers *) |
|
237 |
(* with [] -> () *) |
|
238 |
(* | _ -> fprintf fmt ";") *) |
|
239 |
pp_expr e.eexpr_qfexpr |
|
187 | 240 |
|
188 | 241 |
and pp_s_function fmt expr_ann = |
189 | 242 |
let pp_annot fmt (kwds, ee) = |
190 | 243 |
fprintf fmt " %t : %a" |
191 |
(fun fmt -> match kwds with
|
|
192 |
| [] -> assert false
|
|
193 |
| [x] -> pp_print_string fmt x
|
|
194 |
| _ -> fprintf fmt "%a" (fprintf_list ~sep:"/" pp_print_string) kwds)
|
|
195 |
pp_sf_value ee
|
|
244 |
(fun fmt -> match kwds with |
|
245 |
| [] -> assert false |
|
246 |
| [x] -> pp_print_string fmt x |
|
247 |
| _ -> fprintf fmt "%a" (fprintf_list ~sep:"/" pp_print_string) kwds) |
|
248 |
pp_sf_value ee |
|
196 | 249 |
in |
197 | 250 |
fprintf_list ~sep:"@ " pp_annot fmt expr_ann.annots |
198 | 251 |
|
Also available in: Unified diff
More kind2 outputs: clocked fun call + clocked and restart fun call