From b747c2fa0005b602821220b8bceaca91c49bc0e4 Mon Sep 17 00:00:00 2001 From: Tim Haines Date: Tue, 2 Jan 2024 23:01:05 -0600 Subject: [PATCH] Add parseAPI --- CMakeLists.txt | 1 + parseAPI/CMakeLists.txt | 9 +++++++++ parseAPI/edgePredicate.cpp | 29 +++++++++++++++++++++++++++++ parseAPI/loopAnalysis.cpp | 23 +++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 parseAPI/CMakeLists.txt create mode 100644 parseAPI/edgePredicate.cpp create mode 100644 parseAPI/loopAnalysis.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 173852b..9d621f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ add_subdirectory(instructionAPI) add_subdirectory(interceptOutput) add_subdirectory(maxMallocSize) add_subdirectory(memoryAccessCounter) +add_subdirectory(parseAPI) add_subdirectory(proccontrol) add_subdirectory(readGlobalVariables) add_subdirectory(stackwalker) diff --git a/parseAPI/CMakeLists.txt b/parseAPI/CMakeLists.txt new file mode 100644 index 0000000..61c57df --- /dev/null +++ b/parseAPI/CMakeLists.txt @@ -0,0 +1,9 @@ +project(parseAPI LANGUAGES CXX) + +add_library(loopAnalysis SHARED loopAnalysis.cpp) +target_compile_options(loopAnalysis PRIVATE ${EXAMPLES_WARNING_FLAGS}) +target_link_libraries(loopAnalysis PRIVATE Dyninst::parseAPI) + +add_library(edgePredicate SHARED edgePredicate.cpp) +target_compile_options(edgePredicate PRIVATE ${EXAMPLES_WARNING_FLAGS}) +target_link_libraries(edgePredicate PRIVATE Dyninst::parseAPI) diff --git a/parseAPI/edgePredicate.cpp b/parseAPI/edgePredicate.cpp new file mode 100644 index 0000000..3f0abd4 --- /dev/null +++ b/parseAPI/edgePredicate.cpp @@ -0,0 +1,29 @@ +#include "CFG.h" + +#include + +namespace dp = Dyninst::ParseAPI; + +void edge(dp::Function* func) { + std::vector work; + work.push_back(func->entry()); + + dp::Intraproc intra_pred; // ignore calls, returns + dp::Interproc inter_pred; + + while(!work.empty()) { + dp::Block* block = work.back(); + work.pop_back(); + + dp::Block::edgelist const& targets = block->targets(); + + for(dp::Edge *e : targets) { + if(intra_pred.pred_impl(e)) { + // Examine the Intraprocedural edge + } + if(inter_pred.pred_impl(e)) { + // Examine the Interprocedural edge + } + } + } +} diff --git a/parseAPI/loopAnalysis.cpp b/parseAPI/loopAnalysis.cpp new file mode 100644 index 0000000..e0cdb76 --- /dev/null +++ b/parseAPI/loopAnalysis.cpp @@ -0,0 +1,23 @@ +#include "CFG.h" +#include + +namespace dp = Dyninst::ParseAPI; + +void GetLoopInFunc(dp::Function *f) { + std::vector loops; + f->getLoops(loops); + + for(dp::Loop *loop : loops) { + // Get all the entry blocks + std::vector entries; + loop->getLoopEntries(entries); + + // Get all the blocks in the loop + std::vector blocks; + loop->getLoopBasicBlocks(blocks); + + // Get all the back edges in the loop + std::vector backEdges; + loop->getBackEdges(backEdges); + } +}