Skip to content
Open
Show file tree
Hide file tree
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 Feb 5, 2026
828ac1f
WIP: add simple function parsing and integrated graphlib
gomfol12 Feb 5, 2026
1171889
add wrapper and simple test script
gomfol12 Feb 5, 2026
7a75d16
add main function mangling for fortran to correctly identify main fun…
gomfol12 Feb 5, 2026
ea1f6b5
add simple test case 1
gomfol12 Feb 5, 2026
dfd7789
added test case using a module
gomfol12 Feb 5, 2026
c96cab8
fix typo in CMakeLists.txt and add precompiled headers
gomfol12 Feb 5, 2026
0a6f06a
rework main to construct CG and set hasBody property accordingly
gomfol12 Feb 5, 2026
adbfaf6
tests now ignore _MetaCG part in json file
gomfol12 Feb 5, 2026
7cc5b80
update simple_01 test for MetaCG format version 3
gomfol12 Feb 5, 2026
8806ae2
add some tests
gomfol12 Feb 5, 2026
d29fb75
tests ignore the origin field as this differ from machines
gomfol12 Feb 5, 2026
4067750
nesting test for calls with %
gomfol12 Feb 5, 2026
c67d045
function calls with % are now correctly parsed and generate dot files…
gomfol12 Feb 5, 2026
25cfa21
WIP: impl parsing for function overriding in derived types. And broke…
gomfol12 Feb 5, 2026
b0ac1f1
fix and cleanup the ProcedureDesignator parsing
gomfol12 Feb 5, 2026
2df288f
add -dot option to configure .dot generation
gomfol12 Feb 5, 2026
7d80405
more tests
gomfol12 Feb 5, 2026
7e59c70
WIP: impl finalizers parsing. Still overestimates
gomfol12 Feb 5, 2026
43df1b3
fix: problem with deferred keyword in abstract type where edges where…
gomfol12 Feb 5, 2026
555a4d1
simple 05 add output.json
gomfol12 Feb 5, 2026
55188a8
impl operator overloading parsing, WIP: defined operator parsing
gomfol12 Feb 5, 2026
8eeaab0
better test case for operator overloading and defined operators
gomfol12 Feb 5, 2026
7d4bcef
better test case for finalizers
gomfol12 Feb 5, 2026
a8cd7ab
tests: impl dedicated CG compare tool using node names to compare CGs…
gomfol12 Feb 5, 2026
208bb6d
add cmake managed tests for multi file tests
gomfol12 Feb 5, 2026
1d91598
renamed test case 6 to operator
gomfol12 Feb 5, 2026
b88ca44
add basic README.md for cgfcollector
gomfol12 Feb 5, 2026
087feb0
move some files in the tools directory
gomfol12 Feb 5, 2026
055cfdb
more tests (function_test and math_demo)
gomfol12 Feb 5, 2026
d700acd
WIP: commit
gomfol12 Feb 5, 2026
3aa2ed5
WIP: normal operator parsing now working, operator in interfaces are …
gomfol12 Feb 5, 2026
a72078c
refactor: move ParseTreeVisitor into its own file
gomfol12 Feb 5, 2026
2f727a0
fix operator and improved operator test
gomfol12 Feb 5, 2026
417afc8
destructor now handeling the allocatable case with assignments
gomfol12 Feb 5, 2026
21af625
extended parsing and test for destructors for fix assignment(=), allo…
gomfol12 Feb 5, 2026
0d232fd
renamed 03 test to final
gomfol12 Feb 5, 2026
20af78c
improved logging for debugging and fixes for destructor handling
gomfol12 Feb 5, 2026
2cad8c9
impl destructor handling for function arguments without allocatable attr
gomfol12 Feb 5, 2026
0f12aa9
test final simplified
gomfol12 Feb 5, 2026
31fd832
test final2 for finalizers with function arguments without allocatabl…
gomfol12 Feb 5, 2026
96188ef
impl entry and add test case
gomfol12 Feb 5, 2026
ded841d
renamed 01, 03 and 05 test cases to more descriptive names
gomfol12 Feb 5, 2026
e2f6bb1
add generic interface test
gomfol12 Feb 5, 2026
8aa4ef7
removed cmake_base.txt
gomfol12 Feb 5, 2026
bc22ca8
simplified cmake tests
gomfol12 Feb 5, 2026
98b3f5a
add output.json for multi_02 test
gomfol12 Feb 5, 2026
68a1208
renamed multi_02 test to multi_deps
gomfol12 Feb 5, 2026
fcd93ae
add interop tests
gomfol12 Feb 5, 2026
2d0bfdf
destructor handling with static lifetimes and test
gomfol12 Feb 5, 2026
944b82f
additional finalizer test
gomfol12 Feb 5, 2026
54baf9a
CMakeLists -g commend
gomfol12 Feb 5, 2026
acba642
improved variable tracking, impl handling of allocatable trough funct…
gomfol12 Feb 5, 2026
fe2afa3
more consistent function naming scheme
gomfol12 Feb 5, 2026
1412446
some fixes for destructor with allocatable vars and test
gomfol12 Feb 5, 2026
9a75d45
some code cleanup regarding operators
gomfol12 Feb 5, 2026
89489c4
add more operator tests
gomfol12 Feb 5, 2026
9955ae7
operator: improved interface operators and can now distinguish betwee…
gomfol12 Feb 5, 2026
88a522e
remove typedef we are in c++
gomfol12 Feb 5, 2026
c9ba370
add cmake_base.txt to .gitignore
gomfol12 Feb 5, 2026
e3a1317
comments
gomfol12 Feb 5, 2026
703159f
improved CMakeLists.txt to make it more readable and now using differ…
gomfol12 Feb 5, 2026
2219eac
add test case with fortdepend to generate fortran module dependencies
gomfol12 Feb 5, 2026
08c08b0
add fortran test file config for cmake and make to .gitignore
gomfol12 Feb 5, 2026
5795faf
add script to act as normal compiler that also generates CG
gomfol12 Feb 5, 2026
4976a16
updated README.md
gomfol12 Feb 5, 2026
814bbf2
add partial test examples for function pointer and unlimited polymorp…
gomfol12 Feb 5, 2026
9cdd2dc
update to new metacg version
gomfol12 Feb 5, 2026
9a9e217
fix test runner for fortdepend test
gomfol12 Feb 5, 2026
d00e1c0
update test metacg format version 3 -> 4
gomfol12 Feb 5, 2026
d9ef4a8
swaped insert with getOrInsertNode to only insert nodes with unique n…
gomfol12 Feb 5, 2026
c4a93c0
remove unnecessary includes
gomfol12 Feb 5, 2026
cf4c179
add FlangLLVM.cmake for correctly linking flang
gomfol12 Feb 5, 2026
6eb082a
fix comp_wrapper and add filtering for files in options
gomfol12 Feb 5, 2026
b2db55a
flang_bin can now be set throw env var
gomfol12 Feb 5, 2026
d9e4fd4
don't link against flangFrontendTool
gomfol12 Feb 5, 2026
8336e49
main more consistant output filenames and new norename plugin for cma…
gomfol12 Feb 5, 2026
760c9dd
update tests to reflect main changes
gomfol12 Feb 5, 2026
c9a6012
add norename option to wrapper script
gomfol12 Feb 5, 2026
38345a0
compiler wrapper now correctly filters options and also extract optio…
gomfol12 Feb 5, 2026
975dd0b
comp wrapper fix -o parsing
gomfol12 Feb 5, 2026
732245f
fix for crash in expr's in specification part of module
gomfol12 Feb 5, 2026
a5997d0
more consistent mangling, adjusted tests and fix typo
gomfol12 Feb 5, 2026
b908c7e
FlangLLVM.cmake added required clang package
gomfol12 Feb 5, 2026
7424f19
fix cgManager wrong usage
gomfol12 Feb 5, 2026
9d933f4
test_runner.sh now count test cases run and failed
gomfol12 Feb 5, 2026
b0c3c8e
add empty tests
gomfol12 Feb 5, 2026
dc031f2
reenabled underscoring for mangling
gomfol12 Feb 5, 2026
5fc9a3d
cgfcollector_comp_wrapper ignore -fPIC for flang -fc1 call
gomfol12 Feb 5, 2026
f9e0ce0
add missing _ to some function names
gomfol12 Feb 5, 2026
75a373b
extract info from use definition for derived types and add some tests
gomfol12 Feb 5, 2026
59fad1b
forget to rename test files
gomfol12 Feb 5, 2026
023fb4d
fixed origin field in multi operator and use tests
gomfol12 Feb 5, 2026
ad4c820
add collection of interface operators from use statement. Same idea a…
gomfol12 Feb 5, 2026
6344fba
add comment
gomfol12 Feb 5, 2026
150a245
fix test runner: some failed test got not counted as failed
gomfol12 Feb 5, 2026
190c85c
fix GenericDetails restrict to only IsIntrinsicOperator and fix typo
gomfol12 Feb 5, 2026
1256b80
types array missing extendsfrom entry add more descriptive error msg
gomfol12 Feb 5, 2026
aa03b59
fix: i am now collecting type though the inheritance structure correc…
gomfol12 Feb 5, 2026
4a0ba22
getFileEntry for llvm > 18
gomfol12 Feb 5, 2026
d4d5be5
moved compareSymbols, mangleSymbol to util file
gomfol12 Feb 5, 2026
1dde341
refactor
gomfol12 Feb 5, 2026
12f988d
refactor
gomfol12 Feb 5, 2026
13d762c
refactor
gomfol12 Feb 5, 2026
998274c
add documentation
gomfol12 Feb 5, 2026
3a48582
refactor and add documentation
gomfol12 Feb 5, 2026
9a76262
use function struct for currentFunctions vector
gomfol12 Feb 5, 2026
56458a2
doc and refector
gomfol12 Feb 5, 2026
0c9782c
refactor in individual files
gomfol12 Feb 5, 2026
f269343
variableTracking doc
gomfol12 Feb 5, 2026
f9a31bc
ParseTreeVisitor more doc
gomfol12 Feb 5, 2026
2570939
edgeManager refactor
gomfol12 Feb 5, 2026
e5ef515
edgeManager refactor
gomfol12 Feb 5, 2026
4e7ace6
rename type typeSymbol
gomfol12 Feb 5, 2026
1130db0
change to remove in handleTrackedVars
gomfol12 Feb 5, 2026
35f7387
removed const_cast and resolved auto for clarity
gomfol12 Feb 5, 2026
9efa7ac
add doc in tool scripts
gomfol12 Feb 5, 2026
e743f97
updated cgfcollector README
gomfol12 Feb 5, 2026
c092fcf
removed duplicate comment
gomfol12 Feb 5, 2026
b5503fc
cmake uncomment/removed lines
gomfol12 Feb 9, 2026
3e8de05
README: add context and fix typo
gomfol12 Feb 9, 2026
9c912e5
migration: CGCompare to CGDiff
gomfol12 Feb 9, 2026
d84aef7
removed CGCompare
gomfol12 Feb 9, 2026
2d0dfdd
simplify test script and integrate in cmake
gomfol12 Feb 9, 2026
9602d67
cmake add flangFrontendTool find
gomfol12 Feb 11, 2026
2570553
Filename capitalization and license headers
gomfol12 Feb 17, 2026
59e8b74
removed using namespace from header files and project-local includes …
gomfol12 Feb 17, 2026
056dfe6
use upper case type names
gomfol12 Feb 17, 2026
ed5d7ff
comment style
gomfol12 Feb 17, 2026
a5f9ffe
Consistent naming for cgfcollector
gomfol12 Feb 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ cmake-build*/
spack.yaml
spack.lock
.spack-env/

cgfcollector/test/multi/cmake_base.txt
cgfcollector/test/multi/make_base
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,15 @@ if(METACG_BUILD_PYMETACG)
endif()

add_subdirectory(utils)

# Build fortran collector
option(
METACG_BUILD_CGFCOLLECTOR
"On or off"
OFF
)

if(METACG_BUILD_CGFCOLLECTOR)
include(FlangLLVM)
add_subdirectory(cgfcollector)
endif()
129 changes: 129 additions & 0 deletions cgfcollector/CMakeLists.txt
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)
87 changes: 87 additions & 0 deletions cgfcollector/README.md
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
```
74 changes: 74 additions & 0 deletions cgfcollector/include/Edge.h
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

#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);
};
Loading