Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Baby Hello World for LLVM
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/IR/InstIterator.h"
using namespace llvm;
namespace
{
struct Hello : public FunctionPass
{
static char ID;
Hello() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override
{
errs() << "-> ";
errs().write_escaped(F.getName()) << '\n';
/* for (BasicBlock &B : F) {
for (auto iBegin = B.begin(), iEnd = B.end(); iBegin != iEnd; iBegin++) {
if (iBegin == B.begin())
errs() << "Begin " << iBegin. << "\n";
}
errs() << "Begin:; " << B << "\n";
} */
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
{
if (I == inst_begin(F))
errs() << " Begin: " << *I << "\n";
auto tmp = I;
if ((++tmp) == inst_end(F))
errs() << " End: " << *I << "\n";
}
errs() << "\n";
return false;
}
}; // end of struct Hello
} // end of anonymous namespace
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
You can’t perform that action at this time.