mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
7962dbdc65
definition below all of the header #include lines, lib/Transforms/... edition. This one is tricky for two reasons. We again have a couple of passes that define something else before the includes as well. I've sunk their name macros with the DEBUG_TYPE. Also, InstCombine contains headers that need DEBUG_TYPE, so now those headers #define and #undef DEBUG_TYPE around their code, leaving them well formed modular headers. Fixing these headers was a large motivation for all of these changes, as "leaky" macros of this form are hard on the modules implementation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206844 91177308-0d34-0410-b5e6-96231b3b80d8
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
//===- Hello.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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
using namespace llvm;
|
|
|
|
#define DEBUG_TYPE "hello"
|
|
|
|
STATISTIC(HelloCounter, "Counts number of functions greeted");
|
|
|
|
namespace {
|
|
// Hello - The first implementation, without getAnalysisUsage.
|
|
struct Hello : public FunctionPass {
|
|
static char ID; // Pass identification, replacement for typeid
|
|
Hello() : FunctionPass(ID) {}
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
++HelloCounter;
|
|
errs() << "Hello: ";
|
|
errs().write_escaped(F.getName()) << '\n';
|
|
return false;
|
|
}
|
|
};
|
|
}
|
|
|
|
char Hello::ID = 0;
|
|
static RegisterPass<Hello> X("hello", "Hello World Pass");
|
|
|
|
namespace {
|
|
// Hello2 - The second implementation with getAnalysisUsage implemented.
|
|
struct Hello2 : public FunctionPass {
|
|
static char ID; // Pass identification, replacement for typeid
|
|
Hello2() : FunctionPass(ID) {}
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
++HelloCounter;
|
|
errs() << "Hello: ";
|
|
errs().write_escaped(F.getName()) << '\n';
|
|
return false;
|
|
}
|
|
|
|
// We don't modify the program, so we preserve all analyses.
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
AU.setPreservesAll();
|
|
}
|
|
};
|
|
}
|
|
|
|
char Hello2::ID = 0;
|
|
static RegisterPass<Hello2>
|
|
Y("hello2", "Hello World Pass (with getAnalysisUsage implemented)");
|