Skip to content

Instantly share code, notes, and snippets.

@tanishiking
Created October 30, 2016 10:57
Show Gist options
  • Save tanishiking/5e5d01cf1d126682760be640bc7ecbd1 to your computer and use it in GitHub Desktop.
Save tanishiking/5e5d01cf1d126682760be640bc7ecbd1 to your computer and use it in GitHub Desktop.
EasyPass that show only function names...

EasyPass

This pass print function names

source tree

.
├── CMakeLists.txt
└── easypass
    ├── CMakeLists.txt
    └── easypass.cpp

Requirements

install llvm into your system

How to build

mkdir build & cd build
cmake ..
make

you will get easypass/libeasypass.so

Usage

opt -load easypass/libeasypass.so -easypass hoge.ll > /dev/null

Function name : main
...
# projectroot/CmakeLists.txt
cmake_minimum_required(VERSION 2.8.8)
find_package(LLVM REQUIRED CONFIG)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_subdirectory(easypass)
# projectroot/easypass/CMakeLists.txt
add_library(easypass MODULE EasyPass.cpp)
target_compile_features(easypass PRIVATE cxx_range_for cxx_auto_type)
set_target_properties(easypass PROPERTIES
COMPILE_FLAGS "-fno-rtti"
)
/**
* projectroot/easypass/EasyPass.cpp
**/
#include <cstdio>
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace {
class EasyPass : public FunctionPass {
public:
static char ID;
EasyPass() : FunctionPass(ID) {}
~EasyPass() {}
virtual bool runOnFunction(Function &F);
};
}
bool EasyPass::runOnFunction(Function &F) {
errs() << "Function name: " << F.getName().str() << "\n";
return false;
}
char EasyPass::ID = 0;
static RegisterPass<EasyPass> X(
"easypass",
"easypass only print function name",
false,
false
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment