#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Type.h"

using namespace llvm;

struct Pass1 : public FunctionPass {
  public :
    static char ID;
    Pass1 () : FunctionPass ((intptr_t) &ID) {}
    const char *getPassName() const { return "Pass 1"; }
    virtual bool runOnFunction(Function &F) {
      return false;
    }
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      return;
    }
};

struct BottomPass : public ModulePass {
  public :
    static char ID;
    BottomPass () : ModulePass ((intptr_t) &ID) {
    }
    const char *getPassName() const { return "Bottom Pass"; }
    virtual bool runOnModule(Module &M) {
      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
        Function &F = *I;
        Pass1 &P = getAnalysis<Pass1>(F);
      }
      return false;
    }
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<Pass1>();
    }
};

int main(int argc, char **argv) {
  Module M("testmodule");
  M.getOrInsertFunction ("main", Type::VoidTy, NULL);
  PassManager Passes;
  Passes.add(new BottomPass());
  Passes.run(M);
  return 1;
}

char Pass1::ID = 0;
char BottomPass::ID = 0;

RegisterPass<Pass1> R1("p1","Pass 1");
RegisterPass<BottomPass> R3("b","Bottom Pass");

