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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
(****************************************************************************)
(* 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. *)
(****************************************************************************)
(***************************************************)
(* Translate LISA fake dependencies into real ones *)
(***************************************************)
open Printf
module type Config = sig
val verbose : int
val sync : bool
val deref : bool
val check_name : string -> bool
end
module Make(Config:Config)(Out:OutTests.S) =
struct
module D = Splitter.Default
module LU = LexUtils.Make(D)
module S = Splitter.Make(D)
module OutStr = struct
type t = Buffer.t
let put_char b c = Buffer.add_char b c
let put b s = Buffer.add_string b s
end
module W = Warn.Make(Config)
module TR =
TrTrue.Make
(Config)
(OutStr)
let from_chan idx_out fname in_chan =
try
let { Splitter.locs = locs; start = start; name; arch; _} =
S.split fname in_chan in
if Config.check_name name.Name.name then begin
match arch with
| `LISA ->
let buff = Buffer.create 256 in
let
(_init_start,_init_end),
(code_start,_code_end as code_sec),
(constr_start,_constr_end),
(_last_start,loc_eof) = locs in
let echo sec =
let lexbuf = LU.from_section sec in_chan in
Echo.echo_fun lexbuf (Buffer.add_char buff) in
echo (start,code_start) ;
let ok = TR.tr buff (LU.from_section code_sec in_chan) in
if ok then begin
echo (constr_start,loc_eof) ;
let base = Filename.basename fname in
let out = Out.open_file base in
Misc.output_protect_close Out.close
(fun out ->
Out.fprintf out "%s" (Buffer.contents buff))
out ;
Out.fprintf idx_out "%s\n" base
end
| `C ->
let buff = Buffer.create 256 in
let _,_,_,(_,loc_eof) = locs in
let echo sec =
let lexbuf = LU.from_section sec in_chan in
Echo.echo_fun lexbuf (Buffer.add_char buff) in
echo (start,loc_eof) ;
let base = Filename.basename fname in
let out = Out.open_file base in
Misc.output_protect_close Out.close
(fun out ->
Out.fprintf out "%s" (Buffer.contents buff))
out ;
Out.fprintf idx_out "%s\n" base
| _ -> ()
end else begin
W.warn "%s: rejected by name" (Pos.str_pos0 fname)
end
with LexMisc.Error (msg,pos) ->
Printf.eprintf
"%a: Lex error %s (in %s)\n" Pos.pp_pos pos msg fname ;
raise Misc.Exit
let from_file idx_chan name =
try
Misc.input_protect
(fun in_chan -> from_chan idx_chan name in_chan)
name
with Misc.Exit -> ()
| Misc.Fatal msg|Misc.UserError msg ->
eprintf "Fatal error is not fatal, %s\n" msg
let from_args args =
let idx_out = Out.open_all () in
Misc.output_protect_close Out.close
(fun idx_out ->
Misc.iter_argv_or_stdin (from_file idx_out) args)
idx_out ;
Out.tar ()
end
(**********)
(* Driver *)
(**********)
let tar = ref None
and verbose = ref 0
and aarch64 = ref false
let names = ref []
let excl = ref []
let set_tar x = tar := Some x
let args = ref []
let opts =
[ "-v",
Arg.Unit (fun () -> incr verbose),
" be verbose";
"-o", Arg.String set_tar,
"<name> output to directory or tar file <name>" ;
"-aarch64",
Arg.Bool (fun b -> aarch64 := b),
sprintf "<bool> reduce tests for aarc64 (no deref, no sync) default %b" !aarch64;
CheckName.parse_names names ;
CheckName.parse_excl excl ;
]
let prog =
if Array.length Sys.argv > 0 then Sys.argv.(0)
else "recond"
let () =
Arg.parse opts
(fun a -> args := a :: !args)
(sprintf "Usage %s [options] [test]*" prog)
(* Read names *)
let from_args =
let module Check =
CheckName.Make
(struct
let verbose = !verbose
let rename = []
let select = []
let names = !names
let excl = !excl
end) in
let module X =
Make
(struct
let verbose = !verbose
let sync = false
let deref = !aarch64
let check_name = Check.ok
end) in
match !tar with
| None ->
let module Y = X(OutStd) in
Y.from_args
| Some _ as t ->
let module T =
OutTar.Make
(struct
let verbose = !verbose
let outname = t
end) in
let module Y = X(T) in
Y.from_args
let () = from_args !args
|