Skip to content

Commit

Permalink
Add some logic to automatically find the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeekman committed Dec 14, 2024
1 parent ce2f564 commit 51c594f
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/fparse-llvm.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ set -o pipefail
#set -o verbose
#set -o xtrace

readonly _VERSION=@SALT_VERSION_MAJOR@.@SALT_VERSION_MINOR@
readonly _FORTRAN_CONFIG_FILE_BUILD=@CMAKE_SOURCE_DIR@/config_files/tau_fortran_config.yaml
readonly _FORTRAN_CONFIG_FILE_INSTALL=@SALT_CONFIGFILES_INSTALL_DIR@/tau_fortran_config.yaml
readonly _INSTALL_DEST=@CMAKE_INSTALL_PREFIX@

# get the absolute path of this script
readonly _SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check if the script is being run from the install directory
if [[ -f "${_SCRIPT_DIR}/$0" && "${_SCRIPT_DIR}" == ${_INSTALL_DEST}* ]]; then
FORTRAN_CONFIG_FILE="${_FORTRAN_CONFIG_FILE_INSTALL}"
else
FORTRAN_CONFIG_FILE="${_FORTRAN_CONFIG_FILE_BUILD}"
fi

# Add a help/usage message function
function usage {
echo "Usage: $0 [-h] [-o output_file] [-show] input_file [args]"
Expand Down Expand Up @@ -69,6 +83,10 @@ for arg in "$@"; do
show=true
shift || true
#echo "args remaining: $*"
elif [[ $arg == --config_file=* ]]; then
FORTRAN_CONFIG_FILE="${arg#--config_file=}"
shift || true
#echo "args remaining: $*"
elif [[ -n ${arg:-} ]]; then
args+=("${arg}")
shift || true
Expand Down Expand Up @@ -104,11 +122,19 @@ echo "output file: ${output_file:-\"<None given>\" }"
echo "Remaining Arguments: ${args[*]}"

# This script invokes an LLVM flang frontend plugin to parse and instrument Fortran code
cmd=(flang-new -fc1 -load ./libsalt-flang-plugin.so -plugin salt-instrument "${input_file}" -o "${output_file}" "${args[@]}")
cmd=(flang-new
-fc1
-load ./libsalt-flang-plugin.so
-plugin salt-instrument
"${input_file}"
-o "${output_file}"
"${args[@]}")
if $show; then
echo "SALT_FORTRAN_CONFIG_FILE=\"${FORTRAN_CONFIG_FILE}\""
echo "cmd: ${cmd[*]}"
else
echo "SALT_FORTRAN_CONFIG_FILE=\"${FORTRAN_CONFIG_FILE}\""
echo "Running: ${cmd[*]}"
"${cmd[@]}"
SALT_FORTRAN_CONFIG_FILE="${FORTRAN_CONFIG_FILE}" "${cmd[@]}"
exit $?
fi

0 comments on commit 51c594f

Please sign in to comment.