-
Notifications
You must be signed in to change notification settings - Fork 10
Adding Fortran call graph collector #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gomfol12
wants to merge
130
commits into
tudasc:devel
Choose a base branch
from
gomfol12:fortran_collector
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
130 commits
Select commit
Hold shift + click to select a range
f1d3ddb
add/modified cmakefiles to add cgfcollector subproject
gomfol12 828ac1f
WIP: add simple function parsing and integrated graphlib
gomfol12 1171889
add wrapper and simple test script
gomfol12 7a75d16
add main function mangling for fortran to correctly identify main fun…
gomfol12 ea1f6b5
add simple test case 1
gomfol12 dfd7789
added test case using a module
gomfol12 c96cab8
fix typo in CMakeLists.txt and add precompiled headers
gomfol12 0a6f06a
rework main to construct CG and set hasBody property accordingly
gomfol12 adbfaf6
tests now ignore _MetaCG part in json file
gomfol12 7cc5b80
update simple_01 test for MetaCG format version 3
gomfol12 8806ae2
add some tests
gomfol12 d29fb75
tests ignore the origin field as this differ from machines
gomfol12 4067750
nesting test for calls with %
gomfol12 c67d045
function calls with % are now correctly parsed and generate dot files…
gomfol12 25cfa21
WIP: impl parsing for function overriding in derived types. And broke…
gomfol12 b0ac1f1
fix and cleanup the ProcedureDesignator parsing
gomfol12 2df288f
add -dot option to configure .dot generation
gomfol12 7d80405
more tests
gomfol12 7e59c70
WIP: impl finalizers parsing. Still overestimates
gomfol12 43df1b3
fix: problem with deferred keyword in abstract type where edges where…
gomfol12 555a4d1
simple 05 add output.json
gomfol12 55188a8
impl operator overloading parsing, WIP: defined operator parsing
gomfol12 8eeaab0
better test case for operator overloading and defined operators
gomfol12 7d4bcef
better test case for finalizers
gomfol12 a8cd7ab
tests: impl dedicated CG compare tool using node names to compare CGs…
gomfol12 208bb6d
add cmake managed tests for multi file tests
gomfol12 1d91598
renamed test case 6 to operator
gomfol12 b88ca44
add basic README.md for cgfcollector
gomfol12 087feb0
move some files in the tools directory
gomfol12 055cfdb
more tests (function_test and math_demo)
gomfol12 d700acd
WIP: commit
gomfol12 3aa2ed5
WIP: normal operator parsing now working, operator in interfaces are …
gomfol12 a72078c
refactor: move ParseTreeVisitor into its own file
gomfol12 2f727a0
fix operator and improved operator test
gomfol12 417afc8
destructor now handeling the allocatable case with assignments
gomfol12 21af625
extended parsing and test for destructors for fix assignment(=), allo…
gomfol12 0d232fd
renamed 03 test to final
gomfol12 20af78c
improved logging for debugging and fixes for destructor handling
gomfol12 2cad8c9
impl destructor handling for function arguments without allocatable attr
gomfol12 0f12aa9
test final simplified
gomfol12 31fd832
test final2 for finalizers with function arguments without allocatabl…
gomfol12 96188ef
impl entry and add test case
gomfol12 ded841d
renamed 01, 03 and 05 test cases to more descriptive names
gomfol12 e2f6bb1
add generic interface test
gomfol12 8aa4ef7
removed cmake_base.txt
gomfol12 bc22ca8
simplified cmake tests
gomfol12 98b3f5a
add output.json for multi_02 test
gomfol12 68a1208
renamed multi_02 test to multi_deps
gomfol12 fcd93ae
add interop tests
gomfol12 2d0bfdf
destructor handling with static lifetimes and test
gomfol12 944b82f
additional finalizer test
gomfol12 54baf9a
CMakeLists -g commend
gomfol12 acba642
improved variable tracking, impl handling of allocatable trough funct…
gomfol12 fe2afa3
more consistent function naming scheme
gomfol12 1412446
some fixes for destructor with allocatable vars and test
gomfol12 9a75d45
some code cleanup regarding operators
gomfol12 89489c4
add more operator tests
gomfol12 9955ae7
operator: improved interface operators and can now distinguish betwee…
gomfol12 88a522e
remove typedef we are in c++
gomfol12 c9ba370
add cmake_base.txt to .gitignore
gomfol12 e3a1317
comments
gomfol12 703159f
improved CMakeLists.txt to make it more readable and now using differ…
gomfol12 2219eac
add test case with fortdepend to generate fortran module dependencies
gomfol12 08c08b0
add fortran test file config for cmake and make to .gitignore
gomfol12 5795faf
add script to act as normal compiler that also generates CG
gomfol12 4976a16
updated README.md
gomfol12 814bbf2
add partial test examples for function pointer and unlimited polymorp…
gomfol12 9cdd2dc
update to new metacg version
gomfol12 9a9e217
fix test runner for fortdepend test
gomfol12 d00e1c0
update test metacg format version 3 -> 4
gomfol12 d9ef4a8
swaped insert with getOrInsertNode to only insert nodes with unique n…
gomfol12 c4a93c0
remove unnecessary includes
gomfol12 cf4c179
add FlangLLVM.cmake for correctly linking flang
gomfol12 6eb082a
fix comp_wrapper and add filtering for files in options
gomfol12 b2db55a
flang_bin can now be set throw env var
gomfol12 d9e4fd4
don't link against flangFrontendTool
gomfol12 8336e49
main more consistant output filenames and new norename plugin for cma…
gomfol12 760c9dd
update tests to reflect main changes
gomfol12 c9a6012
add norename option to wrapper script
gomfol12 38345a0
compiler wrapper now correctly filters options and also extract optio…
gomfol12 975dd0b
comp wrapper fix -o parsing
gomfol12 732245f
fix for crash in expr's in specification part of module
gomfol12 a5997d0
more consistent mangling, adjusted tests and fix typo
gomfol12 b908c7e
FlangLLVM.cmake added required clang package
gomfol12 7424f19
fix cgManager wrong usage
gomfol12 9d933f4
test_runner.sh now count test cases run and failed
gomfol12 b0c3c8e
add empty tests
gomfol12 dc031f2
reenabled underscoring for mangling
gomfol12 5fc9a3d
cgfcollector_comp_wrapper ignore -fPIC for flang -fc1 call
gomfol12 f9e0ce0
add missing _ to some function names
gomfol12 75a373b
extract info from use definition for derived types and add some tests
gomfol12 59fad1b
forget to rename test files
gomfol12 023fb4d
fixed origin field in multi operator and use tests
gomfol12 ad4c820
add collection of interface operators from use statement. Same idea a…
gomfol12 6344fba
add comment
gomfol12 150a245
fix test runner: some failed test got not counted as failed
gomfol12 190c85c
fix GenericDetails restrict to only IsIntrinsicOperator and fix typo
gomfol12 1256b80
types array missing extendsfrom entry add more descriptive error msg
gomfol12 aa03b59
fix: i am now collecting type though the inheritance structure correc…
gomfol12 4a0ba22
getFileEntry for llvm > 18
gomfol12 d4d5be5
moved compareSymbols, mangleSymbol to util file
gomfol12 1dde341
refactor
gomfol12 12f988d
refactor
gomfol12 13d762c
refactor
gomfol12 998274c
add documentation
gomfol12 3a48582
refactor and add documentation
gomfol12 9a76262
use function struct for currentFunctions vector
gomfol12 56458a2
doc and refector
gomfol12 0c9782c
refactor in individual files
gomfol12 f269343
variableTracking doc
gomfol12 f9a31bc
ParseTreeVisitor more doc
gomfol12 2570939
edgeManager refactor
gomfol12 e5ef515
edgeManager refactor
gomfol12 4e7ace6
rename type typeSymbol
gomfol12 1130db0
change to remove in handleTrackedVars
gomfol12 35f7387
removed const_cast and resolved auto for clarity
gomfol12 9efa7ac
add doc in tool scripts
gomfol12 e743f97
updated cgfcollector README
gomfol12 c092fcf
removed duplicate comment
gomfol12 b5503fc
cmake uncomment/removed lines
gomfol12 3e8de05
README: add context and fix typo
gomfol12 9c912e5
migration: CGCompare to CGDiff
gomfol12 d84aef7
removed CGCompare
gomfol12 2d0dfdd
simplify test script and integrate in cmake
gomfol12 9602d67
cmake add flangFrontendTool find
gomfol12 2570553
Filename capitalization and license headers
gomfol12 59e8b74
removed using namespace from header files and project-local includes …
gomfol12 056dfe6
use upper case type names
gomfol12 ed5d7ff
comment style
gomfol12 a5f9ffe
Consistent naming for cgfcollector
gomfol12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| set(PROJECT_NAME cgfcollector) | ||
| set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-target) | ||
|
|
||
| file( | ||
| GLOB | ||
| CGFCOLLECTOR_SOURCES | ||
| src/*.cpp | ||
| ) | ||
|
|
||
| add_library(${PROJECT_NAME} SHARED ${CGFCOLLECTOR_SOURCES}) | ||
| add_flang(${PROJECT_NAME}) | ||
| add_metacg(${PROJECT_NAME}) | ||
| add_spdlog_libraries(${PROJECT_NAME}) | ||
|
|
||
| target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
|
||
| install( | ||
| TARGETS ${PROJECT_NAME} | ||
| EXPORT ${TARGETS_EXPORT_NAME} | ||
| LIBRARY DESTINATION lib | ||
| ARCHIVE DESTINATION lib | ||
| ) | ||
|
|
||
| configure_package_config_file( | ||
| ${METACG_Directory}/cmake/Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake | ||
| INSTALL_DESTINATION lib/cmake | ||
| ) | ||
|
|
||
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake DESTINATION lib/cmake) | ||
|
|
||
| # visuel program to generate dot file from graph | ||
| add_executable(${PROJECT_NAME}-visuel ${CMAKE_CURRENT_SOURCE_DIR}/tools/visuel.cpp) | ||
| add_metacg(${PROJECT_NAME}-visuel) | ||
| add_spdlog_libraries(${PROJECT_NAME}-visuel) | ||
| install( | ||
| TARGETS ${PROJECT_NAME}-visuel | ||
| LIBRARY DESTINATION bin | ||
| ARCHIVE DESTINATION bin | ||
| ) | ||
|
|
||
| # generate wrapper scripts | ||
|
|
||
| function( | ||
| configure_file_and_install | ||
| TEMPLATE | ||
| OUTPUT_BASENAME | ||
| DESTINATION | ||
| ) | ||
| set(BUILD_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_BASENAME}") | ||
| set(INSTALL_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_BASENAME}.install") | ||
|
|
||
| # build-time values for development | ||
| set(CGFCOLLECTOR_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.so") | ||
| set(CGFCOLLECTOR_CGDIFF "${CMAKE_BINARY_DIR}/tools/cgdiff/cgdiff") | ||
| set(CGFCOLLECTOR_WRAPPER "${CMAKE_CURRENT_BINARY_DIR}/cgfcollector_wrapper.sh") | ||
| set(CGFCOLLECTOR_TEST_CASES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test") | ||
| set(CGMERGE2_EXECUTABLE "${CMAKE_BINARY_DIR}/tools/cgmerge2/cgmerge2") | ||
|
|
||
| configure_file( | ||
| "${TEMPLATE}" | ||
| "${BUILD_OUTPUT}" | ||
| @ONLY | ||
| ) | ||
|
|
||
| if(DESTINATION | ||
| STREQUAL | ||
| "" | ||
| ) | ||
| return() | ||
| endif() | ||
|
|
||
| # install-time values | ||
| set(CGFCOLLECTOR_FILE_NAME "${CMAKE_INSTALL_PREFIX}/lib/lib${PROJECT_NAME}.so") | ||
|
|
||
| configure_file( | ||
| "${TEMPLATE}" | ||
| "${INSTALL_OUTPUT}" | ||
| @ONLY | ||
| ) | ||
|
|
||
| install( | ||
| PROGRAMS "${INSTALL_OUTPUT}" | ||
| DESTINATION "${DESTINATION}" | ||
| RENAME "${OUTPUT_BASENAME}" | ||
| ) | ||
| endfunction() | ||
|
|
||
| configure_file_and_install( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/tools/cgfcollector_wrapper.sh.in" | ||
| "cgfcollector_wrapper.sh" | ||
| "bin" | ||
| ) | ||
|
|
||
| configure_file_and_install( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/tools/cgfcollector_comp_wrapper.sh.in" | ||
| "cgfcollector_comp_wrapper.sh" | ||
| "bin" | ||
| ) | ||
|
|
||
| configure_file_and_install( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/tools/test_runner.sh.in" | ||
| "test_runner.sh" | ||
| "" | ||
| ) | ||
|
|
||
| configure_file_and_install( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/test/multi/cmake_base.txt.in" | ||
| "cmake_base.txt" | ||
| "" | ||
| ) | ||
| file( | ||
| RENAME | ||
| "${CMAKE_CURRENT_BINARY_DIR}/cmake_base.txt" | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/test/multi/cmake_base.txt" | ||
| ) | ||
|
|
||
| configure_file_and_install( | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/test/multi/make_base.in" | ||
| "make_base" | ||
| "" | ||
| ) | ||
| file( | ||
| RENAME | ||
| "${CMAKE_CURRENT_BINARY_DIR}/make_base" | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/test/multi/make_base" | ||
| ) | ||
|
|
||
| # tests | ||
| add_test(NAME cgfcollector_tests COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_runner.sh) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # CG Fortran collector | ||
|
|
||
| Fortran call graph generation tool for MetaCG. This tool is implemented as a | ||
| Flang plugin and generates a call graph from source-level. | ||
|
|
||
| ## Usage | ||
|
|
||
| For single file projects or projects not using modules use: | ||
|
|
||
| ```sh | ||
| cgfcollector_wrapper.sh <source file/s> | ||
| ``` | ||
|
|
||
| For any other projects you need a build system. For this we provide another | ||
| script that acts as the normal Flang compiler but also produces a call graph. | ||
| [More info below](#generate-a-call-graph). | ||
|
|
||
| ```sh | ||
| cgfcollector_comp_wrapper.sh <source file/s> | ||
| ``` | ||
|
|
||
| You can also run the plugin directly with Flang: | ||
|
|
||
| ```sh | ||
| flang -fc1 -load "libcgfcollector.so" -plugin "genCG" | ||
| ``` | ||
|
|
||
| There are three kinds of plugins: | ||
|
|
||
| - `genCG`: generates a call graph in the MetaCG json format. | ||
| - `genCGwithDot`: like `genCG` but also generate a `.dot` file. Mostly used for debugging. | ||
| - `genCGNoRename`: like `genCG` but does not rename the output file. | ||
|
|
||
| Additionally these other tools are included: | ||
|
|
||
| - `cgfcollector_wrapper.sh`: convenience wrapper to run parse plugin. | ||
| - `cgfcollector_comp_wrapper.sh`: acts like a normal Flang compiler but also generates a call graph. | ||
| - `test_runner.sh`: run tests. | ||
|
|
||
| ## How to build | ||
|
|
||
| To build the cgfcollector the option `METACG_BUILD_CGFCOLLECTOR` must be set to | ||
| `ON`. | ||
|
|
||
| ## Generate a call graph | ||
|
|
||
| ### from a CMake project | ||
|
|
||
| Paste this into your CMakeLists.txt. | ||
|
|
||
| ``` | ||
| set(CMAKE_Fortran_COMPILER <path to cgfcollector_wrapper.sh>) | ||
| set(CMAKE_Fortran_FLAGS "") | ||
| set(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> -dot <DEFINES> <INCLUDES> <FLAGS> <SOURCE> -o <OBJECT>") | ||
| set(CMAKE_Fortran_LINK_EXECUTABLE "<path to cgmerge2> <TARGET> <OBJECTS>") | ||
| set(CMAKE_EXECUTABLE_SUFFIX .json) | ||
| ``` | ||
|
|
||
| This will hook into the CMake build process and generate a call graph instead of | ||
| an executable. | ||
|
|
||
| An example can be found in `test/multi/deps`. | ||
|
|
||
| ### from other projects | ||
|
|
||
| Use `cgfcollector_comp_wrapper.sh` or `cgfcollector_wrapper.sh` to hook into the | ||
| build process of your favorite tool and use the `cgmerge2` utility to merge the | ||
| partial generated call graphs. | ||
|
|
||
| An example can be found in `test/multi/fortdepend_deps`. This example uses | ||
| fortdepend to generate a module dependency list. If your build system already | ||
| generates such a list and executes the compiler on the files in the correct order | ||
| you probably don't need this. | ||
|
|
||
| ## Running test | ||
|
|
||
| run `test_runner.sh` | ||
|
|
||
| NOTE: The test `test/multi/fortdepend_deps` has a dependency on [fortdepend](https://fortdepend.readthedocs.io/en/latest/) | ||
|
|
||
| ## Debugging | ||
|
|
||
| ### print parse tree | ||
|
|
||
| ```sh | ||
| flang-new -fc1 -fdebug-dump-parse-tree file.f90 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * File: Edge.h | ||
| * License: Part of the MetaCG project. Licensed under BSD 3 clause license. See LICENSE.txt file at | ||
| * https://github.com/tudasc/metacg/LICENSE.txt | ||
| */ | ||
|
|
||
| #pragma once | ||
gomfol12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include "FortranUtil.h" | ||
| #include "Type.h" | ||
|
|
||
| #include <LoggerUtil.h> | ||
| #include <flang/Parser/parse-tree.h> | ||
| #include <flang/Semantics/symbol.h> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| struct Edge { | ||
| std::string caller; | ||
| std::string callee; | ||
|
|
||
| Edge(std::string caller, std::string callee) : caller(std::move(caller)), callee(std::move(callee)) {} | ||
|
|
||
| bool operator==(const Edge& other) const { return caller == other.caller && callee == other.callee; } | ||
| bool operator<(const Edge& other) const { | ||
| return caller < other.caller || (caller == other.caller && callee < other.callee); | ||
| } | ||
| }; | ||
|
|
||
| struct EdgeSymbol { | ||
| const Fortran::semantics::Symbol* caller; | ||
| const Fortran::semantics::Symbol* callee; | ||
|
|
||
| EdgeSymbol(const Fortran::semantics::Symbol* caller, const Fortran::semantics::Symbol* callee) | ||
| : caller(caller), callee(callee) {} | ||
|
|
||
| bool operator==(const EdgeSymbol& other) const { return caller == other.caller && callee == other.callee; } | ||
| bool operator<(const EdgeSymbol& other) const { | ||
| return caller < other.caller || (caller == other.caller && callee < other.callee); | ||
| } | ||
| }; | ||
|
|
||
| struct EdgeManager { | ||
| std::vector<Edge>& edges; | ||
|
|
||
| EdgeManager(std::vector<Edge>& edges) : edges(edges) {} | ||
|
|
||
| void addEdge(const EdgeSymbol& e, bool debug = true); | ||
| void addEdge(const Fortran::semantics::Symbol* caller, const Fortran::semantics::Symbol* callee, bool debug = true); | ||
| void addEdge(const Edge& e, bool debug = true); | ||
| void addEdge(const std::string& caller, const std::string& callee, bool debug = true); | ||
| void addEdges(const std::vector<Edge>& newEdges, bool debug = true); | ||
| void addEdges(const std::vector<EdgeSymbol>& newEdges, bool debug = true); | ||
|
|
||
| /** | ||
| * @brief For a given symbol, returns a list of edges from the current function to all finalizers of that type. | ||
| * | ||
| * @param types | ||
| * @param currentFunctionSymbol | ||
| * @param symbol | ||
| */ | ||
| std::vector<EdgeSymbol> getEdgesForFinalizers(const std::vector<Type>& types, | ||
| const Fortran::semantics::Symbol* currentFunctionSymbol, | ||
| const Fortran::semantics::Symbol* symbol); | ||
| /** | ||
| * @brief Calls getEdgesForFinalizers and adds them to the edges vector. | ||
| * | ||
| * @param types | ||
| * @param currentFunctionSymbol | ||
| * @param symbol | ||
| */ | ||
| void addEdgesForFinalizers(const std::vector<Type>& types, const Fortran::semantics::Symbol* currentFunctionSymbol, | ||
| const Fortran::semantics::Symbol* symbol); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.