-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
LLVM_BUILD := ~/llvm-project-15.0.7.src/build | ||
|
||
# Rule to build the project | ||
build_project: | ||
mkdir -p build \ | ||
&& cd build \ | ||
&& PATH=${LLVM_BUILD}/bin:${PATH} \ | ||
CC=clang CXX=clang++ \ | ||
cmake ../src \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||
-DCMAKE_CXX_FLAGS_RELEASE="-std=c++17 -fno-rtti -fpic -g" \ | ||
&& make | ||
|
||
# Rule to clean the build directory | ||
clean_project: | ||
rm -rf build | ||
|
||
# Default target | ||
all: project | ||
|
||
# Clean target | ||
clean: clean_project | ||
|
||
# Project target depends on build_project | ||
project: clean_project build_project |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
project(IPA) | ||
|
||
find_package(LLVM REQUIRED CONFIG) | ||
# list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") | ||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") | ||
include_directories(${LLVM_INCLUDE_DIRS}) | ||
# add_definitions(${LLVM_DEFINITIONS}) | ||
|
||
set(project | ||
main.cpp | ||
PrintFunctionArgsPass.cpp | ||
PrintFunctionArgsPass.hpp | ||
PrintFunctionNamesPass.cpp | ||
PrintFunctionNamesPass.hpp | ||
) | ||
add_executable(ipa ${project}) | ||
|
||
target_link_libraries( | ||
ipa | ||
LLVMCore | ||
LLVMSupport | ||
LLVMIRReader | ||
LLVMAnalysis | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "PrintFunctionArgsPass.hpp" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
using namespace llvm; | ||
|
||
char PrintFunctionArgsPass::ID = 0; | ||
|
||
PrintFunctionArgsPass::PrintFunctionArgsPass() : ModulePass(ID) {} | ||
|
||
bool PrintFunctionArgsPass::runOnModule(Module &M) { | ||
// Iterate through all functions in the module and print the number of arguments | ||
for (Function &F : M) { | ||
if (!F.isDeclaration()) { | ||
errs() << "Function Name: " << F.getName() | ||
<< ", Argument Count: " << F.arg_size() << "\n"; | ||
} | ||
} | ||
return false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef PRINT_FUNCTION_ARGS_PASS_HPP | ||
#define PRINT_FUNCTION_ARGS_PASS_HPP | ||
|
||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
|
||
class PrintFunctionArgsPass : public llvm::ModulePass { | ||
public: | ||
static char ID; | ||
PrintFunctionArgsPass(); | ||
|
||
bool runOnModule(llvm::Module &M) override; | ||
}; | ||
|
||
#endif // PRINT_FUNCTION_ARGS_PASS_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "PrintFunctionNamesPass.hpp" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
using namespace llvm; | ||
|
||
char PrintFunctionNamesPass::ID = 0; | ||
|
||
PrintFunctionNamesPass::PrintFunctionNamesPass() : ModulePass(ID) {} | ||
|
||
bool PrintFunctionNamesPass::runOnModule(Module &M) { | ||
// Iterate through all functions in the module and print their names | ||
for (Function &F : M) { | ||
if (!F.isDeclaration()) { | ||
errs() << "Function Name: " << F.getName() << "\n"; | ||
} | ||
} | ||
return false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PRINT_FUNCTION_NAMES_PASS_HPP | ||
#define PRINT_FUNCTION_NAMES_PASS_HPP | ||
|
||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
|
||
|
||
class PrintFunctionNamesPass : public llvm::ModulePass { | ||
public: | ||
static char ID; | ||
PrintFunctionNamesPass(); | ||
|
||
bool runOnModule(llvm::Module &M) override; | ||
}; | ||
|
||
#endif // PRINT_FUNCTION_NAMES_PASS_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "llvm/IRReader/IRReader.h" | ||
#include "llvm/Support/SourceMgr.h" | ||
#include "llvm/Pass.h" | ||
|
||
#include "PrintFunctionNamesPass.hpp" | ||
#include "PrintFunctionArgsPass.hpp" | ||
|
||
using namespace llvm; | ||
|
||
// Command-line option to specify multiple input .bc files | ||
static cl::list<std::string> InputFilenames(cl::Positional, | ||
cl::desc("<input .bc files>"), | ||
cl::OneOrMore); | ||
|
||
int main(int argc, char **argv) { | ||
cl::ParseCommandLineOptions(argc, argv, "Function Passes\n"); | ||
|
||
LLVMContext Context; | ||
|
||
// Iterate through all input files | ||
for (const auto &InputFilename : InputFilenames) { | ||
SMDiagnostic Err; | ||
|
||
// Load the bitcode file | ||
std::unique_ptr<Module> Mod = parseIRFile(InputFilename, Err, Context); | ||
if (!Mod) { | ||
errs() << "Error reading bitcode file: " << InputFilename << "\n"; | ||
Err.print(argv[0], errs()); | ||
continue; // Skip to the next file if there's an error | ||
} | ||
|
||
errs() << "Analyzing file: " << InputFilename << "\n"; | ||
|
||
// Create and run the function name pass | ||
PrintFunctionNamesPass NamePass; | ||
NamePass.runOnModule(*Mod); | ||
|
||
// Create and run the function argument pass | ||
PrintFunctionArgsPass ArgsPass; | ||
ArgsPass.runOnModule(*Mod); | ||
} | ||
|
||
return 0; | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.