mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
Make the ProgramName variable a std::string so we can eliminate the path
portion fo the program name via sys::Path().getLast(). This makes error messages more readable since this is invariably used only in error messages. Instead of: /path/to/llvm/bin/directory/toolname: error message we will now get: toolname: error message Also, since we always have a program name (even if its defaulted), don't check to see if it is set or not when generating error messages. This eliminates a bunch of constant strings, saving a little under 1K of data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29842 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/System/Path.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -31,7 +32,7 @@ using namespace llvm;
|
|||||||
using namespace cl;
|
using namespace cl;
|
||||||
|
|
||||||
// Globals for name and overview of program
|
// Globals for name and overview of program
|
||||||
static const char *ProgramName = "<premain>";
|
static std::string ProgramName ( "<premain>" );
|
||||||
static const char *ProgramOverview = 0;
|
static const char *ProgramOverview = 0;
|
||||||
|
|
||||||
// This collects additional help to be printed.
|
// This collects additional help to be printed.
|
||||||
@@ -289,7 +290,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
|
|||||||
assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
|
assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
|
||||||
"No options specified, or ParseCommandLineOptions called more"
|
"No options specified, or ParseCommandLineOptions called more"
|
||||||
" than once!");
|
" than once!");
|
||||||
ProgramName = argv[0]; // Save this away safe and snug
|
sys::Path progname(argv[0]);
|
||||||
|
ProgramName = sys::Path(argv[0]).getLast();
|
||||||
ProgramOverview = Overview;
|
ProgramOverview = Overview;
|
||||||
bool ErrorParsing = false;
|
bool ErrorParsing = false;
|
||||||
|
|
||||||
@@ -448,11 +450,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Handler == 0) {
|
if (Handler == 0) {
|
||||||
if (ProgramName)
|
|
||||||
std::cerr << ProgramName << ": Unknown command line argument '"
|
std::cerr << ProgramName << ": Unknown command line argument '"
|
||||||
<< argv[i] << "'. Try: '" << argv[0] << " --help'\n";
|
<< argv[i] << "'. Try: '" << argv[0] << " --help'\n";
|
||||||
else
|
|
||||||
std::cerr << "Unknown command line argument '" << argv[i] << "'.\n";
|
|
||||||
ErrorParsing = true;
|
ErrorParsing = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -488,28 +487,18 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
|
|||||||
|
|
||||||
// Check and handle positional arguments now...
|
// Check and handle positional arguments now...
|
||||||
if (NumPositionalRequired > PositionalVals.size()) {
|
if (NumPositionalRequired > PositionalVals.size()) {
|
||||||
if (ProgramName)
|
|
||||||
std::cerr << ProgramName
|
std::cerr << ProgramName
|
||||||
<< ": Not enough positional command line arguments specified!\n"
|
<< ": Not enough positional command line arguments specified!\n"
|
||||||
<< "Must specify at least " << NumPositionalRequired
|
<< "Must specify at least " << NumPositionalRequired
|
||||||
<< " positional arguments: See: " << argv[0] << " --help\n";
|
<< " positional arguments: See: " << argv[0] << " --help\n";
|
||||||
else
|
|
||||||
std::cerr << "Not enough positional command line arguments specified!\n"
|
|
||||||
<< "Must specify at least " << NumPositionalRequired
|
|
||||||
<< " positional arguments.";
|
|
||||||
|
|
||||||
ErrorParsing = true;
|
ErrorParsing = true;
|
||||||
} else if (!HasUnlimitedPositionals
|
} else if (!HasUnlimitedPositionals
|
||||||
&& PositionalVals.size() > PositionalOpts.size()) {
|
&& PositionalVals.size() > PositionalOpts.size()) {
|
||||||
if (ProgramName)
|
|
||||||
std::cerr << ProgramName
|
std::cerr << ProgramName
|
||||||
<< ": Too many positional arguments specified!\n"
|
<< ": Too many positional arguments specified!\n"
|
||||||
<< "Can specify at most " << PositionalOpts.size()
|
<< "Can specify at most " << PositionalOpts.size()
|
||||||
<< " positional arguments: See: " << argv[0] << " --help\n";
|
<< " positional arguments: See: " << argv[0] << " --help\n";
|
||||||
else
|
|
||||||
std::cerr << "Too many positional arguments specified!\n"
|
|
||||||
<< "Can specify at most " << PositionalOpts.size()
|
|
||||||
<< " positional arguments.\n";
|
|
||||||
ErrorParsing = true;
|
ErrorParsing = true;
|
||||||
|
|
||||||
} else if (ConsumeAfterOpt == 0) {
|
} else if (ConsumeAfterOpt == 0) {
|
||||||
@@ -616,8 +605,7 @@ bool Option::error(std::string Message, const char *ArgName) {
|
|||||||
if (ArgName[0] == 0)
|
if (ArgName[0] == 0)
|
||||||
std::cerr << HelpStr; // Be nice for positional arguments
|
std::cerr << HelpStr; // Be nice for positional arguments
|
||||||
else
|
else
|
||||||
std::cerr << (ProgramName ? ProgramName : "***")
|
std::cerr << ProgramName << ": for the -" << ArgName;
|
||||||
<< ": for the -" << ArgName;
|
|
||||||
|
|
||||||
std::cerr << " option: " << Message << "\n";
|
std::cerr << " option: " << Message << "\n";
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user