Commit 265fdf44 authored by Per's avatar Per

callgirl

parent b94792f9
......@@ -14,4 +14,9 @@ Build:
Run:
$ clang -Xclang -load -Xclang build/skeleton/libSkeletonPass.* something.c
$ clang -Xclang -load -Xclang build/skeleton/libSkeletonPass.* ctest/test1.c
$ cd ctest
$ clang -S -emit-llvm test1.c
$ opt -load ../build/skeleton/libSkeletonPass.* -callgirl test1.ll -o dummy.ll
......@@ -5,6 +5,7 @@
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Analysis/Trace.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Instructions.h"
using namespace llvm;
......@@ -19,12 +20,17 @@ struct SkeletonPass : public FunctionPass
{
errs() << "Function " << F.getName() << "!\n";
for (Function::BasicBlockListType::iterator i = F.begin(), ie = F.end(); i != ie; ++i)
for (Function::BasicBlockListType::iterator b = F.begin(), be = F.end(); b != be; ++b)
{
for (llvm::BasicBlock::InstListType::iterator j = i->begin(), je = i->end(); j != je; ++j)
for (llvm::BasicBlock::InstListType::iterator j = b->begin(), je = b->end(); j != je; ++j)
{
Instruction *ii = &*j;
errs() << *ii << "\n";
// errs() << *ii << "\n";
errs() << "opcode: " << *ii << ", in function: " << (*ii).getFunction()->getName() << "\n";
if (CallInst *c = dyn_cast<CallInst>(ii))
{
errs() << "call to:" << c->getCalledFunction()->getName() << "\n";
}
}
}
return false;
......@@ -34,6 +40,10 @@ struct SkeletonPass : public FunctionPass
char SkeletonPass::ID = 0;
static RegisterPass<SkeletonPass> X("callgirl", "A politically incorrect LLVM pass",
true /* Only looks at CFG */,
true /* Analysis Pass */);
// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
static void registerSkeletonPass(const PassManagerBuilder &,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment