Skip to content

Instantly share code, notes, and snippets.

@nazwadi
Created April 9, 2019 18:22
Show Gist options
  • Save nazwadi/81f372123a64ee217b4fe7a8f9aa13de to your computer and use it in GitHub Desktop.
Save nazwadi/81f372123a64ee217b4fe7a8f9aa13de to your computer and use it in GitHub Desktop.
LLVM_Template - modified slightly from the example in http://llvm.org/docs/ProgrammersManual.html
// From http://llvm.org/docs/ProgrammersManual.html
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace {
struct Hello : public FunctionPass {
static char ID;
Hello() : FunctionPass(ID) {}
virtual bool doInitialization(Module &M) {
return false;
}
virtual bool doFinalization(Module &M) {
return false;
}
bool runOnFunction(Function &F) override {
errs() << "Hello: ";
errs().write_escaped(F.getName()) << '\n';
return false;
}
}; // end of struct Hello
}
char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "Hello World Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment