-
Notifications
You must be signed in to change notification settings - Fork 10
[CGToDot] tool extracted from Fortran collector (#115) #119
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
708fbba
add cgvisual tool
gomfol12 7cdca4a
adopted cxxopts
gomfol12 699d9bc
updated includes
gomfol12 e8a92bd
Rename CGVisual to CGToDot
gomfol12 ed6c843
make use of std::filesystem::path
gomfol12 13dd0b8
add tests for cgtodot
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| set(PROJECT_NAME CGVisual) | ||
| set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-target) | ||
| set(PROJECT_BINARY_NAME cgvisual) | ||
|
|
||
| add_executable(${PROJECT_BINARY_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/visual.cpp) | ||
|
|
||
| add_metacg(${PROJECT_BINARY_NAME}) | ||
| add_spdlog_libraries(${PROJECT_BINARY_NAME}) | ||
|
|
||
| install( | ||
| TARGETS ${PROJECT_BINARY_NAME} | ||
| EXPORT ${TARGETS_EXPORT_NAME} | ||
| RUNTIME DESTINATION bin | ||
| ) | ||
|
|
||
| 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) | ||
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,12 @@ | ||
| # CGVisual | ||
|
|
||
| CGVisual is a simple tool to generate a DOT file representation of a given call | ||
| graph. It uses the existing DOT infrastructure already present in MetaCG. | ||
|
gomfol12 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Usage | ||
|
|
||
| ``` | ||
| cgvisual [options] <input_file> | ||
| ``` | ||
|
|
||
| Use `cgvisual --help` to get a list of available options. | ||
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,85 @@ | ||
| /** | ||
| * File: visual.cpp | ||
| * License: Part of the MetaCG project. Licensed under BSD 3 clause license. See LICENSE.txt file at | ||
| * https://github.com/tudasc/metacg/LICENSE.txt | ||
| */ | ||
|
|
||
| #include <Callgraph.h> | ||
|
gomfol12 marked this conversation as resolved.
Outdated
|
||
| #include <DotIO.h> | ||
| #include <LoggerUtil.h> | ||
| #include <fstream> | ||
| #include <io/MCGReader.h> | ||
|
|
||
| static auto console = metacg::MCGLogger::instance().getConsole(); | ||
| static auto errConsole = metacg::MCGLogger::instance().getErrConsole(); | ||
|
|
||
| void printUsage() { | ||
| std::cout << "Usage: visuel <cg>\n\n"; | ||
|
gomfol12 marked this conversation as resolved.
Outdated
|
||
| std::cout << "Reads a call graph from the specified file and generates a DOT file for visualization.\n\n"; | ||
| std::cout << "Options:\n"; | ||
| std::cout << " -h, --help Show this help message\n"; | ||
| std::cout << " -o, --output Specify output DOT file name (default: callgraph.dot)\n"; | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| if (argc < 2) { | ||
| printUsage(); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| std::string inputFile; | ||
| std::string outputFile = "callgraph.dot"; | ||
|
|
||
| for (int i = 1; i < argc; i++) { | ||
| std::string arg = argv[i]; | ||
|
|
||
| if (arg == "-h" || arg == "--help") { | ||
|
gomfol12 marked this conversation as resolved.
Outdated
|
||
| printUsage(); | ||
| return EXIT_SUCCESS; | ||
| } else if (arg == "-o" || arg == "--output") { | ||
| if (i + 1 >= argc) { | ||
| errConsole->error("Output file name not specified after {}", arg); | ||
| return EXIT_FAILURE; | ||
| } | ||
| outputFile = argv[++i]; | ||
| } else { | ||
| inputFile = arg; | ||
| } | ||
| } | ||
|
|
||
| if (inputFile.empty()) { | ||
| errConsole->error("No input call graph file specified."); | ||
| printUsage(); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| metacg::io::FileSource fs1(inputFile); | ||
|
gomfol12 marked this conversation as resolved.
Outdated
|
||
|
|
||
| auto mcgReader1 = metacg::io::createReader(fs1); | ||
|
gomfol12 marked this conversation as resolved.
Outdated
|
||
| if (!mcgReader1) { | ||
| errConsole->error("Failed to create MCG reader for file: {}", inputFile); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| auto cg = mcgReader1->read(); | ||
| if (!cg) { | ||
| errConsole->error("Failed to read call graph from file."); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| metacg::io::dot::DotGenerator dotGen(cg.get()); | ||
| dotGen.generate(); | ||
|
|
||
| std::ofstream outFile(outputFile); | ||
| if (!outFile.is_open()) { | ||
| errConsole->error("Could not open output file for writing: {}", outputFile); | ||
| return EXIT_FAILURE; | ||
| } | ||
| outFile << dotGen.getDotString(); | ||
|
|
||
| outFile.close(); | ||
|
|
||
| console->info("DOT file generated successfully: {}", outputFile); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } | ||
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.