Files
mercury/slice/mtc_union.m
Zoltan Somogyi 3c07fc2121 Use explicit streams in deep_profiler/*.m.
deep_profiler/analysis_utils.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/autopar_search_goals.m:
deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/cliques.m:
deep_profiler/coverage.m:
deep_profiler/dump.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
deep_profiler/profile.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/startup.m:
deep_profiler/var_use_analysis.m:
    Replace implicit streams with explicit streams.

    In some places, simplify some code, often using constructs such as
    string.format that either did not exist or were too expensive to use
    when the original code was written.

    Consistenly use the spelling StdErr over Stderr.

    In mdbprof_dump.m, put filename and reason-for-failing-to-open-that-file
    in the right order in an error message.

deep_profiler/DEEP_FLAGS.in:
    Turn on --warn-implicit-stream-calls for the entire deep_profiler
    directory.

mdbcomp/program_representation.m:
mdbcomp/trace_counts.m:
    Replace implicit streams with explicit streams. These are the two mdbcomp
    modules that (a) used to use implicit streams, and (2) are used by the
    deep profiler.

mdbcomp/Mercury.options:
    Turn on --warn-implicit-stream-calls for these two modules.

slice/mcov.m:
slice/mtc_union.m:
    Conform to the changes in mdbcomp.
2021-03-06 18:30:50 +11:00

128 lines
4.3 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 expandtab
%-----------------------------------------------------------------------------%
% Copyright (C) 2005-2006, 2012 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% File: mtc_union.m.
% Main Author: Ian MacLarty.
%
% A tool to combine several trace counts into one.
%
%-----------------------------------------------------------------------------%
:- module mtc_union.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module mdbcomp.
:- import_module mdbcomp.shared_utilities.
:- import_module mdbcomp.trace_counts.
:- import_module bool.
:- import_module getopt.
:- import_module list.
:- import_module map.
:- import_module maybe.
:- import_module set.
:- import_module string.
%-----------------------------------------------------------------------------%
main(!IO) :-
io.stdout_stream(StdOutStream, !IO),
io.stderr_stream(StdErrStream, !IO),
unlimit_stack(!IO),
io.command_line_arguments(Args0, !IO),
OptionOps = option_ops_multi(short_option, long_option, option_default),
getopt.process_options(OptionOps, Args0, Args, GetoptResult),
(
GetoptResult = ok(OptionTable),
lookup_string_option(OptionTable, output_filename, OutputFile),
( if
Args = [_ | _],
OutputFile \= ""
then
lookup_bool_option(OptionTable, verbose, Verbose),
(
Verbose = yes,
ShowProgress = yes(StdOutStream)
;
Verbose = no,
ShowProgress = no
),
read_and_union_trace_counts(ShowProgress, Args, NumTests, Kinds,
TraceCounts, MaybeReadError, !IO),
(
MaybeReadError = yes(ReadErrorMsg),
io.write_string(StdErrStream, ReadErrorMsg, !IO),
io.nl(StdErrStream, !IO)
;
MaybeReadError = no,
Type = union_file(NumTests, set.to_sorted_list(Kinds)),
write_trace_counts_to_file(Type, TraceCounts, OutputFile,
WriteResult, !IO),
(
WriteResult = ok
;
WriteResult = error(WriteErrorMsg),
io.write_string(StdErrStream,
"Error writing to file `" ++ OutputFile ++ "'" ++
": " ++ string(WriteErrorMsg), !IO),
io.nl(StdErrStream, !IO)
)
)
else
usage(StdOutStream, !IO)
)
;
GetoptResult = error(GetoptError),
GetoptErrorMsg = option_error_to_string(GetoptError),
io.format(StdOutStream, "%s\n", [s(GetoptErrorMsg)], !IO)
).
:- pred usage(io.text_output_stream::in, io::di, io::uo) is det.
usage(OutStream, !IO) :-
io.write_strings(OutStream, [
"Usage: mtc_union [-v] -o output_file file1 file2 ...\n",
"The -v or --verbose option causes each trace count file name\n",
"to be printed as it is added to the union.\n",
"file1, file2, etc should be trace count files.\n"],
!IO).
%-----------------------------------------------------------------------------%
:- type option
---> output_filename
; verbose.
:- type option_table == option_table(option).
:- pred short_option(character::in, option::out) is semidet.
short_option('o', output_filename).
short_option('v', verbose).
:- pred long_option(string::in, option::out) is semidet.
long_option("out", output_filename).
long_option("verbose", verbose).
:- pred option_default(option::out, option_data::out) is multi.
option_default(output_filename, string("")).
option_default(verbose, bool(no)).
%-----------------------------------------------------------------------------%