1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
(****************************************************************************)
(* the diy toolsuite *)
(* *)
(* Jade Alglave, University College London, UK. *)
(* Luc Maranget, INRIA Paris-Rocquencourt, France. *)
(* *)
(* Copyright 2012-present Institut National de Recherche en Informatique et *)
(* en Automatique and the authors. All rights reserved. *)
(* *)
(* This software is governed by the CeCILL-B license under French law and *)
(* abiding by the rules of distribution of free software. You can use, *)
(* modify and/ or redistribute the software under the terms of the CeCILL-B *)
(* license as circulated by CEA, CNRS and INRIA at the following URL *)
(* "http://www.cecill.info". We also give a copy in LICENSE.txt. *)
(****************************************************************************)
(* Extract name: cycle from test(s) *)
open Printf
type cycle = One of string | Norm of string * string
let get_cycle info =
let orig =
try Some (List.assoc "Orig" info)
with Not_found -> None
and cycle =
try Some (List.assoc "Cycle" info)
with Not_found -> None in
match orig,cycle with
| Some o,Some c -> Norm (o,c)
| None,Some c
| Some c,None -> One c
| None,None -> raise Not_found
let get_scope info =
try Some (List.assoc "Scopes" info)
with Not_found -> None
let from_splitted splitted =
let name = splitted.Splitter.name
and info = splitted.Splitter.info in
name.Name.name,get_cycle info,get_scope info
module SP = Splitter.Make(Splitter.Default)
let from_file name =
let sp = Misc.input_protect (SP.split name) name in
from_splitted sp
(* Command line *)
let arg = ref []
let prog =
if Array.length Sys.argv > 0 then Sys.argv.(0)
else "mcycles"
let () =
Arg.parse
[]
(fun s -> arg := s :: !arg)
(sprintf "Usage: %s [test]*" prog)
let tests = !arg
module S =
MySet.Make
(struct
type t = string * string option
let compare x y =
Misc.pair_compare
String.compare
(Misc.opt_compare String.compare)
x y
end)
let seen = ref S.empty
let ppo = function
| None -> ""
| Some s -> " " ^ s
let () =
Misc.iter_argv_or_stdin
(fun name ->
try
let tname,cycle,st = from_file name in
match cycle with
| One c ->
printf "%s: %s%s\n" tname c (ppo st)
| Norm (o,c) ->
let k = c,st in
if not (S.mem k !seen) then begin
seen := S.add k !seen ;
printf "%s: %s%s\n" tname o (ppo st)
end
with
| Not_found -> Warn.warn_always "%s: no cycle" name
| Misc.Exit -> ()
| Misc.Fatal msg|Misc.UserError msg ->
Warn.warn_always "%a %s" Pos.pp_pos0 name msg
| e ->
Printf.eprintf "\nFatal: %a Adios\n" Pos.pp_pos0 name ;
raise e)
tests
|