summaryrefslogtreecommitdiff
path: root/tools/llvm-profdata
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-03-19 02:20:46 +0000
committerJustin Bogner <mail@justinbogner.com>2014-03-19 02:20:46 +0000
commit695043fb4886d23e285ff88bee3d7e2859bf6280 (patch)
treef6920aa9c4c1f23cd891df719f9568ce496e8e6a /tools/llvm-profdata
parentfb007bb98c8943b734111ab601e4481ed266713e (diff)
downloadllvm-695043fb4886d23e285ff88bee3d7e2859bf6280.tar.gz
llvm-695043fb4886d23e285ff88bee3d7e2859bf6280.tar.bz2
llvm-695043fb4886d23e285ff88bee3d7e2859bf6280.tar.xz
llvm-profdata: Make "merge" into a subcommand.
We'll be adding a few more subcommands in the near future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204211 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-profdata')
-rw-r--r--tools/llvm-profdata/llvm-profdata.cpp67
1 files changed, 51 insertions, 16 deletions
diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp
index b4dd55c833..d8abafc33c 100644
--- a/tools/llvm-profdata/llvm-profdata.cpp
+++ b/tools/llvm-profdata/llvm-profdata.cpp
@@ -22,17 +22,6 @@
using namespace llvm;
-static cl::opt<std::string> Filename1(cl::Positional, cl::Required,
- cl::desc("file1"));
-static cl::opt<std::string> Filename2(cl::Positional, cl::Required,
- cl::desc("file2"));
-
-static cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
- cl::init("-"),
- cl::desc("Output file"));
-static cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
- cl::aliasopt(OutputFilename));
-
static void exitWithError(const std::string &Message,
const std::string &Filename, int64_t Line = -1) {
errs() << "error: " << Filename;
@@ -43,11 +32,17 @@ static void exitWithError(const std::string &Message,
}
//===----------------------------------------------------------------------===//
-int main(int argc, char **argv) {
- // Print a stack trace if we signal out.
- sys::PrintStackTraceOnErrorSignal();
- PrettyStackTraceProgram X(argc, argv);
- llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+int merge_main(int argc, const char *argv[]) {
+ cl::opt<std::string> Filename1(cl::Positional, cl::Required,
+ cl::desc("file1"));
+ cl::opt<std::string> Filename2(cl::Positional, cl::Required,
+ cl::desc("file2"));
+
+ cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
+ cl::init("-"),
+ cl::desc("Output file"));
+ cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
+ cl::aliasopt(OutputFilename));
cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
@@ -127,3 +122,43 @@ int main(int argc, char **argv) {
return 0;
}
+
+int main(int argc, const char *argv[]) {
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
+ StringRef ProgName(sys::path::filename(argv[0]));
+ if (argc > 1) {
+ int (*func)(int, const char *[]) = 0;
+
+ if (strcmp(argv[1], "merge") == 0)
+ func = merge_main;
+
+ if (func) {
+ std::string Invocation(ProgName.str() + " " + argv[1]);
+ argv[1] = Invocation.c_str();
+ return func(argc - 1, argv + 1);
+ }
+
+ if (strcmp(argv[1], "-h") == 0 ||
+ strcmp(argv[1], "-help") == 0 ||
+ strcmp(argv[1], "--help") == 0) {
+
+ errs() << "OVERVIEW: LLVM profile data tools\n\n"
+ << "USAGE: " << ProgName << " <command> [args...]\n"
+ << "USAGE: " << ProgName << " <command> -help\n\n"
+ << "Available commands: merge\n";
+ return 0;
+ }
+ }
+
+ if (argc < 2)
+ errs() << ProgName << ": No command specified!\n";
+ else
+ errs() << ProgName << ": Unknown command!\n";
+
+ errs() << "USAGE: " << ProgName << " <merge|show|generate> [args...]\n";
+ return 1;
+}