Finegrainify namespacification
[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 using namespace llvm;
18
19 namespace {
20   // Hello - The first implementation, without getAnalysisUsage.
21   struct Hello : public FunctionPass {
22     virtual bool runOnFunction(Function &F) {
23       std::cerr << "Hello: " << F.getName() << "\n";
24       return false;
25     }
26   }; 
27   RegisterOpt<Hello> X("hello", "Hello World Pass");
28
29   // Hello2 - The second implementation with getAnalysisUsage implemented.
30   struct Hello2 : public FunctionPass {
31     virtual bool runOnFunction(Function &F) {
32       std::cerr << "Hello: " << F.getName() << "\n";
33       return false;
34     }
35
36     // We don't modify the program, so we preserve all analyses
37     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38       AU.setPreservesAll();
39     };
40   }; 
41   RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");
42 }