Skip to content

Commit

Permalink
Add a usage message, handle return codes better & smoke test fparse-llvm
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeekman committed Dec 13, 2024
1 parent e870cc4 commit d2eba16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,15 @@ set(FORTRAN_TESTS_SOURCES_LIST
trivial.f90
)

# Add a smoke test of the fparse-llvm script
add_test(NAME fparse_llvm_smoke_test
COMMAND ${CMAKE_BINARY_DIR}/fparse-llvm -h)
set_tests_properties(fparse_llvm_smoke_test
PROPERTIES
LABELS smoke
PASS_REGULAR_EXPRESSION "Usage"
)

foreach(test_source IN LISTS FORTRAN_TESTS_SOURCES_LIST)
add_test(NAME instrument_${test_source}
COMMAND ./fparse-llvm ${CMAKE_SOURCE_DIR}/tests/fortran/${test_source}
Expand Down
24 changes: 22 additions & 2 deletions src/fparse-llvm.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,34 @@ set -o pipefail
#set -o verbose
#set -o xtrace

# Add a help/usage message function
function usage {
echo "Usage: $0 [-h] [-o output_file] [-show] input_file [args]"
echo " -h: print this help message and exit"
echo " -o output_file: specify the output file name"
echo " -show: print the command line without running it"
echo " input_file: the Fortran source file to parse and instrument"
echo " args: additional arguments to pass to the flang compiler (include flags etc.)"

}

if [[ $# -eq 0 ]]; then
usage
exit 1
fi

# Loop over the arguments and check for the output file -o flag and it's argument
# If found, set the output file name to the argument following the -o flag and remove the -o flag and argument from the argument list
# If not found, set the output file name to the first argument with a .inst extension
args=()
expecting_output_file=false
show=false
for arg in "$@"; do
echo "working on arg: $arg"
if $expecting_output_file; then
#echo "working on arg: $arg"
if [[ $arg == -h ]]; then
usage
exit 0
elif $expecting_output_file; then
output_file="$arg"
expecting_output_file=false
shift || true
Expand Down Expand Up @@ -91,4 +110,5 @@ if $show; then
else
echo "Running: ${cmd[*]}"
"${cmd[@]}"
exit $?
fi

0 comments on commit d2eba16

Please sign in to comment.