Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_subdirectory(cgconvert)
add_subdirectory(cgformat)
add_subdirectory(cgdiff)
add_subdirectory(cgquery)
add_subdirectory(cgvisual)
if(BUILD_CAGE)
add_subdirectory(cage)
endif()
21 changes: 21 additions & 0 deletions tools/cgvisual/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(PROJECT_NAME CGVisual)
Comment thread
gomfol12 marked this conversation as resolved.
Outdated
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)
12 changes: 12 additions & 0 deletions tools/cgvisual/README.md
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.
Comment thread
gomfol12 marked this conversation as resolved.
Outdated

## Usage

```
cgvisual [options] <input_file>
```

Use `cgvisual --help` to get a list of available options.
85 changes: 85 additions & 0 deletions tools/cgvisual/visual.cpp
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>
Comment thread
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";
Comment thread
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") {
Comment thread
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);
Comment thread
gomfol12 marked this conversation as resolved.
Outdated

auto mcgReader1 = metacg::io::createReader(fs1);
Comment thread
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;
}