2004-08-20 05:17:53 +08:00
|
|
|
//===- Configuration.cpp - Configuration Data Mgmt --------------*- C++ -*-===//
|
2004-08-14 04:21:22 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the parsing of configuration files for the LLVM Compiler
|
|
|
|
// Driver (llvmc).
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
|
2004-08-20 05:52:49 +08:00
|
|
|
#include "Configuration.h"
|
2004-08-14 17:37:15 +08:00
|
|
|
#include "ConfigLexer.h"
|
2004-08-14 04:21:22 +08:00
|
|
|
#include "CompilerDriver.h"
|
2004-08-20 17:24:07 +08:00
|
|
|
#include "Config/config.h"
|
2004-08-19 12:49:47 +08:00
|
|
|
#include "Support/CommandLine.h"
|
2004-08-14 04:21:22 +08:00
|
|
|
#include "Support/StringExtras.h"
|
|
|
|
#include <iostream>
|
2004-08-14 17:37:15 +08:00
|
|
|
#include <fstream>
|
2004-08-14 04:21:22 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2004-08-20 17:24:07 +08:00
|
|
|
namespace sys {
|
|
|
|
// From CompilerDriver.cpp (for now)
|
2004-08-24 22:03:23 +08:00
|
|
|
extern bool FileIsReadable(const std::string& fname);
|
2004-08-20 17:24:07 +08:00
|
|
|
}
|
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
namespace llvm {
|
2004-08-19 12:49:47 +08:00
|
|
|
ConfigLexerInfo ConfigLexerState;
|
2004-08-14 17:37:15 +08:00
|
|
|
InputProvider* ConfigLexerInput = 0;
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
InputProvider::~InputProvider() {}
|
|
|
|
void InputProvider::error(const std::string& msg) {
|
2004-08-19 12:49:47 +08:00
|
|
|
std::cerr << name << ":" << ConfigLexerState.lineNum << ": Error: " <<
|
|
|
|
msg << "\n";
|
2004-08-14 17:37:15 +08:00
|
|
|
errCount++;
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void InputProvider::checkErrors() {
|
|
|
|
if (errCount > 0) {
|
|
|
|
std::cerr << name << " had " << errCount << " errors. Terminating.\n";
|
|
|
|
exit(errCount);
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class FileInputProvider : public InputProvider {
|
|
|
|
public:
|
|
|
|
FileInputProvider(const std::string & fname)
|
|
|
|
: InputProvider(fname)
|
|
|
|
, F(fname.c_str()) {
|
|
|
|
ConfigLexerInput = this;
|
|
|
|
}
|
|
|
|
virtual ~FileInputProvider() { F.close(); ConfigLexerInput = 0; }
|
|
|
|
virtual unsigned read(char *buffer, unsigned max_size) {
|
|
|
|
if (F.good()) {
|
|
|
|
F.read(buffer,max_size);
|
|
|
|
if ( F.gcount() ) return F.gcount() - 1;
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool okay() { return F.good(); }
|
|
|
|
private:
|
|
|
|
std::ifstream F;
|
|
|
|
};
|
|
|
|
|
2004-08-19 12:49:47 +08:00
|
|
|
cl::opt<bool> DumpTokens("dump-tokens", cl::Optional, cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Dump lexical tokens (debug use only)."));
|
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
struct Parser
|
2004-08-14 17:37:15 +08:00
|
|
|
{
|
2004-08-19 12:49:47 +08:00
|
|
|
Parser() {
|
|
|
|
token = EOFTOK;
|
|
|
|
provider = 0;
|
|
|
|
confDat = 0;
|
|
|
|
ConfigLexerState.lineNum = 1;
|
|
|
|
ConfigLexerState.in_value = false;
|
|
|
|
ConfigLexerState.StringVal.clear();
|
|
|
|
ConfigLexerState.IntegerVal = 0;
|
|
|
|
};
|
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
ConfigLexerTokens token;
|
2004-08-14 17:37:15 +08:00
|
|
|
InputProvider* provider;
|
|
|
|
CompilerDriver::ConfigData* confDat;
|
|
|
|
|
2004-08-30 03:26:56 +08:00
|
|
|
inline int next() {
|
2004-08-19 12:49:47 +08:00
|
|
|
token = Configlex();
|
|
|
|
if (DumpTokens)
|
|
|
|
std::cerr << token << "\n";
|
|
|
|
return token;
|
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
|
2004-08-30 03:26:56 +08:00
|
|
|
inline bool next_is_real() {
|
2004-08-19 12:49:47 +08:00
|
|
|
next();
|
2004-08-14 17:37:15 +08:00
|
|
|
return (token != EOLTOK) && (token != ERRORTOK) && (token != 0);
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
|
|
|
|
2004-08-30 03:26:56 +08:00
|
|
|
inline void eatLineRemnant() {
|
2004-08-14 17:37:15 +08:00
|
|
|
while (next_is_real()) ;
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void error(const std::string& msg, bool skip = true) {
|
|
|
|
provider->error(msg);
|
|
|
|
if (skip)
|
|
|
|
eatLineRemnant();
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
std::string parseName() {
|
|
|
|
std::string result;
|
|
|
|
if (next() == EQUALS) {
|
|
|
|
while (next_is_real()) {
|
|
|
|
switch (token ) {
|
|
|
|
case STRING :
|
|
|
|
case OPTION :
|
2004-08-19 12:49:47 +08:00
|
|
|
result += ConfigLexerState.StringVal + " ";
|
2004-08-14 17:37:15 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Invalid name");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.empty())
|
|
|
|
error("Name exepected");
|
|
|
|
else
|
|
|
|
result.erase(result.size()-1,1);
|
|
|
|
} else
|
|
|
|
error("= expected");
|
|
|
|
return result;
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
bool parseBoolean() {
|
|
|
|
bool result = true;
|
|
|
|
if (next() == EQUALS) {
|
|
|
|
if (next() == FALSETOK) {
|
|
|
|
result = false;
|
|
|
|
} else if (token != TRUETOK) {
|
|
|
|
error("Expecting boolean value");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (next() != EOLTOK && token != 0) {
|
|
|
|
error("Extraneous tokens after boolean");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error("Expecting '='");
|
|
|
|
return result;
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-19 12:49:47 +08:00
|
|
|
bool parseSubstitution(CompilerDriver::StringVector& optList) {
|
|
|
|
switch (token) {
|
2004-08-24 22:03:23 +08:00
|
|
|
case ARGS_SUBST: optList.push_back("%args%"); break;
|
2004-08-30 14:29:06 +08:00
|
|
|
case DEFS_SUBST: optList.push_back("%defs%"); break;
|
|
|
|
case FORCE_SUBST: optList.push_back("%force%"); break;
|
2004-08-21 06:53:11 +08:00
|
|
|
case IN_SUBST: optList.push_back("%in%"); break;
|
2004-08-30 14:29:06 +08:00
|
|
|
case INCLS_SUBST: optList.push_back("%incls%"); break;
|
|
|
|
case LIBS_SUBST: optList.push_back("%libs%"); break;
|
2004-08-21 06:53:11 +08:00
|
|
|
case OPT_SUBST: optList.push_back("%opt%"); break;
|
2004-08-30 14:29:06 +08:00
|
|
|
case OUT_SUBST: optList.push_back("%out%"); break;
|
2004-08-21 06:53:11 +08:00
|
|
|
case TARGET_SUBST: optList.push_back("%target%"); break;
|
2004-08-30 14:29:06 +08:00
|
|
|
case STATS_SUBST: optList.push_back("%stats%"); break;
|
|
|
|
case TIME_SUBST: optList.push_back("%time%"); break;
|
2004-08-30 03:26:56 +08:00
|
|
|
case VERBOSE_SUBST: optList.push_back("%verbose%"); break;
|
2004-08-19 12:49:47 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
void parseOptionList(CompilerDriver::StringVector& optList ) {
|
2004-08-19 12:49:47 +08:00
|
|
|
if (next() == EQUALS) {
|
|
|
|
while (next_is_real()) {
|
|
|
|
if (token == STRING || token == OPTION)
|
|
|
|
optList.push_back(ConfigLexerState.StringVal);
|
|
|
|
else if (!parseSubstitution(optList)) {
|
|
|
|
error("Expecting a program argument or substitution", false);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
2004-08-19 12:49:47 +08:00
|
|
|
} else
|
|
|
|
error("Expecting '='");
|
2004-08-15 16:19:46 +08:00
|
|
|
}
|
|
|
|
|
2004-08-23 02:03:25 +08:00
|
|
|
void parseVersion() {
|
|
|
|
if (next() == EQUALS) {
|
|
|
|
while (next_is_real()) {
|
|
|
|
if (token == STRING || token == OPTION)
|
|
|
|
confDat->version = ConfigLexerState.StringVal;
|
|
|
|
else
|
|
|
|
error("Expecting a version string");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
error("Expecting '='");
|
|
|
|
}
|
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
void parseLang() {
|
|
|
|
switch (next() ) {
|
|
|
|
case NAME:
|
|
|
|
confDat->langName = parseName();
|
|
|
|
break;
|
|
|
|
case OPT1:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_FAST_COMPILE]);
|
|
|
|
break;
|
|
|
|
case OPT2:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_SIMPLE]);
|
|
|
|
break;
|
|
|
|
case OPT3:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_AGGRESSIVE]);
|
|
|
|
break;
|
|
|
|
case OPT4:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_LINK_TIME]);
|
|
|
|
break;
|
|
|
|
case OPT5:
|
|
|
|
parseOptionList(
|
|
|
|
confDat->opts[CompilerDriver::OPT_AGGRESSIVE_LINK_TIME]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Expecting 'name' or 'optN' after 'lang.'");
|
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseCommand(CompilerDriver::Action& action) {
|
|
|
|
if (next() == EQUALS) {
|
2004-08-15 16:19:46 +08:00
|
|
|
if (next() == EOLTOK) {
|
2004-08-14 17:37:15 +08:00
|
|
|
// no value (valid)
|
|
|
|
action.program.clear();
|
|
|
|
action.args.clear();
|
|
|
|
} else {
|
|
|
|
if (token == STRING || token == OPTION) {
|
2004-08-30 03:26:56 +08:00
|
|
|
action.program.set_file(ConfigLexerState.StringVal);
|
2004-08-14 17:37:15 +08:00
|
|
|
} else {
|
|
|
|
error("Expecting a program name");
|
|
|
|
}
|
|
|
|
while (next_is_real()) {
|
2004-08-15 16:19:46 +08:00
|
|
|
if (token == STRING || token == OPTION) {
|
2004-08-19 12:49:47 +08:00
|
|
|
action.args.push_back(ConfigLexerState.StringVal);
|
|
|
|
} else if (!parseSubstitution(action.args)) {
|
|
|
|
error("Expecting a program argument or substitution", false);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
void parsePreprocessor() {
|
|
|
|
switch (next()) {
|
|
|
|
case COMMAND:
|
|
|
|
parseCommand(confDat->PreProcessor);
|
|
|
|
break;
|
|
|
|
case REQUIRED:
|
|
|
|
if (parseBoolean())
|
|
|
|
confDat->PreProcessor.set(CompilerDriver::REQUIRED_FLAG);
|
|
|
|
else
|
|
|
|
confDat->PreProcessor.clear(CompilerDriver::REQUIRED_FLAG);
|
|
|
|
break;
|
|
|
|
default:
|
2004-08-24 22:03:23 +08:00
|
|
|
error("Expecting 'command' or 'required' but found '" +
|
|
|
|
ConfigLexerState.StringVal);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-24 22:03:23 +08:00
|
|
|
bool parseOutputFlag() {
|
|
|
|
if (next() == EQUALS) {
|
|
|
|
if (next() == ASSEMBLY) {
|
|
|
|
return true;
|
|
|
|
} else if (token == BYTECODE) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
error("Expecting output type value");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (next() != EOLTOK && token != 0) {
|
|
|
|
error("Extraneous tokens after output value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error("Expecting '='");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseTranslator() {
|
2004-08-15 16:19:46 +08:00
|
|
|
switch (next()) {
|
|
|
|
case COMMAND:
|
|
|
|
parseCommand(confDat->Translator);
|
|
|
|
break;
|
|
|
|
case REQUIRED:
|
|
|
|
if (parseBoolean())
|
|
|
|
confDat->Translator.set(CompilerDriver::REQUIRED_FLAG);
|
|
|
|
else
|
|
|
|
confDat->Translator.clear(CompilerDriver::REQUIRED_FLAG);
|
|
|
|
break;
|
|
|
|
case PREPROCESSES:
|
|
|
|
if (parseBoolean())
|
|
|
|
confDat->Translator.set(CompilerDriver::PREPROCESSES_FLAG);
|
|
|
|
else
|
|
|
|
confDat->Translator.clear(CompilerDriver::PREPROCESSES_FLAG);
|
|
|
|
break;
|
2004-08-24 22:03:23 +08:00
|
|
|
case OUTPUT:
|
|
|
|
if (parseOutputFlag())
|
2004-08-19 12:49:47 +08:00
|
|
|
confDat->Translator.set(CompilerDriver::OUTPUT_IS_ASM_FLAG);
|
2004-08-15 16:19:46 +08:00
|
|
|
else
|
2004-08-19 12:49:47 +08:00
|
|
|
confDat->Translator.clear(CompilerDriver::OUTPUT_IS_ASM_FLAG);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2004-08-19 12:49:47 +08:00
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
default:
|
2004-08-24 22:03:23 +08:00
|
|
|
error("Expecting 'command', 'required', 'preprocesses', or "
|
|
|
|
"'output' but found '" + ConfigLexerState.StringVal +
|
|
|
|
"' instead");
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseOptimizer() {
|
2004-08-15 16:19:46 +08:00
|
|
|
switch (next()) {
|
|
|
|
case COMMAND:
|
|
|
|
parseCommand(confDat->Optimizer);
|
|
|
|
break;
|
2004-08-19 12:49:47 +08:00
|
|
|
case PREPROCESSES:
|
|
|
|
if (parseBoolean())
|
|
|
|
confDat->Optimizer.set(CompilerDriver::PREPROCESSES_FLAG);
|
|
|
|
else
|
|
|
|
confDat->Optimizer.clear(CompilerDriver::PREPROCESSES_FLAG);
|
|
|
|
break;
|
|
|
|
case TRANSLATES:
|
|
|
|
if (parseBoolean())
|
|
|
|
confDat->Optimizer.set(CompilerDriver::TRANSLATES_FLAG);
|
|
|
|
else
|
|
|
|
confDat->Optimizer.clear(CompilerDriver::TRANSLATES_FLAG);
|
|
|
|
break;
|
2004-08-24 22:03:23 +08:00
|
|
|
case REQUIRED:
|
2004-08-15 16:19:46 +08:00
|
|
|
if (parseBoolean())
|
2004-08-24 22:03:23 +08:00
|
|
|
confDat->Optimizer.set(CompilerDriver::REQUIRED_FLAG);
|
2004-08-15 16:19:46 +08:00
|
|
|
else
|
2004-08-24 22:03:23 +08:00
|
|
|
confDat->Optimizer.clear(CompilerDriver::REQUIRED_FLAG);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2004-08-24 22:03:23 +08:00
|
|
|
case OUTPUT:
|
|
|
|
if (parseOutputFlag())
|
2004-08-19 12:49:47 +08:00
|
|
|
confDat->Translator.set(CompilerDriver::OUTPUT_IS_ASM_FLAG);
|
2004-08-15 16:19:46 +08:00
|
|
|
else
|
2004-08-19 12:49:47 +08:00
|
|
|
confDat->Translator.clear(CompilerDriver::OUTPUT_IS_ASM_FLAG);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
|
|
|
default:
|
2004-08-24 22:03:23 +08:00
|
|
|
error(std::string("Expecting 'command', 'preprocesses', ") +
|
|
|
|
"'translates' or 'output' but found '" +
|
|
|
|
ConfigLexerState.StringVal + "' instead");
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseAssembler() {
|
2004-08-15 16:19:46 +08:00
|
|
|
switch(next()) {
|
|
|
|
case COMMAND:
|
|
|
|
parseCommand(confDat->Assembler);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Expecting 'command'");
|
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseLinker() {
|
2004-08-15 16:19:46 +08:00
|
|
|
switch(next()) {
|
2004-08-24 22:03:23 +08:00
|
|
|
case LIBS:
|
|
|
|
break; //FIXME
|
|
|
|
case LIBPATHS:
|
|
|
|
break; //FIXME
|
2004-08-15 16:19:46 +08:00
|
|
|
default:
|
2004-08-24 22:03:23 +08:00
|
|
|
error("Expecting 'libs' or 'libpaths'");
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseAssignment() {
|
|
|
|
switch (token) {
|
2004-08-23 02:03:25 +08:00
|
|
|
case VERSION: parseVersion(); break;
|
2004-08-15 16:19:46 +08:00
|
|
|
case LANG: parseLang(); break;
|
|
|
|
case PREPROCESSOR: parsePreprocessor(); break;
|
|
|
|
case TRANSLATOR: parseTranslator(); break;
|
|
|
|
case OPTIMIZER: parseOptimizer(); break;
|
|
|
|
case ASSEMBLER: parseAssembler(); break;
|
|
|
|
case LINKER: parseLinker(); break;
|
2004-08-14 17:37:15 +08:00
|
|
|
case EOLTOK: break; // just ignore
|
|
|
|
case ERRORTOK:
|
|
|
|
default:
|
2004-08-15 16:19:46 +08:00
|
|
|
error("Invalid top level configuration item");
|
|
|
|
break;
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-14 04:21:22 +08:00
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseFile() {
|
2004-08-15 16:19:46 +08:00
|
|
|
while ( next() != EOFTOK ) {
|
|
|
|
if (token == ERRORTOK)
|
|
|
|
error("Invalid token");
|
|
|
|
else if (token != EOLTOK)
|
|
|
|
parseAssignment();
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
provider->checkErrors();
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ParseConfigData(InputProvider& provider, CompilerDriver::ConfigData& confDat) {
|
2004-08-15 16:19:46 +08:00
|
|
|
Parser p;
|
|
|
|
p.token = EOFTOK;
|
|
|
|
p.provider = &provider;
|
|
|
|
p.confDat = &confDat;
|
|
|
|
p.parseFile();
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CompilerDriver::ConfigData*
|
2004-08-14 17:37:15 +08:00
|
|
|
LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
|
|
|
|
CompilerDriver::ConfigData* result = 0;
|
2004-08-30 03:26:56 +08:00
|
|
|
sys::Path confFile;
|
|
|
|
if (configDir.is_empty()) {
|
2004-08-20 17:24:07 +08:00
|
|
|
// Try the environment variable
|
|
|
|
const char* conf = getenv("LLVM_CONFIG_DIR");
|
|
|
|
if (conf) {
|
2004-08-30 03:26:56 +08:00
|
|
|
confFile.set_directory(conf);
|
|
|
|
confFile.append_file(ftype);
|
|
|
|
if (!confFile.readable())
|
2004-08-30 14:29:06 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
|
|
|
"' is not available.";
|
2004-08-20 17:24:07 +08:00
|
|
|
} else {
|
|
|
|
// Try the user's home directory
|
2004-08-30 03:26:56 +08:00
|
|
|
confFile = sys::Path::GetUserHomeDirectory();
|
|
|
|
if (!confFile.is_empty()) {
|
|
|
|
confFile.append_directory(".llvm");
|
|
|
|
confFile.append_directory("etc");
|
|
|
|
confFile.append_file(ftype);
|
|
|
|
if (!confFile.readable())
|
|
|
|
confFile.clear();
|
|
|
|
}
|
|
|
|
if (!confFile.is_empty()) {
|
|
|
|
// Okay, try the LLVM installation directory
|
|
|
|
confFile = sys::Path::GetLLVMConfigDir();
|
|
|
|
confFile.append_file(ftype);
|
|
|
|
if (!confFile.readable()) {
|
|
|
|
// Okay, try the "standard" place
|
|
|
|
confFile = sys::Path::GetLLVMDefaultConfigDir();
|
|
|
|
confFile.append_file(ftype);
|
|
|
|
if (!confFile.readable()) {
|
2004-08-30 14:29:06 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
|
|
|
"' is not available.";
|
2004-08-20 17:24:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
}
|
|
|
|
} else {
|
2004-08-30 03:26:56 +08:00
|
|
|
confFile = configDir;
|
|
|
|
confFile.append_file(ftype);
|
|
|
|
if (!confFile.readable())
|
2004-08-30 14:29:06 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
|
|
|
"' is not available.";
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
2004-08-30 03:26:56 +08:00
|
|
|
FileInputProvider fip( confFile.get() );
|
2004-08-20 17:24:07 +08:00
|
|
|
if (!fip.okay()) {
|
2004-08-30 14:29:06 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
|
|
|
"' is not available.";
|
2004-08-20 17:24:07 +08:00
|
|
|
}
|
|
|
|
result = new CompilerDriver::ConfigData();
|
|
|
|
ParseConfigData(fip,*result);
|
2004-08-14 17:37:15 +08:00
|
|
|
return result;
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMC_ConfigDataProvider::~LLVMC_ConfigDataProvider()
|
|
|
|
{
|
|
|
|
ConfigDataMap::iterator cIt = Configurations.begin();
|
|
|
|
while (cIt != Configurations.end()) {
|
|
|
|
CompilerDriver::ConfigData* cd = cIt->second;
|
|
|
|
++cIt;
|
|
|
|
delete cd;
|
|
|
|
}
|
|
|
|
Configurations.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CompilerDriver::ConfigData*
|
|
|
|
LLVMC_ConfigDataProvider::ProvideConfigData(const std::string& filetype) {
|
|
|
|
CompilerDriver::ConfigData* result = 0;
|
|
|
|
if (!Configurations.empty()) {
|
|
|
|
ConfigDataMap::iterator cIt = Configurations.find(filetype);
|
|
|
|
if ( cIt != Configurations.end() ) {
|
|
|
|
// We found one in the case, return it.
|
|
|
|
result = cIt->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == 0) {
|
|
|
|
// The configuration data doesn't exist, we have to go read it.
|
|
|
|
result = ReadConfigData(filetype);
|
|
|
|
// If we got one, cache it
|
2004-08-30 03:26:56 +08:00
|
|
|
if (result != 0)
|
2004-08-14 04:21:22 +08:00
|
|
|
Configurations.insert(std::make_pair(filetype,result));
|
|
|
|
}
|
|
|
|
return result; // Might return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|