Implement the "setIncludePaths" and "setSymbolDefines" interface methods.

Revise token substitution to be a little faster.
Clean up exception throwing, make sure its always a std::string.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16116 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2004-08-30 06:29:06 +00:00
parent 7c14fd152e
commit ca01f9bc6f
5 changed files with 159 additions and 52 deletions

View File

@ -123,6 +123,21 @@ namespace {
AdditionalArgs[phase] = opts; AdditionalArgs[phase] = opts;
} }
virtual void setIncludePaths(const StringVector& paths) {
StringVector::const_iterator I = paths.begin();
StringVector::const_iterator E = paths.end();
while (I != E) {
sys::Path tmp;
tmp.set_directory(*I);
IncludePaths.push_back(tmp);
++I;
}
}
virtual void setSymbolDefines(const StringVector& defs) {
Defines = defs;
}
virtual void setLibraryPaths(const StringVector& paths) { virtual void setLibraryPaths(const StringVector& paths) {
StringVector::const_iterator I = paths.begin(); StringVector::const_iterator I = paths.begin();
StringVector::const_iterator E = paths.end(); StringVector::const_iterator E = paths.end();
@ -193,25 +208,66 @@ namespace {
StringVector::iterator PI = pat->args.begin(); StringVector::iterator PI = pat->args.begin();
StringVector::iterator PE = pat->args.end(); StringVector::iterator PE = pat->args.end();
while (PI != PE) { while (PI != PE) {
if ((*PI)[0] == '%') { if ((*PI)[0] == '%' && PI->length() >2) {
if (*PI == "%in%") { bool found = true;
action->args.push_back(input.get()); switch ((*PI)[1]) {
} else if (*PI == "%out%") { case 'a':
action->args.push_back(output.get()); if (*PI == "%args%") {
} else if (*PI == "%time%") { if (AdditionalArgs.size() > unsigned(phase))
if (isSet(TIME_PASSES_FLAG)) if (!AdditionalArgs[phase].empty()) {
action->args.push_back("-time-passes"); // Get specific options for each kind of action type
} else if (*PI == "%stats%") { StringVector& addargs = AdditionalArgs[phase];
if (isSet(SHOW_STATS_FLAG)) // Add specific options for each kind of action type
action->args.push_back("-stats"); action->args.insert(action->args.end(), addargs.begin(), addargs.end());
} else if (*PI == "%force%") { }
} else
found = false;
break;
case 'd':
if (*PI == "%defs%") {
StringVector::iterator I = Defines.begin();
StringVector::iterator E = Defines.end();
while (I != E) {
action->args.push_back( std::string("-D") + *I);
++I;
}
} else
found = false;
break;
case 'f':
if (*PI == "%force%") {
if (isSet(FORCE_FLAG)) if (isSet(FORCE_FLAG))
action->args.push_back("-f"); action->args.push_back("-f");
} else if (*PI == "%verbose%") { } else
if (isSet(VERBOSE_FLAG)) found = false;
action->args.push_back("-v"); break;
} else if (*PI == "%target%") { case 'i':
// FIXME: Ignore for now if (*PI == "%in%") {
action->args.push_back(input.get());
} else if (*PI == "%incls%") {
PathVector::iterator I = IncludePaths.begin();
PathVector::iterator E = IncludePaths.end();
while (I != E) {
action->args.push_back( std::string("-I") + I->get() );
++I;
}
} else
found = false;
break;
case 'l':
if (*PI == "%libs%") {
PathVector::iterator I = LibraryPaths.begin();
PathVector::iterator E = LibraryPaths.end();
while (I != E) {
action->args.push_back( std::string("-L") + I->get() );
++I;
}
} else
found = false;
break;
case 'o':
if (*PI == "%out%") {
action->args.push_back(output.get());
} else if (*PI == "%opt%") { } else if (*PI == "%opt%") {
if (!isSet(EMIT_RAW_FLAG)) { if (!isSet(EMIT_RAW_FLAG)) {
if (cd->opts.size() > static_cast<unsigned>(optLevel) && if (cd->opts.size() > static_cast<unsigned>(optLevel) &&
@ -222,16 +278,46 @@ namespace {
throw std::string("Optimization options for level ") + throw std::string("Optimization options for level ") +
utostr(unsigned(optLevel)) + " were not specified"; utostr(unsigned(optLevel)) + " were not specified";
} }
} else if (*PI == "%args%") { } else
if (AdditionalArgs.size() > unsigned(phase)) found = false;
if (!AdditionalArgs[phase].empty()) { break;
// Get specific options for each kind of action type case 's':
StringVector& addargs = AdditionalArgs[phase]; if (*PI == "%stats%") {
// Add specific options for each kind of action type if (isSet(SHOW_STATS_FLAG))
action->args.insert(action->args.end(), addargs.begin(), addargs.end()); action->args.push_back("-stats");
} else
found = false;
break;
case 't':
if (*PI == "%target%") {
action->args.push_back(std::string("-march=") + machine);
} else if (*PI == "%time%") {
if (isSet(TIME_PASSES_FLAG))
action->args.push_back("-time-passes");
} else
found = false;
break;
case 'v':
if (*PI == "%verbose%") {
if (isSet(VERBOSE_FLAG))
action->args.push_back("-v");
} else
found = false;
break;
default:
found = false;
break;
} }
if (!found) {
// Did it even look like a substitution?
if (PI->length()>1 && (*PI)[0] == '%' &&
(*PI)[PI->length()-1] == '%') {
throw std::string("Invalid substitution token: '") + *PI +
"' for command '" + pat->program.get() + "'";
} else { } else {
throw "Invalid substitution name" + *PI; // It's not a legal substitution, just pass it through
action->args.push_back(*PI);
}
} }
} else { } else {
// Its not a substitution, just put it in the action // Its not a substitution, just put it in the action
@ -240,7 +326,6 @@ namespace {
PI++; PI++;
} }
// Finally, we're done // Finally, we're done
return action; return action;
} }
@ -252,7 +337,7 @@ namespace {
if (!isSet(DRY_RUN_FLAG)) { if (!isSet(DRY_RUN_FLAG)) {
action->program = sys::Program::FindProgramByName(action->program.get()); action->program = sys::Program::FindProgramByName(action->program.get());
if (action->program.is_empty()) if (action->program.is_empty())
throw "Can't find program '" + action->program.get() + "'"; throw std::string("Can't find program '") + action->program.get() + "'";
// Invoke the program // Invoke the program
return 0 == action->program.ExecuteAndWait(action->args); return 0 == action->program.ExecuteAndWait(action->args);
@ -571,7 +656,7 @@ namespace {
std::vector<Action*>::iterator AE = actions.end(); std::vector<Action*>::iterator AE = actions.end();
while (AI != AE) { while (AI != AE) {
if (!DoAction(*AI)) if (!DoAction(*AI))
throw "Action failed"; throw std::string("Action failed");
AI++; AI++;
} }
@ -579,7 +664,8 @@ namespace {
actions.clear(); actions.clear();
if (finalPhase == LINKING) { if (finalPhase == LINKING) {
if (isSet(EMIT_NATIVE_FLAG)) { if (isSet(EMIT_NATIVE_FLAG)) {
throw "llvmc doesn't know how to link native code yet"; throw std::string(
"llvmc doesn't know how to link native code yet");
} else { } else {
// First, we need to examine the files to ensure that they all contain // First, we need to examine the files to ensure that they all contain
// bytecode files. Since the final output is bytecode, we can only // bytecode files. Since the final output is bytecode, we can only
@ -646,6 +732,8 @@ namespace {
unsigned Flags; ///< The driver flags unsigned Flags; ///< The driver flags
std::string machine; ///< Target machine name std::string machine; ///< Target machine name
PathVector LibraryPaths; ///< -L options PathVector LibraryPaths; ///< -L options
PathVector IncludePaths; ///< -I options
StringVector Defines; ///< -D options
sys::Path TempDir; ///< Name of the temporary directory. sys::Path TempDir; ///< Name of the temporary directory.
StringTable AdditionalArgs; ///< The -Txyz options StringTable AdditionalArgs; ///< The -Txyz options

View File

@ -160,6 +160,12 @@ namespace llvm {
/// @brief Set Preprocessor specific options /// @brief Set Preprocessor specific options
virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0; virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0;
/// @brief Set Library Paths
virtual void setIncludePaths(const StringVector& paths) = 0;
/// @brief Set Library Paths
virtual void setSymbolDefines(const StringVector& paths) = 0;
/// @brief Set Library Paths /// @brief Set Library Paths
virtual void setLibraryPaths(const StringVector& paths) = 0; virtual void setLibraryPaths(const StringVector& paths) = 0;

View File

@ -55,14 +55,17 @@ enum ConfigLexerTokens {
ASSEMBLER, ///< The name "assembler" (and variants) ASSEMBLER, ///< The name "assembler" (and variants)
BYTECODE, ///< The value "bytecode" (and variants) BYTECODE, ///< The value "bytecode" (and variants)
COMMAND, ///< The name "command" (and variants) COMMAND, ///< The name "command" (and variants)
DEFS_SUBST, ///< The substitution item %defs%
EQUALS, ///< The equals sign, = EQUALS, ///< The equals sign, =
FALSETOK, ///< A boolean false value (false/no/off) FALSETOK, ///< A boolean false value (false/no/off)
FORCE_SUBST, ///< The substitution item %force% FORCE_SUBST, ///< The substitution item %force%
IN_SUBST, ///< The substitution item %in% IN_SUBST, ///< The substitution item %in%
INCLS_SUBST, ///< The substitution item %incls%
INTEGER, ///< An integer INTEGER, ///< An integer
LANG, ///< The name "lang" (and variants) LANG, ///< The name "lang" (and variants)
LIBPATHS, ///< The name "libpaths" (and variants) LIBPATHS, ///< The name "libpaths" (and variants)
LIBS, ///< The name "libs" (and variants) LIBS, ///< The name "libs" (and variants)
LIBS_SUBST, ///< The substitution item %libs%
LINKER, ///< The name "linker" (and variants) LINKER, ///< The name "linker" (and variants)
NAME, ///< The name "name" (and variants) NAME, ///< The name "name" (and variants)
OPT_SUBST, ///< The substitution item %opt% OPT_SUBST, ///< The substitution item %opt%

View File

@ -160,8 +160,11 @@ White [ \t]*
{LINKER} { return handleNameContext(LINKER); } {LINKER} { return handleNameContext(LINKER); }
%args% { return handleSubstitution(ARGS_SUBST); } %args% { return handleSubstitution(ARGS_SUBST); }
%defs% { return handleSubstitution(DEFS_SUBST); }
%force% { return handleSubstitution(FORCE_SUBST); } %force% { return handleSubstitution(FORCE_SUBST); }
%in% { return handleSubstitution(IN_SUBST); } %in% { return handleSubstitution(IN_SUBST); }
%incls% { return handleSubstitution(INCLS_SUBST); }
%libs% { return handleSubstitution(LIBS_SUBST); }
%opt% { return handleSubstitution(OPT_SUBST); } %opt% { return handleSubstitution(OPT_SUBST); }
%out% { return handleSubstitution(OUT_SUBST); } %out% { return handleSubstitution(OUT_SUBST); }
%stats% { return handleSubstitution(STATS_SUBST); } %stats% { return handleSubstitution(STATS_SUBST); }

View File

@ -156,13 +156,16 @@ namespace {
bool parseSubstitution(CompilerDriver::StringVector& optList) { bool parseSubstitution(CompilerDriver::StringVector& optList) {
switch (token) { switch (token) {
case ARGS_SUBST: optList.push_back("%args%"); break; case ARGS_SUBST: optList.push_back("%args%"); break;
case IN_SUBST: optList.push_back("%in%"); break; case DEFS_SUBST: optList.push_back("%defs%"); break;
case OUT_SUBST: optList.push_back("%out%"); break;
case TIME_SUBST: optList.push_back("%time%"); break;
case STATS_SUBST: optList.push_back("%stats%"); break;
case OPT_SUBST: optList.push_back("%opt%"); break;
case TARGET_SUBST: optList.push_back("%target%"); break;
case FORCE_SUBST: optList.push_back("%force%"); break; case FORCE_SUBST: optList.push_back("%force%"); break;
case IN_SUBST: optList.push_back("%in%"); break;
case INCLS_SUBST: optList.push_back("%incls%"); break;
case LIBS_SUBST: optList.push_back("%libs%"); break;
case OPT_SUBST: optList.push_back("%opt%"); break;
case OUT_SUBST: optList.push_back("%out%"); break;
case TARGET_SUBST: optList.push_back("%target%"); break;
case STATS_SUBST: optList.push_back("%stats%"); break;
case TIME_SUBST: optList.push_back("%time%"); break;
case VERBOSE_SUBST: optList.push_back("%verbose%"); break; case VERBOSE_SUBST: optList.push_back("%verbose%"); break;
default: default:
return false; return false;
@ -425,7 +428,8 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
confFile.set_directory(conf); confFile.set_directory(conf);
confFile.append_file(ftype); confFile.append_file(ftype);
if (!confFile.readable()) if (!confFile.readable())
throw "Configuration file for '" + ftype + "' is not available."; throw std::string("Configuration file for '") + ftype +
"' is not available.";
} else { } else {
// Try the user's home directory // Try the user's home directory
confFile = sys::Path::GetUserHomeDirectory(); confFile = sys::Path::GetUserHomeDirectory();
@ -445,7 +449,8 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
confFile = sys::Path::GetLLVMDefaultConfigDir(); confFile = sys::Path::GetLLVMDefaultConfigDir();
confFile.append_file(ftype); confFile.append_file(ftype);
if (!confFile.readable()) { if (!confFile.readable()) {
throw "Configuration file for '" + ftype + "' is not available."; throw std::string("Configuration file for '") + ftype +
"' is not available.";
} }
} }
} }
@ -454,11 +459,13 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
confFile = configDir; confFile = configDir;
confFile.append_file(ftype); confFile.append_file(ftype);
if (!confFile.readable()) if (!confFile.readable())
throw "Configuration file for '" + ftype + "' is not available."; throw std::string("Configuration file for '") + ftype +
"' is not available.";
} }
FileInputProvider fip( confFile.get() ); FileInputProvider fip( confFile.get() );
if (!fip.okay()) { if (!fip.okay()) {
throw "Configuration file for '" + ftype + "' is not available."; throw std::string("Configuration file for '") + ftype +
"' is not available.";
} }
result = new CompilerDriver::ConfigData(); result = new CompilerDriver::ConfigData();
ParseConfigData(fip,*result); ParseConfigData(fip,*result);