//===- Pass2.cpp - Example code from "Writing an LLVM Pass" ---------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements two versions of the LLVM "Hello World" pass described
// in docs/WritingAnLLVMPass.html
//
//===----------------------------------------------------------------------===//

//#define DEBUG_TYPE "pass2"

// LLVM-related headers:
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/Statistic.h"

#include "Pass1.h"

// default namespace is llvm
using namespace llvm;

// declare a statistics counter -- HelloCounter, that can be used as an integer
// in code
//STATISTIC(HelloCounter, "Counts number of functions greeted");


namespace {
  // Hello2 - The second implementation with getAnalysisUsage implemented.
  struct Pass2 : public FunctionPass {
    static char ID; // Pass identification, replacement for typeid

    Pass2() : FunctionPass(&ID){}

    // init the HelloCounter
    //virtual bool doInitialization(Module &M) {
    //	return false;
    //}

    virtual bool runOnFunction(Function &F) {
      //1. obtain passInfo from Pass1:
      Pass1 &pass1 = getAnalysis<Pass1>();

      //2. return false, since nothing will be changed:
      return false;
    }

    //virtual bool doFinalization(Module &M){
    	//errs() <<"Pass2: Transformation Pass" <<'\n';
    	//return false;
    //}

    // We don't modify the program, so we preserve all analyses
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<Pass1>();
      //AU.setPreservesAll();
    }
  };
}

char Pass2::ID = 0;
static RegisterPass<Pass2>
Y("pass2", "Pass2 (Transformation Pass)");


