2004-08-20 05:17:53 +08:00
|
|
|
//===- Configuration.cpp - Configuration Data Mgmt --------------*- C++ -*-===//
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2004-08-14 04:21:22 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-22 08:00:37 +08:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-08-14 04:21:22 +08:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2004-08-14 04:21:22 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Config/config.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2004-08-14 04:21:22 +08:00
|
|
|
#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) {
|
2005-04-22 08:00:37 +08:00
|
|
|
std::cerr << name << ":" << ConfigLexerState.lineNum << ": Error: " <<
|
2004-08-19 12:49:47 +08:00
|
|
|
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)
|
2005-04-22 08:00:37 +08:00
|
|
|
: InputProvider(fname)
|
2004-08-14 17:37:15 +08:00
|
|
|
, 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;
|
|
|
|
};
|
|
|
|
|
2005-04-22 08:00:37 +08:00
|
|
|
cl::opt<bool> DumpTokens("dump-tokens", cl::Optional, cl::Hidden,
|
2004-10-28 12:04:38 +08:00
|
|
|
cl::init(false), cl::desc("Dump lexical tokens (debug use only)."));
|
2004-08-19 12:49:47 +08:00
|
|
|
|
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;
|
|
|
|
|
2005-04-22 08:00:37 +08:00
|
|
|
inline int next() {
|
2004-08-19 12:49:47 +08:00
|
|
|
token = Configlex();
|
2005-04-22 08:00:37 +08:00
|
|
|
if (DumpTokens)
|
2004-08-19 12:49:47 +08:00
|
|
|
std::cerr << token << "\n";
|
|
|
|
return token;
|
|
|
|
}
|
2004-08-14 17:37:15 +08:00
|
|
|
|
2005-04-22 08:00:37 +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-11-24 07:37:26 +08:00
|
|
|
bool parseCompleteItem(std::string& result) {
|
|
|
|
result.clear();
|
|
|
|
while (next_is_real()) {
|
|
|
|
switch (token ) {
|
|
|
|
case STRING :
|
2005-04-22 08:00:37 +08:00
|
|
|
case OPTION :
|
2004-11-24 07:37:26 +08:00
|
|
|
result += ConfigLexerState.StringVal;
|
|
|
|
break;
|
|
|
|
case SEPARATOR:
|
|
|
|
result += ".";
|
|
|
|
break;
|
|
|
|
case SPACE:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
std::string parseName() {
|
|
|
|
std::string result;
|
|
|
|
if (next() == EQUALS) {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (parseCompleteItem(result))
|
|
|
|
eatLineRemnant();
|
2004-08-14 17:37:15 +08:00
|
|
|
if (result.empty())
|
|
|
|
error("Name exepected");
|
|
|
|
} else
|
2004-11-24 07:37:26 +08:00
|
|
|
error("Expecting '='");
|
2004-08-14 17:37:15 +08:00
|
|
|
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) {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (next() == SPACE)
|
|
|
|
next();
|
|
|
|
if (token == FALSETOK) {
|
2004-08-14 17:37:15 +08:00
|
|
|
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;
|
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-11-24 07:37:26 +08:00
|
|
|
case FOPTS_SUBST: optList.push_back("%fOpts%"); break;
|
|
|
|
case MOPTS_SUBST: optList.push_back("%Mopts%"); break;
|
|
|
|
case WOPTS_SUBST: optList.push_back("%Wopts%"); 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() {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (next() != EQUALS)
|
2004-08-23 02:03:25 +08:00
|
|
|
error("Expecting '='");
|
2004-11-24 07:37:26 +08:00
|
|
|
while (next_is_real()) {
|
|
|
|
if (token == STRING || token == OPTION)
|
|
|
|
confDat->version = ConfigLexerState.StringVal;
|
|
|
|
else
|
|
|
|
error("Expecting a version string");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void parseLibs() {
|
|
|
|
if (next() != EQUALS)
|
|
|
|
error("Expecting '='");
|
|
|
|
std::string lib;
|
|
|
|
while (parseCompleteItem(lib)) {
|
|
|
|
if (!lib.empty()) {
|
|
|
|
confDat->libpaths.push_back(lib);
|
|
|
|
}
|
|
|
|
}
|
2004-08-23 02:03:25 +08:00
|
|
|
}
|
|
|
|
|
2004-08-15 16:19:46 +08:00
|
|
|
void parseLang() {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (next() != SEPARATOR)
|
|
|
|
error("Expecting '.'");
|
2004-08-15 16:19:46 +08:00
|
|
|
switch (next() ) {
|
2004-11-24 07:37:26 +08:00
|
|
|
case LIBS:
|
|
|
|
parseLibs();
|
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
case NAME:
|
|
|
|
confDat->langName = parseName();
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
case OPT1:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_FAST_COMPILE]);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
case OPT2:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_SIMPLE]);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
case OPT3:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_AGGRESSIVE]);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
case OPT4:
|
|
|
|
parseOptionList(confDat->opts[CompilerDriver::OPT_LINK_TIME]);
|
2004-08-15 16:19:46 +08:00
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
case OPT5:
|
2004-08-15 16:19:46 +08:00
|
|
|
parseOptionList(
|
|
|
|
confDat->opts[CompilerDriver::OPT_AGGRESSIVE_LINK_TIME]);
|
|
|
|
break;
|
2005-04-22 08:00:37 +08:00
|
|
|
default:
|
|
|
|
error("Expecting 'name' or 'optN' after 'lang.'");
|
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-11-24 07:37:26 +08:00
|
|
|
bool parseProgramName(std::string& str) {
|
|
|
|
str.clear();
|
|
|
|
do {
|
|
|
|
switch (token) {
|
|
|
|
case OPTION:
|
|
|
|
case STRING:
|
|
|
|
case ARGS_SUBST:
|
|
|
|
case DEFS_SUBST:
|
|
|
|
case IN_SUBST:
|
|
|
|
case INCLS_SUBST:
|
|
|
|
case LIBS_SUBST:
|
|
|
|
case OPT_SUBST:
|
|
|
|
case OUT_SUBST:
|
|
|
|
case STATS_SUBST:
|
|
|
|
case TARGET_SUBST:
|
|
|
|
case TIME_SUBST:
|
|
|
|
case VERBOSE_SUBST:
|
|
|
|
case FOPTS_SUBST:
|
|
|
|
case MOPTS_SUBST:
|
|
|
|
case WOPTS_SUBST:
|
|
|
|
str += ConfigLexerState.StringVal;
|
|
|
|
break;
|
|
|
|
case SEPARATOR:
|
|
|
|
str += ".";
|
|
|
|
break;
|
|
|
|
case ASSEMBLY:
|
|
|
|
str += "assembly";
|
|
|
|
break;
|
|
|
|
case BYTECODE:
|
|
|
|
str += "bytecode";
|
|
|
|
break;
|
|
|
|
case TRUETOK:
|
|
|
|
str += "true";
|
|
|
|
break;
|
|
|
|
case FALSETOK:
|
|
|
|
str += "false";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
next();
|
2005-04-22 08:00:37 +08:00
|
|
|
} while (token != SPACE && token != EOFTOK && token != EOLTOK &&
|
2004-11-24 07:37:26 +08:00
|
|
|
token != ERRORTOK);
|
|
|
|
return !str.empty();
|
|
|
|
}
|
|
|
|
|
2004-08-14 17:37:15 +08:00
|
|
|
void parseCommand(CompilerDriver::Action& action) {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (next() != EQUALS)
|
|
|
|
error("Expecting '='");
|
|
|
|
switch (next()) {
|
|
|
|
case EOLTOK:
|
2004-08-14 17:37:15 +08:00
|
|
|
// no value (valid)
|
|
|
|
action.program.clear();
|
|
|
|
action.args.clear();
|
2004-11-24 07:37:26 +08:00
|
|
|
break;
|
|
|
|
case SPACE:
|
|
|
|
next();
|
|
|
|
/* FALL THROUGH */
|
2005-04-22 08:00:37 +08:00
|
|
|
default:
|
2004-11-24 07:37:26 +08:00
|
|
|
{
|
|
|
|
std::string progname;
|
|
|
|
if (parseProgramName(progname))
|
|
|
|
action.program.setFile(progname);
|
|
|
|
else
|
2004-08-14 17:37:15 +08:00
|
|
|
error("Expecting a program name");
|
2004-11-24 07:37:26 +08:00
|
|
|
|
|
|
|
// Get the options
|
|
|
|
std::string anOption;
|
2004-08-14 17:37:15 +08:00
|
|
|
while (next_is_real()) {
|
2004-11-24 07:37:26 +08:00
|
|
|
switch (token) {
|
|
|
|
case STRING:
|
|
|
|
case OPTION:
|
|
|
|
anOption += ConfigLexerState.StringVal;
|
|
|
|
break;
|
|
|
|
case ASSEMBLY:
|
|
|
|
anOption += "assembly";
|
|
|
|
break;
|
|
|
|
case BYTECODE:
|
|
|
|
anOption += "bytecode";
|
|
|
|
break;
|
|
|
|
case TRUETOK:
|
|
|
|
anOption += "true";
|
|
|
|
break;
|
|
|
|
case FALSETOK:
|
|
|
|
anOption += "false";
|
|
|
|
break;
|
|
|
|
case SEPARATOR:
|
|
|
|
anOption += ".";
|
|
|
|
break;
|
|
|
|
case SPACE:
|
|
|
|
action.args.push_back(anOption);
|
|
|
|
anOption.clear();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!parseSubstitution(action.args))
|
|
|
|
error("Expecting a program argument or substitution", false);
|
|
|
|
break;
|
2004-08-15 16:19:46 +08:00
|
|
|
}
|
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() {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (next() != SEPARATOR)
|
|
|
|
error("Expecting '.'");
|
2004-08-15 16:19:46 +08:00
|
|
|
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) {
|
2004-11-24 07:37:26 +08:00
|
|
|
if (next() == SPACE)
|
|
|
|
next();
|
|
|
|
if (token == ASSEMBLY) {
|
2004-08-24 22:03:23 +08:00
|
|
|
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-11-24 07:37:26 +08:00
|
|
|
if (next() != SEPARATOR)
|
|
|
|
error("Expecting '.'");
|
2004-08-15 16:19:46 +08:00
|
|
|
switch (next()) {
|
2005-04-22 08:00:37 +08:00
|
|
|
case COMMAND:
|
2004-08-15 16:19:46 +08:00
|
|
|
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);
|
2005-04-22 08:00:37 +08:00
|
|
|
else
|
2004-08-15 16:19:46 +08:00
|
|
|
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-11-24 07:37:26 +08:00
|
|
|
if (next() != SEPARATOR)
|
|
|
|
error("Expecting '.'");
|
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:
|
2005-04-22 08:00:37 +08:00
|
|
|
error(std::string("Expecting 'command', 'preprocesses', "
|
|
|
|
"'translates' or 'output' but found '") +
|
2004-08-24 22:03:23 +08:00
|
|
|
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-11-24 07:37:26 +08:00
|
|
|
if (next() != SEPARATOR)
|
|
|
|
error("Expecting '.'");
|
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-11-24 07:37:26 +08:00
|
|
|
if (next() != SEPARATOR)
|
|
|
|
error("Expecting '.'");
|
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-10-28 12:04:38 +08:00
|
|
|
case VERSION_TOK: 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:
|
2005-04-22 08:00:37 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2004-10-28 12:04:38 +08:00
|
|
|
void
|
|
|
|
ParseConfigData(InputProvider& provider, CompilerDriver::ConfigData& confDat) {
|
|
|
|
Parser p;
|
|
|
|
p.token = EOFTOK;
|
|
|
|
p.provider = &provider;
|
|
|
|
p.confDat = &confDat;
|
|
|
|
p.parseFile();
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
2004-10-28 12:04:38 +08:00
|
|
|
|
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;
|
2004-11-06 06:15:36 +08:00
|
|
|
if (configDir.isEmpty()) {
|
2004-08-20 17:24:07 +08:00
|
|
|
// Try the environment variable
|
|
|
|
const char* conf = getenv("LLVM_CONFIG_DIR");
|
|
|
|
if (conf) {
|
2004-11-06 06:15:36 +08:00
|
|
|
confFile.setDirectory(conf);
|
|
|
|
confFile.appendFile(ftype);
|
2004-08-30 03:26:56 +08:00
|
|
|
if (!confFile.readable())
|
2005-04-22 08:00:37 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
2004-08-30 14:29:06 +08:00
|
|
|
"' 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();
|
2004-11-06 06:15:36 +08:00
|
|
|
if (!confFile.isEmpty()) {
|
|
|
|
confFile.appendDirectory(".llvm");
|
|
|
|
confFile.appendDirectory("etc");
|
|
|
|
confFile.appendFile(ftype);
|
2004-08-30 03:26:56 +08:00
|
|
|
if (!confFile.readable())
|
|
|
|
confFile.clear();
|
|
|
|
}
|
2004-11-06 06:15:36 +08:00
|
|
|
if (!confFile.isEmpty()) {
|
2004-08-30 03:26:56 +08:00
|
|
|
// Okay, try the LLVM installation directory
|
|
|
|
confFile = sys::Path::GetLLVMConfigDir();
|
2004-11-06 06:15:36 +08:00
|
|
|
confFile.appendFile(ftype);
|
2004-08-30 03:26:56 +08:00
|
|
|
if (!confFile.readable()) {
|
|
|
|
// Okay, try the "standard" place
|
|
|
|
confFile = sys::Path::GetLLVMDefaultConfigDir();
|
2004-11-06 06:15:36 +08:00
|
|
|
confFile.appendFile(ftype);
|
2004-08-30 03:26:56 +08:00
|
|
|
if (!confFile.readable()) {
|
2005-04-22 08:00:37 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
2004-08-30 14:29:06 +08:00
|
|
|
"' 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;
|
2004-11-06 06:15:36 +08:00
|
|
|
confFile.appendFile(ftype);
|
2004-08-30 03:26:56 +08:00
|
|
|
if (!confFile.readable())
|
2005-04-22 08:00:37 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
2004-08-30 14:29:06 +08:00
|
|
|
"' is not available.";
|
2004-08-14 04:21:22 +08:00
|
|
|
}
|
2004-12-11 08:14:15 +08:00
|
|
|
FileInputProvider fip( confFile.toString() );
|
2004-08-20 17:24:07 +08:00
|
|
|
if (!fip.okay()) {
|
2005-04-22 08:00:37 +08:00
|
|
|
throw std::string("Configuration file for '") + ftype +
|
2004-08-30 14:29:06 +08:00
|
|
|
"' 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();
|
|
|
|
}
|
|
|
|
|
2005-04-22 08:00:37 +08:00
|
|
|
CompilerDriver::ConfigData*
|
2004-08-14 04:21:22 +08:00
|
|
|
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
|
|
|
|
}
|