mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
Make it possible to use hooks like this: '$CALL(MyHook)/path/to/file'.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51734 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -862,19 +862,36 @@ void EmitOptionPropertyHandlingCode (const ToolOptionDescription& D,
|
|||||||
/// SubstituteSpecialCommands - Perform string substitution for $CALL
|
/// SubstituteSpecialCommands - Perform string substitution for $CALL
|
||||||
/// and $ENV. Helper function used by EmitCmdLineVecFill().
|
/// and $ENV. Helper function used by EmitCmdLineVecFill().
|
||||||
std::string SubstituteSpecialCommands(const std::string& cmd) {
|
std::string SubstituteSpecialCommands(const std::string& cmd) {
|
||||||
|
size_t cparen = cmd.find(")");
|
||||||
|
std::string ret;
|
||||||
|
|
||||||
if (cmd.find("$CALL(") == 0) {
|
if (cmd.find("$CALL(") == 0) {
|
||||||
if (cmd.size() == 6)
|
if (cmd.size() == 6)
|
||||||
throw std::string("$CALL invocation: empty argument list!");
|
throw std::string("$CALL invocation: empty argument list!");
|
||||||
return std::string("hooks::") + (cmd.c_str() + 6) + "()";
|
|
||||||
|
ret += "hooks::";
|
||||||
|
ret += std::string(cmd.begin() + 6, cmd.begin() + cparen);
|
||||||
|
ret += "()";
|
||||||
}
|
}
|
||||||
else if (cmd.find("$ENV(") == 0) {
|
else if (cmd.find("$ENV(") == 0) {
|
||||||
if (cmd.size() == 5)
|
if (cmd.size() == 5)
|
||||||
throw std::string("$ENV invocation: empty argument list!");
|
throw std::string("$ENV invocation: empty argument list!");
|
||||||
return std::string("std::getenv(\"") + (cmd.c_str() + 5) + "\")";
|
|
||||||
|
ret += "std::getenv(\"";
|
||||||
|
ret += std::string(cmd.begin() + 5, cmd.begin() + cparen);
|
||||||
|
ret += "\")";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw "Unknown special command: " + cmd;
|
throw "Unknown special command: " + cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd.begin() + cparen + 1 != cmd.end()) {
|
||||||
|
ret += " + std::string(\"";
|
||||||
|
ret += (cmd.c_str() + cparen + 1);
|
||||||
|
ret += "\")";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitCmdLineVecFill - Emit code that fills in the command line
|
/// EmitCmdLineVecFill - Emit code that fills in the command line
|
||||||
@@ -883,7 +900,7 @@ void EmitCmdLineVecFill(const Init* CmdLine, const std::string& ToolName,
|
|||||||
bool Version, const char* IndentLevel,
|
bool Version, const char* IndentLevel,
|
||||||
std::ostream& O) {
|
std::ostream& O) {
|
||||||
StrVector StrVec;
|
StrVector StrVec;
|
||||||
SplitString(InitPtrToString(CmdLine), StrVec, ") ");
|
SplitString(InitPtrToString(CmdLine), StrVec);
|
||||||
if (StrVec.empty())
|
if (StrVec.empty())
|
||||||
throw "Tool " + ToolName + " has empty command line!";
|
throw "Tool " + ToolName + " has empty command line!";
|
||||||
|
|
||||||
@@ -906,7 +923,8 @@ void EmitCmdLineVecFill(const Init* CmdLine, const std::string& ToolName,
|
|||||||
O << "vec.push_back(outFile.toString());\n";
|
O << "vec.push_back(outFile.toString());\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
O << "vec.push_back(" << SubstituteSpecialCommands(cmd) << ");\n";
|
O << "vec.push_back(" << SubstituteSpecialCommands(cmd);
|
||||||
|
O << ");\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1322,14 +1340,15 @@ void EmitPopulateCompilationGraph (Record* CompilationGraph,
|
|||||||
/// function used by FillInHookNames().
|
/// function used by FillInHookNames().
|
||||||
void ExtractHookNames(const Init* CmdLine, StrVector& HookNames) {
|
void ExtractHookNames(const Init* CmdLine, StrVector& HookNames) {
|
||||||
StrVector cmds;
|
StrVector cmds;
|
||||||
llvm::SplitString(InitPtrToString(CmdLine), cmds, ") ");
|
llvm::SplitString(InitPtrToString(CmdLine), cmds);
|
||||||
for (StrVector::const_iterator B = cmds.begin(), E = cmds.end();
|
for (StrVector::const_iterator B = cmds.begin(), E = cmds.end();
|
||||||
B != E; ++B) {
|
B != E; ++B) {
|
||||||
const std::string& cmd = *B;
|
const std::string& cmd = *B;
|
||||||
if (cmd.find("$CALL(") == 0) {
|
if (cmd.find("$CALL(") == 0) {
|
||||||
if (cmd.size() == 6)
|
if (cmd.size() == 6)
|
||||||
throw std::string("$CALL invocation: empty argument list!");
|
throw std::string("$CALL invocation: empty argument list!");
|
||||||
HookNames.push_back(std::string(cmd.c_str() + 6));
|
HookNames.push_back(std::string(cmd.begin() + 6,
|
||||||
|
cmd.begin() + cmd.find(")")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user