ldc/gen/cl_helpers.h
Frits van Bommel b3d87205ad Use LLVM-style command line (instead of DMD-style)
Note: For a backward compatible interface, use the new bin/ldmd script. It
      supports all old options while passing on anything it doesn't recognize.

Some changes caused by this:
* -debug and -version are now -d-debug and -d-version due to a conflict with
  standard LLVM options.
* All "flag" options now allow an optional =true/=1/=false/=0 suffix.
* Some "hidden debug switches" starting with "--" were renamed because LLVM
  doesn't care about the number of dashes, so they were conflicting with other
  options (such as -c).
  The new versions start with "-hidden-debug-" instead of "--"
* --help works, but has a non-zero exit code. This breaks some Tango scripts
  which use it to test for compiler existence. See tango.patch.

Some changes not (directly) caused by this;
* (-enable/-disable)-FOO options are now available for pre- and postconditions.
* -march is used instead of -m (like other LLVM programs), but -m is an alias
  for it.
* -defaultlib, -debuglib, -d-debug and -d-version allow comma-separated values.
  The effect should be identical to specifying the same option multiple times.
  I decided against allowing these for some other options because paths might
  contain commas on some systems.
* -fPIC is removed in favor of the standard LLVM option -relocation-model=pic

Bug:
* If -run is specified as the last argument in DFLAGS, no error is generated.
  (Not very serious IMHO)
2009-02-25 17:34:51 +01:00

68 lines
1.9 KiB
C++

#ifndef LDC_CL_HELPERS_H
#define LDC_CL_HELPERS_H
#include <string>
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
struct Array;
namespace opts {
namespace cl = llvm::cl;
/// Helper class for fancier options
class FlagParser : public cl::parser<bool> {
std::vector<std::pair<std::string, bool> > switches;
public:
template <class Opt>
void initialize(Opt &O) {
assert(!(O.getMiscFlags() & cl::AllowInverse)
&& "FlagParser doesn't support redundant AllowInverse flag");
std::string Name = O.ArgStr;
switches.push_back(make_pair("enable-" + Name, true));
switches.push_back(make_pair("disable-" + Name, false));
// Replace <foo> with -enable-<foo>
O.ArgStr = switches[0].first.c_str();
}
bool parse(cl::Option &O, const char *ArgName, const std::string &ArgValue, bool &Val);
void getExtraOptionNames(std::vector<const char*> &Names);
};
/// Helper class for options that set multiple flags
class MultiSetter {
std::vector<bool*> locations;
bool invert;
MultiSetter(bool); //not implemented, disable auto-conversion
public:
MultiSetter(bool invert, bool* p, ...) END_WITH_NULL;
void operator=(bool val);
};
/// Helper class to fill Array with char* when given strings
/// (Errors on empty strings)
class ArrayAdapter {
const char* name;
Array** arrp;
public:
ArrayAdapter(const char* name_, Array*& arr) {
name = name_;
arrp = &arr;
assert(name);
assert(arrp);
}
void push_back(const char* cstr);
void push_back(const std::string& str) {
push_back(str.c_str());
}
};
}
#endif