forked from OSchip/llvm-project
Switch to using the LLVM CommandLine library so that our help
message is properly contaminated with nonsense about timing passes that doesn't apply at all to this utility. :) llvm-svn: 109769
This commit is contained in:
parent
c95a398947
commit
58c5088d48
|
@ -13,6 +13,7 @@
|
||||||
#include <llvm/Support/MemoryBuffer.h>
|
#include <llvm/Support/MemoryBuffer.h>
|
||||||
#include <llvm/Bitcode/ReaderWriter.h>
|
#include <llvm/Bitcode/ReaderWriter.h>
|
||||||
|
|
||||||
|
#include <llvm/Support/CommandLine.h>
|
||||||
#include <llvm/Support/raw_ostream.h>
|
#include <llvm/Support/raw_ostream.h>
|
||||||
#include <llvm/Support/ErrorHandling.h>
|
#include <llvm/Support/ErrorHandling.h>
|
||||||
#include <llvm/LLVMContext.h>
|
#include <llvm/LLVMContext.h>
|
||||||
|
@ -52,14 +53,6 @@ static Module *ReadModule(LLVMContext &Context, StringRef Name) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage() {
|
|
||||||
errs() << "expected usage:\n";
|
|
||||||
errs() << " llvm-diff oldmodule.ll newmodule.ll [function list]\n";
|
|
||||||
errs() << "Assembly or bitcode modules may be used interchangeably.\n";
|
|
||||||
errs() << "If no functions are provided, all functions will be compared.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct DiffContext {
|
struct DiffContext {
|
||||||
DiffContext(Value *L, Value *R)
|
DiffContext(Value *L, Value *R)
|
||||||
|
@ -270,48 +263,47 @@ public:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
static void diffGlobal(DifferenceEngine &Engine, Module *L, Module *R,
|
||||||
if (argc < 3) return usage();
|
StringRef Name) {
|
||||||
|
// Drop leading sigils from the global name.
|
||||||
|
if (Name.startswith("@")) Name = Name.substr(1);
|
||||||
|
|
||||||
// Don't make StringRef locals like this at home.
|
Function *LFn = L->getFunction(Name);
|
||||||
StringRef LModuleFile = argv[1];
|
Function *RFn = R->getFunction(Name);
|
||||||
StringRef RModuleFile = argv[2];
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
cl::opt<std::string> LeftFilename(cl::Positional, cl::desc("<first file>"), cl::Required);
|
||||||
|
cl::opt<std::string> RightFilename(cl::Positional, cl::desc("<second file>"), cl::Required);
|
||||||
|
cl::list<std::string> GlobalsToCompare(cl::Positional, cl::desc("<globals to compare>"));
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
cl::ParseCommandLineOptions(argc, argv);
|
||||||
|
|
||||||
LLVMContext Context;
|
LLVMContext Context;
|
||||||
|
|
||||||
// Load both modules. Die if that fails.
|
// Load both modules. Die if that fails.
|
||||||
Module *LModule = ReadModule(Context, LModuleFile);
|
Module *LModule = ReadModule(Context, LeftFilename);
|
||||||
Module *RModule = ReadModule(Context, RModuleFile);
|
Module *RModule = ReadModule(Context, RightFilename);
|
||||||
if (!LModule || !RModule) return 1;
|
if (!LModule || !RModule) return 1;
|
||||||
|
|
||||||
DiffConsumer Consumer(LModule, RModule);
|
DiffConsumer Consumer(LModule, RModule);
|
||||||
DifferenceEngine Engine(Context, Consumer);
|
DifferenceEngine Engine(Context, Consumer);
|
||||||
|
|
||||||
// If any function names were given, just diff those.
|
// If any global names were given, just diff those.
|
||||||
const char **FnNames = argv + 3;
|
if (!GlobalsToCompare.empty()) {
|
||||||
unsigned NumFnNames = argc - 3;
|
for (unsigned I = 0, E = GlobalsToCompare.size(); I != E; ++I)
|
||||||
if (NumFnNames) {
|
diffGlobal(Engine, LModule, RModule, GlobalsToCompare[I]);
|
||||||
for (unsigned I = 0; I != NumFnNames; ++I) {
|
|
||||||
StringRef FnName = FnNames[I];
|
|
||||||
|
|
||||||
// Drop leading sigils from the function name.
|
// Otherwise, diff everything in the module.
|
||||||
if (FnName.startswith("@")) FnName = FnName.substr(1);
|
|
||||||
|
|
||||||
Function *LFn = LModule->getFunction(FnName);
|
|
||||||
Function *RFn = RModule->getFunction(FnName);
|
|
||||||
if (LFn && RFn)
|
|
||||||
Engine.diff(LFn, RFn);
|
|
||||||
else {
|
|
||||||
if (!LFn && !RFn)
|
|
||||||
errs() << "No function named @" << FnName << " in either module\n";
|
|
||||||
else if (!LFn)
|
|
||||||
errs() << "No function named @" << FnName << " in left module\n";
|
|
||||||
else
|
|
||||||
errs() << "No function named @" << FnName << " in right module\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, diff all functions in the modules.
|
|
||||||
Engine.diff(LModule, RModule);
|
Engine.diff(LModule, RModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue