Skip to content

Commit

Permalink
Emit capitalized F file extensions for instrumented code
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeekman committed Dec 13, 2024
1 parent 35da0ac commit 6873bb1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -640,34 +640,44 @@ foreach(compiler IN LISTS fortran_compilers_to_test)
STRING(TOUPPER ${compiler} upper_comp)
add_test(NAME setup_${compiler}_dir
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${upper_comp})
set_tests_properties(setup_${compiler}_dir
PROPERTIES
FIXTURES_SETUP ${upper_comp}_dir
)
endforeach()

foreach(test_source IN LISTS FORTRAN_TESTS_SOURCES_LIST)
# Get the name of the instrumented source file
get_filename_component(TEST_BASE_NAME ${test_source} NAME_WLE)
get_filename_component(TEST_LANG ${test_source} LAST_EXT)
# fparse-llvm is adding preprocessor directives and should emit uppercase file extensions (e.g., .F90)
string(TOUPPER ${TEST_LANG} TEST_LANG)
set(TEST_INST_SOURCE ${TEST_BASE_NAME}.inst${TEST_LANG})

foreach(compiler IN LISTS fortran_compilers_to_test)
STRING(TOUPPER ${compiler} upper_comp)
if(${compiler} STREQUAL "gfortran")
set(mapped_comp GCC)
set(EXTRA_FLAGS -Wpedantic -Wextra -Wno-missing-include-dirs -Werror)
elseif(${compiler} STREQUAL "flang-new")
set(mapped_comp CLANG)
set(EXTRA_FLAGS -Werror)
elseif(${compiler} STREQUAL "flang")
set(mapped_comp CLANG)
set(EXTRA_FLAGS -Werror)
else()
message(FATAL_ERROR "Unknown compiler: ${compiler}")
endif()
add_test(NAME compile_${upper_comp}_${test_source}
COMMAND ${TAUF90} ${TAU_F90_OPTS} -o ${TEST_BASE_NAME} ${CMAKE_BINARY_DIR}/${TEST_INST_SOURCE}
COMMAND ${TAUF90} ${TAU_F90_OPTS} -o ${TEST_BASE_NAME} -Wall ${EXTRA_FLAGS} ${CMAKE_BINARY_DIR}/${TEST_INST_SOURCE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${upper_comp}
)
set_tests_properties(compile_${upper_comp}_${test_source}
PROPERTIES
ENVIRONMENT "TAU_MAKEFILE=${TAU_${mapped_comp}_MAKEFILE}"
DEPENDS "instrument_${test_source};setup_${compiler}_dir"
FAIL_REGULAR_EXPRESSION "[Ee]rror"
DEPENDS "instrument_${test_source}"
FIXTURES_REQUIRED ${upper_comp}_dir
FAIL_REGULAR_EXPRESSION "[^W][Ee]rror"
)
# Profile with TAU and Verify profiles are created
add_test(NAME run_${upper_comp}_${test_source}
Expand Down
4 changes: 2 additions & 2 deletions src/fparse-llvm.in
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ if [[ -z "${output_file:-}" ]]; then
file_ext=""
fi
if [[ "${input_file}" == */* ]]; then
output_file="${input_file%.*}.inst${file_ext}"
output_file="${input_file%.*}.inst${file_ext//f/F}"
output_file="$(pwd)/${output_file##*/}"
else
output_file="$(pwd)/${input_file%.*}.inst${file_ext}"
output_file="$(pwd)/${input_file%.*}.inst${file_ext//f/F}"
fi

fi
Expand Down
10 changes: 8 additions & 2 deletions src/salt_instrument_flang_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,18 @@ class SaltInstrumentAction final : public PluginParseTreeAction {
const InstrumentationMap instMap = getInstrumentationMap(yamlTree);

// Get the extension of the input file
// For input file 'filename.ext' we will output to 'filename.inst.ext'
// For input file 'filename.ext' we will output to 'filename.inst.Ext'
// Since we are adding preprocessor directives in the emitted code,
// the file extension should be capitalized.
std::string inputFileExtension;
if (auto const extPos = inputFilePath->find_last_of('.'); extPos == std::string::npos) {
inputFileExtension = "f90"; // Default if for some reason file has no extension
inputFileExtension = "F90"; // Default if for some reason file has no extension
} else {
inputFileExtension = inputFilePath->substr(extPos + 1); // Part of string past last '.'
// Capitalize the first character of inputFileExtension
if (!inputFileExtension.empty()) {
inputFileExtension[0] = std::toupper(inputFileExtension[0]);
}
}

// Open an output file for writing the instrumented code
Expand Down

0 comments on commit 6873bb1

Please sign in to comment.