blob: b6262118efa9becc67edafcdbd479c30d662bd71 [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"
Chris Lattnerf7703df2004-01-09 06:12:26 +000017using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000018
Chris Lattner180e5682002-08-08 20:10:38 +000019namespace {
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}