-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbisect_driver
More file actions
executable file
·100 lines (76 loc) · 2.56 KB
/
bisect_driver
File metadata and controls
executable file
·100 lines (76 loc) · 2.56 KB
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
#!/usr/bin/env bash
# Copyright (c) 2020 Matt Windsor and contributors
#
# This file is part of c4-scripts.
# Licenced under the MIT licence; see `LICENSE`.
# Runs all of the various single-shot binaries of c4t in a pipeline, but
# in a way that is amenable to use as a bisection driver.
set -euo pipefail
SCRIPTDIR="${SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"}"
readonly SCRIPTDIR
# shellcheck source=act_bash/args.sh
source "${SCRIPTDIR}/act_bash/args.sh"
# shellcheck source=act_bash/log.sh
source "${SCRIPTDIR}/act_bash/log.sh"
# shellcheck source=act_bash/naming.sh
source "${SCRIPTDIR}/act_bash/naming.sh"
## Variables ##
# The name of the output directory.
# If empty, we use a temporary directory.
OUTPUT_DIR=""
# The ID of the machine to run.
MACHINE="localhost"
# The ID of the compiler to run.
COMPILER="gcc"
# The opt of the compiler to run.
OPT=""
# The mopt of the compiler to run.
MOPT=""
# Whether or not verbose logging is enabled.
VERBOSE="false"
## Functions ##
# Prints the script's usage and exits.
usage() {
echo "usage: $0 [-d DIR] [-m MACHINE] [-c COMPILER] [-O OPT] [-M OPT] [-${ACT_STANDARD_FLAGS}] FILES..." >&2
echo
echo "-d: directory to use for outputting intermediate files"
echo "-m: ID of machine to use"
echo "-O: optimisation level to use"
echo "-M: machine optimisation profile to use"
act::standard_usage
exit 1
}
# Runs the c4t pipeline needed for bisection.
run() {
local plan="${OUTPUT_DIR}/plan.orig.json"
local pplan="${OUTPUT_DIR}/plan.setc.json"
local lplan="${OUTPUT_DIR}/plan.lifted.json"
local oplan="${OUTPUT_DIR}/plan.out.json"
c4t-plan -m "${MACHINE}" -c "${COMPILER}" "$@" > "${plan}"
c4t-setc -c "${COMPILER}" --opt-level "${OPT}" --machine-opt "${MOPT}" "${plan}" > "${pplan}"
c4t-lift -d "${OUTPUT_DIR}/lift" "${pplan}" > "${lplan}"
c4t-invoke -d "${OUTPUT_DIR}/compile" -t 20s -T 10s "${lplan}" > "${oplan}"
c4t-analyse -e "${oplan}"
}
# The main function.
main() {
while getopts "d:m:c:O:M:qvx?h" a; do
case "${a}" in
d) OUTPUT_DIR="${OPTARG}" ;;
m) MACHINE="${OPTARG}" ;;
c) COMPILER="${OPTARG}" ;;
O) OPT="${OPTARG}" ;;
M) MOPT="${OPTARG}" ;;
*) act::parse_standard_args "${a}" "${OPTARG:-}" ;;
esac
done
# VERBOSE etc. are used indirectly by various library functions.
# shellcheck disable=SC2034
readonly VERBOSE FUZZ MACHINE
shift $((OPTIND-1))
if [[ $# -lt 1 ]]; then act::arg_error "need at least one file argument"; fi
if [[ -z ${OUTPUT_DIR} ]]; then act::setup_temp_output_dir; fi
readonly OUTPUT_DIR
run "$@"
}
main "$@"