diff options
author | dim <dim@FreeBSD.org> | 2012-02-05 23:56:22 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-02-05 23:56:22 +0000 |
commit | eb8951e7f7015d193e6640deb0ebde32f01b72d8 (patch) | |
tree | 8052b8010f619e8d40e5e3b37482591f537e0ca0 /contrib/llvm/tools/llvm-diff/llvm-diff.cpp | |
parent | 4de4d315e465f872a81f448b1788cc017f2d2033 (diff) | |
parent | 07637c87f826cdf411f0673595e9bc92ebd793f2 (diff) | |
download | FreeBSD-src-eb8951e7f7015d193e6640deb0ebde32f01b72d8.zip FreeBSD-src-eb8951e7f7015d193e6640deb0ebde32f01b72d8.tar.gz |
Add a WITH_CLANG_EXTRAS option for src.conf(5), disabled by default,
that builds the following additional llvm/clang tools:
- bugpoint
- llc
- lli
- llvm-ar
- llvm-as
- llvm-bcanalyzer
- llvm-diff
- llvm-dis
- llvm-extract
- llvm-ld
- llvm-link
- llvm-mc
- llvm-nm
- llvm-objdump
- llvm-prof
- llvm-ranlib
- llvm-rtdyld
- llvm-stub
- macho-dump
- opt
These tools are mainly useful for people that want to manipulate llvm
bitcode (.bc) and llvm assembly language (.ll) files, or want to tinker
with llvm and clang themselves.
MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm/tools/llvm-diff/llvm-diff.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-diff/llvm-diff.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/contrib/llvm/tools/llvm-diff/llvm-diff.cpp b/contrib/llvm/tools/llvm-diff/llvm-diff.cpp new file mode 100644 index 0000000..76853f1 --- /dev/null +++ b/contrib/llvm/tools/llvm-diff/llvm-diff.cpp @@ -0,0 +1,98 @@ +//===-- llvm-diff.cpp - Module comparator command-line driver ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the command-line driver for the difference engine. +// +//===----------------------------------------------------------------------===// + +#include "DiffLog.h" +#include "DifferenceEngine.h" + +#include "llvm/LLVMContext.h" +#include "llvm/Module.h" +#include "llvm/Type.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/IRReader.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/SourceMgr.h" + +#include <string> +#include <utility> + + +using namespace llvm; + +/// Reads a module from a file. On error, messages are written to stderr +/// and null is returned. +static Module *ReadModule(LLVMContext &Context, StringRef Name) { + SMDiagnostic Diag; + Module *M = ParseIRFile(Name, Diag, Context); + if (!M) + Diag.Print("llvmdiff", errs()); + return M; +} + +static void diffGlobal(DifferenceEngine &Engine, Module *L, Module *R, + StringRef Name) { + // Drop leading sigils from the global name. + if (Name.startswith("@")) Name = Name.substr(1); + + Function *LFn = L->getFunction(Name); + Function *RFn = R->getFunction(Name); + if (LFn && RFn) + Engine.diff(LFn, RFn); + else if (!LFn && !RFn) + errs() << "No function named @" << Name << " in either module\n"; + else if (!LFn) + errs() << "No function named @" << Name << " in left module\n"; + else + errs() << "No function named @" << Name << " in right module\n"; +} + +static cl::opt<std::string> LeftFilename(cl::Positional, + cl::desc("<first file>"), + cl::Required); +static cl::opt<std::string> RightFilename(cl::Positional, + cl::desc("<second file>"), + cl::Required); +static cl::list<std::string> GlobalsToCompare(cl::Positional, + cl::desc("<globals to compare>")); + +int main(int argc, char **argv) { + cl::ParseCommandLineOptions(argc, argv); + + LLVMContext Context; + + // Load both modules. Die if that fails. + Module *LModule = ReadModule(Context, LeftFilename); + Module *RModule = ReadModule(Context, RightFilename); + if (!LModule || !RModule) return 1; + + DiffConsumer Consumer(LModule, RModule); + DifferenceEngine Engine(Context, Consumer); + + // If any global names were given, just diff those. + if (!GlobalsToCompare.empty()) { + for (unsigned I = 0, E = GlobalsToCompare.size(); I != E; ++I) + diffGlobal(Engine, LModule, RModule, GlobalsToCompare[I]); + + // Otherwise, diff everything in the module. + } else { + Engine.diff(LModule, RModule); + } + + delete LModule; + delete RModule; + + return Consumer.hadDifferences(); +} |