Merge pull request #1469 from rainers/multi_config

Allow different configurations in the ldc2.conf
This commit is contained in:
David Nadlinger 2016-05-23 00:02:34 +01:00
commit f68ebbf1ec
4 changed files with 44 additions and 5 deletions

View file

@ -162,7 +162,7 @@ bool ConfigFile::locate() {
return false; return false;
} }
bool ConfigFile::read(const char *explicitConfFile) { bool ConfigFile::read(const char *explicitConfFile, const char* section) {
// explicitly provided by user in command line? // explicitly provided by user in command line?
if (explicitConfFile) { if (explicitConfFile) {
const std::string clPath = explicitConfFile; const std::string clPath = explicitConfFile;
@ -192,14 +192,21 @@ bool ConfigFile::read(const char *explicitConfFile) {
return false; return false;
} }
config_setting_t *root = nullptr;
if (section && *section)
root = config_lookup(cfg, section);
// make sure there's a default group // make sure there's a default group
config_setting_t *root = config_lookup(cfg, "default"); if (!root) {
section = "default";
root = config_lookup(cfg, section);
}
if (!root) { if (!root) {
std::cerr << "no default settings in configuration file" << std::endl; std::cerr << "no default settings in configuration file" << std::endl;
return false; return false;
} }
if (!config_setting_is_group(root)) { if (!config_setting_is_group(root)) {
std::cerr << "default is not a group" << std::endl; std::cerr << section << " is not a group" << std::endl;
return false; return false;
} }

View file

@ -27,7 +27,7 @@ public:
public: public:
ConfigFile(); ConfigFile();
bool read(const char *explicitConfFile); bool read(const char *explicitConfFile, const char* section);
s_iterator switches_begin() { return switches.begin(); } s_iterator switches_begin() { return switches.begin(); }
s_iterator switches_end() { return switches.end(); } s_iterator switches_end() { return switches.end(); }

View file

@ -345,6 +345,31 @@ static const char *tryGetExplicitConfFile(int argc, char **argv) {
return nullptr; return nullptr;
} }
static llvm::Triple tryGetExplicitTriple(int argc, char **argv) {
// most combinations of flags are illegal, this mimicks command line
// behaviour for legal ones only
llvm::Triple triple(llvm::sys::getDefaultTargetTriple());
const char* mtriple = nullptr;
const char* march = nullptr;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-m32") == 0)
return triple.get32BitArchVariant();
else if (strcmp(argv[i], "-m64") == 0)
return triple.get64BitArchVariant();
else if (strcmp(argv[i], "-mtriple=") == 0)
mtriple = argv[i] + 9;
else if (strcmp(argv[i], "-march=") == 0)
march = argv[i] + 7;
}
if (mtriple)
triple = llvm::Triple(llvm::Triple::normalize(mtriple));
if (march) {
std::string errorMsg; // ignore error, will show up later anyway
lookupTarget(march, triple, errorMsg); // modifies triple
}
return triple;
}
/// Parses switches from the command line, any response files and the global /// Parses switches from the command line, any response files and the global
/// config file and sets up global.params accordingly. /// config file and sets up global.params accordingly.
/// ///
@ -371,8 +396,9 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
ConfigFile cfg_file; ConfigFile cfg_file;
const char *explicitConfFile = tryGetExplicitConfFile(argc, argv); const char *explicitConfFile = tryGetExplicitConfFile(argc, argv);
std::string cfg_triple = tryGetExplicitTriple(argc, argv).getTriple();
// just ignore errors for now, they are still printed // just ignore errors for now, they are still printed
cfg_file.read(explicitConfFile); cfg_file.read(explicitConfFile, cfg_triple.c_str());
final_args.insert(final_args.end(), cfg_file.switches_begin(), final_args.insert(final_args.end(), cfg_file.switches_begin(),
cfg_file.switches_end()); cfg_file.switches_end());

View file

@ -35,6 +35,8 @@ enum Type { Unknown, O32, N32, N64, EABI };
} }
namespace llvm { namespace llvm {
class Triple;
class Target;
class TargetMachine; class TargetMachine;
} }
@ -65,4 +67,8 @@ llvm::TargetMachine *createTargetMachine(
*/ */
MipsABI::Type getMipsABI(); MipsABI::Type getMipsABI();
// Looks up a target based on an arch name and a target triple.
const llvm::Target *lookupTarget(const std::string &arch, llvm::Triple &triple,
std::string &errorMsg);
#endif // LDC_DRIVER_TARGET_H #endif // LDC_DRIVER_TARGET_H