Added LLVM project notice to the top of every C++ source file.
[oota-llvm.git] / lib / Transforms / Hello / Hello.cpp
1 //===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements two versions of the LLVM "Hello World" pass described
11 // in docs/WritingAnLLVMPass.html
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Pass.h"
16 #include "llvm/Function.h"
17
18 namespace {
19   // Hello - The first implementation, without getAnalysisUsage.
20   struct Hello : public FunctionPass {
21     virtual bool runOnFunction(Function &F) {
22       std::cerr << "Hello: " << F.getName() << "\n";
23       return false;
24     }
25   }; 
26   RegisterOpt<Hello> X("hello", "Hello World Pass");
27
28   // Hello2 - The second implementation with getAnalysisUsage implemented.
29   struct Hello2 : public FunctionPass {
30     virtual bool runOnFunction(Function &F) {
31       std::cerr << "Hello: " << F.getName() << "\n";
32       return false;
33     }
34
35     // We don't modify the program, so we preserve all analyses
36     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
37       AU.setPreservesAll();
38     };
39   }; 
40   RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");
41 }