@@ -352,21 +352,20 @@ module Disequalities = struct
352352 *)
353353
354354 (* * Produces a string for the number used as offset; helper function for show* functions below.*)
355- let show_number r =
355+ let pretty_number () r =
356356 if Z. equal r Z. zero then
357- " "
357+ Pretty. nil
358358 else if Z. leq r Z. zero then
359- Z. to_string r
359+ GobZ. pretty () r
360360 else
361- " + " ^ Z. to_string r
361+ Pretty. dprintf " + %a " GobZ. pretty r
362362
363- let show_neq neq =
363+ let pretty_neq () neq =
364364 let clist = bindings neq in
365- let do_neq =
366- (fun s (v ,r ,v' ) ->
367- s ^ " \t " ^ T. show v ^ show_number r ^ " != " ^ T. show v' ^ " \n " )
365+ let do_neq () (v ,r ,v' ) =
366+ Pretty. dprintf " \t %a%a != %a\n " T. pretty v pretty_number r T. pretty v'
368367 in
369- List. fold_left do_neq " " clist
368+ Pretty. docList ~sep: Pretty. nil ( do_neq () ) () clist
370369
371370 let get_disequalities x =
372371 let to_disequality (t1 , z , t2 ) =
@@ -404,11 +403,11 @@ module SSet = struct
404403 let find_opt = TSet. find_opt
405404 let union = TSet. union
406405
407- let show_set set =
408- let show_element v s =
409- s ^ " \t " ^ T. show v ^ " ; \n "
406+ let pretty_set () set =
407+ let pretty_element () v =
408+ Pretty. dprintf " \t %a; \n " T. pretty v
410409 in
411- TSet. fold show_element set " " ^ " \n "
410+ Pretty. docList ~sep: Pretty. nil (pretty_element () ) () ( TSet. elements set)
412411
413412 (* * Adds all subterms of t to the SSet and the LookupMap*)
414413 let rec subterms_of_term (set ,map ) t =
@@ -495,12 +494,11 @@ module MRMap = struct
495494 let mem = TMap. mem
496495 let empty = TMap. empty
497496
498- let show_min_rep min_representatives =
499- let show_one_rep s (state , (rep , z )) =
500- s ^ " \t State: " ^ T. show state ^
501- " \n\t Min: (" ^ T. show rep ^ " , " ^ Z. to_string z ^ " )--\n\n "
497+ let pretty_min_rep () min_representatives =
498+ let pretty_one_rep () (state , (rep , z )) =
499+ Pretty. dprintf " \t State: %a\n\t Min: (%a, %a)--\n\n " T. pretty state T. pretty rep GobZ. pretty z
502500 in
503- List. fold_left show_one_rep " " (bindings min_representatives)
501+ Pretty. docList ~sep: Pretty. nil (pretty_one_rep () ) () (bindings min_representatives)
504502
505503 let rec update_min_repr (uf , set , map ) min_representatives = function
506504 | [] -> min_representatives
@@ -607,14 +605,12 @@ let get_transitions (uf, map) =
607605 in
608606 List. concat_map do_bindings (LMap. bindings map)
609607
610- let show_conj list =
608+ let pretty_conj () list =
611609 match list with
612- | [] -> " top"
610+ | [] -> Pretty. text " top"
613611 | list ->
614- let show_prop s d =
615- s ^ " \t " ^ T. show_prop d ^ " ;\n "
616- in
617- List. fold_left show_prop " " list
612+ let pretty_prop () d = Pretty. dprintf " \t %a;\n " T. pretty_prop d in
613+ Pretty. docList ~sep: Pretty. nil (pretty_prop () ) () list
618614
619615type data = {
620616 uf : TUF .t ;
@@ -675,7 +671,7 @@ let get_normal_conjunction cc get_normal_repr =
675671 | Equal (t1 ,t2 ,z ) -> failwith " No equality expected."
676672 | BlNequal (t1 ,t2 ) -> failwith " No block disequality expected."
677673 in
678- if M. tracing then M. trace " c2po-diseq" " DISEQUALITIES: %s ;\n Union find: %s \n Map: %s \n " (show_conj disequalities) ( TUF. show_uf cc.uf) ( LMap. show_map cc.map) ;
674+ if M. tracing then M. trace " c2po-diseq" " DISEQUALITIES: %a ;\n Union find: %a \n Map: %a \n " pretty_conj disequalities TUF. pretty_uf cc.uf LMap. pretty_map cc.map;
679675 let disequalities = List. map normalize_disequality disequalities in
680676 (* block disequalities *)
681677 let normalize_bldis t = match t with
@@ -753,11 +749,11 @@ let get_normal_form cc =
753749 LazyNormalFormEval. force cc.normal_form
754750
755751(* * Converts the normal form to string, but only if it was already computed. *)
756- let show_normal_form normal_form =
752+ let pretty_normal_form () normal_form =
757753 if LazyNormalFormEval. is_val normal_form then
758- show_conj (LazyNormalFormEval. force normal_form)
754+ pretty_conj () (LazyNormalFormEval. force normal_form)
759755 else
760- " not computed"
756+ Pretty. text " not computed"
761757
762758
763759let get_conjunction_from_data data =
@@ -778,21 +774,15 @@ let data_to_t (cc : data) : t =
778774 {data = cc;
779775 normal_form = LazyNormalFormEval. make cc}
780776
781- let show_all (x : t ) =
782- " Normal form:\n " ^
783- show_conj((get_conjunction x)) ^
784- " Union Find partition:\n " ^
785- TUF. show_uf x.data.uf
786- ^ " \n Subterm set:\n "
787- ^ SSet. show_set x.data.set
788- ^ " \n Lookup map/transitions:\n "
789- ^ LMap. show_map x.data.map
790- ^ " \n Neq:\n "
791- ^ Disequalities. show_neq x.data.diseq
792- ^ " \n Block diseqs:\n "
793- ^ show_conj (BlDis. to_conj x.data.bldis)
794- ^ " \n Min repr:\n "
795- ^ show_normal_form x.normal_form
777+ let pretty_all () (x : t ) =
778+ Pretty. dprintf " Normal form:\n %a\n Union Find partition:\n %a\n Subterm set:\n %a\n Lookup map/transitions:\n %a\n Neq:\n %a\n Block diseqs:\n %a\n Min repr:\n %a"
779+ pretty_conj (get_conjunction x)
780+ TUF. pretty_uf x.data.uf
781+ SSet. pretty_set x.data.set
782+ LMap. pretty_map x.data.map
783+ Disequalities. pretty_neq x.data.diseq
784+ pretty_conj (BlDis. to_conj x.data.bldis)
785+ pretty_normal_form x.normal_form
796786
797787(* * Splits the conjunction into three groups: the first one contains all equality propositions,
798788 the second one contains all inequality propositions
@@ -832,7 +822,7 @@ let congruence_neq cc neg' =
832822 (* take explicit dis-equalities into account *)
833823 let uf, neq_list = Disequalities. init_list_neq uf neg in
834824 let neq = Disequalities. propagate_neq (uf, cmap, arg, neq) cc.bldis neq_list in
835- if M. tracing then M. trace " c2po-neq" " congruence_neq: %s \n Union find: %s \n " ( Disequalities. show_neq neq) ( TUF. show_uf uf) ;
825+ if M. tracing then M. trace " c2po-neq" " congruence_neq: %a \n Union find: %a \n " Disequalities. pretty_neq neq TUF. pretty_uf uf;
836826 {cc with uf; diseq = neq}
837827
838828(* *
@@ -856,7 +846,7 @@ let rec closure (uf, map, new_repr) = function
856846 let v2, r2, uf = TUF. find uf t2 in
857847 let sizet1, sizet2 = T. get_size t1, T. get_size t2 in
858848 if not (Z. equal sizet1 sizet2) then (
859- if M. tracing then M. trace " c2po" " ignoring equality because the sizes are not the same: %s = %s + %s " ( T. show t1) ( Z. to_string r) ( T. show t2) ;
849+ if M. tracing then M. trace " c2po" " ignoring equality because the sizes are not the same: %a = %a + %a " T. pretty t1 GobZ. pretty r T. pretty t2;
860850 closure (uf, map, new_repr) rest
861851 )
862852 else if T. equal v1 v2 then
@@ -1046,7 +1036,7 @@ let meet_pos_conjs cc pos_conjs =
10461036 let cc = insert_set cc subterms in
10471037 closure cc pos_conjs
10481038 in
1049- if M. tracing then M. trace " c2po-meet" " meet_pos_conjs result: %s \n " (show_conj (get_conjunction_from_data res));
1039+ if M. tracing then M. trace " c2po-meet" " meet_pos_conjs result: %a \n " pretty_conj (get_conjunction_from_data res); (* TODO: avoid eager computation in argument *)
10501040 res
10511041
10521042(* * Adds propositions to the data structure.
@@ -1342,7 +1332,7 @@ let join_neq diseq1 diseq2 cc1 cc2 cc cmap1 cmap2 =
13421332 let subterms, _ = SSet. subterms_of_conj diseq in
13431333 let cc = insert_set cc subterms in
13441334 let res = congruence_neq cc diseq in
1345- (if M. tracing then M. trace " c2po-neq" " join_neq: %s \n\n " ( Disequalities. show_neq res.diseq) );
1335+ (if M. tracing then M. trace " c2po-neq" " join_neq: %a " Disequalities. pretty_neq res.diseq);
13461336 res
13471337
13481338(* * Joins the block disequalities bldiseq1 and bldiseq2, given a congruence closure data structure.
@@ -1369,7 +1359,7 @@ let join_bldis bldiseq1 bldiseq2 cc1 cc2 cc cmap1 cmap2 =
13691359 let cc = insert_set cc subterms in
13701360 let diseqs_ref_terms = List. filter both_root bldiseq in
13711361 let bldis = List. fold_left BlDis. add_block_diseq BlDis. empty diseqs_ref_terms in
1372- (if M. tracing then M. trace " c2po-neq" " join_bldis: %s \n\n " (show_conj (BlDis. to_conj bldis) ));
1362+ (if M. tracing then M. trace " c2po-neq" " join_bldis: %a " pretty_conj (BlDis. to_conj bldis));
13731363 {cc with bldis}
13741364
13751365(* * Check for equality of two congruence closures,
@@ -1516,8 +1506,8 @@ module MayBeEqual = struct
15161506 res
15171507 in
15181508
1519- if M. tracing then M. trace " c2po-query" " may-point-to %a -> equal terms: %s "
1520- d_exp exp (List. fold_left (fun s (t ,z ) -> s ^ " ( " ^ T. show t ^ " , " ^ Z. to_string Z. (z + offset) ^ " ) " ) " " equal_terms) ;
1509+ if M. tracing then M. trace " c2po-query" " may-point-to %a -> equal terms: %a "
1510+ d_exp exp (Pretty. docList ~sep: Pretty. nil (fun (t ,z ) -> Pretty. dprintf " (%a,%a) " T. pretty t GobZ. pretty Z. (z + offset))) equal_terms;
15211511
15221512 List. fold_left intersect_query_result (AD. top () ) equal_terms
15231513
@@ -1542,8 +1532,8 @@ module MayBeEqual = struct
15421532 with IntDomain. ArithmeticOnIntegerBot _ ->
15431533 AD. bot ()
15441534 in
1545- M. tracel " c2po-maypointto2" " QUERY MayPointTo. \n res: %a;\n t2: %s ; exp2: %a; res: %a; \n meet: %a; result: %s \n "
1546- AD. pretty mpt1 ( T. show t2) d_plainexp exp2 AD. pretty mpt2 AD. pretty meet (string_of_bool res) ;
1535+ M. tracel " c2po-maypointto2" " QUERY MayPointTo. \n res: %a;\n t2: %a ; exp2: %a; res: %a; \n meet: %a; result: %B "
1536+ AD. pretty mpt1 T. pretty t2 d_plainexp exp2 AD. pretty mpt2 AD. pretty meet res;
15471537 end ;
15481538 res
15491539
@@ -1555,8 +1545,8 @@ module MayBeEqual = struct
15551545 let exp1 = T. to_cil t1 in
15561546 let mpt1 = may_point_to_all_equal_terms ask exp1 cc t1 Z. zero in
15571547 let res = may_point_to_address ask mpt1 t2 off cc in
1558- if M. tracing && res then M. tracel " c2po-maypointto2" " QUERY MayPointTo. \n res: %a;\n t1: %s ; exp1: %a;\n "
1559- AD. pretty mpt1 ( T. show t1) d_plainexp exp1;
1548+ if M. tracing && res then M. tracel " c2po-maypointto2" " QUERY MayPointTo. \n res: %a;\n t1: %a ; exp1: %a;"
1549+ AD. pretty mpt1 T. pretty t1 d_plainexp exp1;
15601550 res
15611551
15621552 (* * Returns true if `t1` and `t2` may possibly be equal or may possibly overlap. *)
@@ -1597,7 +1587,7 @@ module MayBeEqual = struct
15971587 The parameter s is the size in bits of the variable t1 we are assigning to. *)
15981588 let may_be_equal ask cc size t1 t2 =
15991589 let res = may_be_equal ask cc size t1 t2 in
1600- if M. tracing then M. tracel " c2po-maypointto" " May be equal: %s %s : %b\n " ( T. show t1) ( T. show t2) res;
1590+ if M. tracing then M. tracel " c2po-maypointto" " May be equal: %a %a : %b" T. pretty t1 T. pretty t2 res;
16011591 res
16021592
16031593 (* *Returns true if `t2` or any subterm of `t2` may possibly point to one of the addresses in `addresses`.*)
0 commit comments