blob: 4ed281a40afce43e16746365660935f7a4d17a89 [file] [log] [blame]
Chris Lattner180e5682002-08-08 20:10:38 +00001//===- Hello.cpp - Example code from "Writing an LLVM Pass" ---------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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//===----------------------------------------------------------------------===//
Chris Lattner180e5682002-08-08 20:10:38 +00009//
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
Brian Gaeked0fde302003-11-11 22:41:34 +000018namespace llvm {
19
Chris Lattner180e5682002-08-08 20:10:38 +000020namespace {
21 // Hello - The first implementation, without getAnalysisUsage.
22 struct Hello : public FunctionPass {
23 virtual bool runOnFunction(Function &F) {
24 std::cerr << "Hello: " << F.getName() << "\n";
25 return false;
26 }
27 };
28 RegisterOpt<Hello> X("hello", "Hello World Pass");
29
30 // Hello2 - The second implementation with getAnalysisUsage implemented.
31 struct Hello2 : public FunctionPass {
32 virtual bool runOnFunction(Function &F) {
33 std::cerr << "Hello: " << F.getName() << "\n";
34 return false;
35 }
36
37 // We don't modify the program, so we preserve all analyses
38 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
39 AU.setPreservesAll();
40 };
41 };
42 RegisterOpt<Hello2> Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");
43}
Brian Gaeked0fde302003-11-11 22:41:34 +000044
45} // End llvm namespace