@@ -382,13 +382,34 @@ let main () =
382382 (* Initialize I/O + interaction module *)
383383 let module State = struct
384384 type t = {
385- prvopts : prv_options ;
386- input : string option ;
387- terminal : T .terminal lazy_t ;
388- interactive : bool ;
389- eco : bool ;
390- gccompact : int option ;
385+ (* ---*) prvopts : prv_options ;
386+ (* ---*) input : string option ;
387+ (* ---*) terminal : T .terminal lazy_t ;
388+ (* ---*) interactive : bool ;
389+ (* ---*) eco : bool ;
390+ (* ---*) gccompact : int option ;
391+ mutable trace : trace1 list option ;
391392 }
393+
394+ and trace1 =
395+ { position : int
396+ ; goal : string option
397+ ; messages : (EcGState .loglevel * string ) list }
398+
399+ module Trace = struct
400+ let trace0 : trace1 =
401+ { position = 0 ; goal = None ; messages = [] ; }
402+
403+ let push1_message (trace1 : trace1 ) (msg , lvl ) : trace1 =
404+ { trace1 with messages = (msg, lvl) :: trace1.messages }
405+
406+ let push_message (trace : trace1 list ) msg =
407+ match trace with
408+ | [] ->
409+ [push1_message trace0 msg]
410+ | trace1 :: trace ->
411+ push1_message trace1 msg :: trace
412+ end
392413 end in
393414
394415 let state : State.t =
@@ -442,7 +463,8 @@ let main () =
442463 ; terminal = terminal
443464 ; interactive = true
444465 ; eco = false
445- ; gccompact = None }
466+ ; gccompact = None
467+ ; trace = None }
446468
447469 end
448470
@@ -464,12 +486,15 @@ let main () =
464486 lazy (T. from_channel ~name ~gcstats ~progress (open_in name))
465487 in
466488
489+ let trace0 = State. { position = 0 ; goal = None ; messages = [] } in
490+
467491 { prvopts = {cmpopts.cmpo_provers with prvo_iterate = true }
468492 ; input = Some name
469493 ; terminal = terminal
470494 ; interactive = false
471495 ; eco = cmpopts.cmpo_noeco
472- ; gccompact = cmpopts.cmpo_compact }
496+ ; gccompact = cmpopts.cmpo_compact
497+ ; trace = Some [trace0] }
473498
474499 end
475500
@@ -500,7 +525,20 @@ let main () =
500525
501526 assert (nameo <> input);
502527
503- let eco = EcEco. {
528+ let eco =
529+ let mktrace (trace : State.trace1 list ) : EcEco.ecotrace =
530+ let mktrace1 (trace1 : State.trace1 ) : int * EcEco.ecotrace1 =
531+ let goal = Option. value ~default: " " trace1.goal in
532+ let messages =
533+ let for1 (lvl , msg ) =
534+ Format. sprintf " %s: %s"
535+ (EcGState. string_of_loglevel lvl)
536+ msg in
537+ String. concat " \n " (List. rev_map for1 trace1.messages) in
538+ (trace1.position, EcEco. { goal; messages; })
539+ in List. rev_map mktrace1 trace in
540+
541+ EcEco. {
504542 eco_root = EcEco. {
505543 eco_digest = Digest. file input;
506544 eco_kind = kind;
@@ -513,6 +551,7 @@ let main () =
513551 eco_kind = x.rqd_kind;
514552 } in (x.rqd_name, (ecr, x.rqd_direct)))
515553 (EcScope.Theory. required scope));
554+ eco_trace = Option. map mktrace state.trace;
516555 } in
517556
518557 let out = open_out nameo in
@@ -589,7 +628,10 @@ let main () =
589628 EcScope. hierror " invalid pragma: `%s'\n %!" x);
590629
591630 let notifier (lvl : EcGState.loglevel ) (lazy msg ) =
592- T. notice ~immediate: true lvl msg terminal
631+ state.trace < - state.trace |> Option. map (fun trace ->
632+ State.Trace. push_message trace (lvl, msg)
633+ );
634+ T. notice ~immediate: true lvl msg terminal;
593635 in
594636
595637 EcCommands. addnotifier notifier;
@@ -617,8 +659,30 @@ let main () =
617659 let timed = p.EP. gl_debug = Some `Timed in
618660 let break = p.EP. gl_debug = Some `Break in
619661 let ignore_fail = ref false in
662+
663+ state.trace < - state.trace |> Option. map (fun trace ->
664+ { State.Trace. trace0 with position = loc.loc_echar } :: trace
665+ );
666+
620667 try
621668 let tdelta = EcCommands. process ~timed ~break p.EP. gl_action in
669+
670+ state.trace < - state.trace |> Option. map (fun trace ->
671+ match trace with
672+ | [] -> assert false
673+ | trace1 :: trace ->
674+ assert (Option. is_none trace1.State. goal);
675+ let goal =
676+ let buffer = Buffer. create 0 in
677+ Format. fprintf
678+ (Format. formatter_of_buffer buffer)
679+ " %t@?" (EcCommands. pp_current_goal ~all: false );
680+ Buffer. contents buffer in
681+ let goal = if String. is_empty goal then None else Some goal in
682+ let trace1 = { trace1 with goal } in
683+ trace1 :: trace
684+ );
685+
622686 if p.EP. gl_fail then begin
623687 ignore_fail := true ;
624688 raise (EcScope. HiScopeError (None , " this command is expected to fail" ))
@@ -636,10 +700,10 @@ let main () =
636700 raise (EcScope. toperror_of_exn ~gloc: loc e)
637701 end ;
638702 if T. interactive terminal then begin
639- let error =
640- Format. asprintf
641- " The following error has been ignored:@.@.@%a"
642- EcPException. exn_printer e in
703+ let error =
704+ Format. asprintf
705+ " The following error has been ignored:@.@.@%a"
706+ EcPException. exn_printer e in
643707 T. notice ~immediate: true `Info error terminal
644708 end
645709 end )
0 commit comments