aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-05-30 06:22:15 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-05-30 06:22:15 +0000
commit2d0dc9ab4439c110ab5d745208b874c3eaa7c89d (patch)
treee5417866657bad5e38eb1c673dd3e0348e0f6a62 /utils
parent4fb71eae48279b7e643b34b6b857f95be7eedb09 (diff)
downloadexternal_llvm-2d0dc9ab4439c110ab5d745208b874c3eaa7c89d.zip
external_llvm-2d0dc9ab4439c110ab5d745208b874c3eaa7c89d.tar.gz
external_llvm-2d0dc9ab4439c110ab5d745208b874c3eaa7c89d.tar.bz2
Allow nesting of case expressions.
The following is now legal: (case (in_language "c"), (case (switch_on "E"), "gcc -x c -E $INFILE", (default), "gcc -x c $INFILE"), (default), "gcc $INFILE $OUTFILE") git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/LLVMCConfigurationEmitter.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp
index b978c29..08f008e 100644
--- a/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -763,7 +763,7 @@ void EmitCaseTest(const DagInit& d, const char* IndentLevel,
// void F(Init* Statement, const char* IndentLevel, std::ostream& O).
template <typename F>
void EmitCaseConstructHandler(const DagInit* d, const char* IndentLevel,
- const F& Callback,
+ const F& Callback, bool EmitElseIf,
const GlobalOptionDescriptions& OptDescs,
std::ostream& O) {
assert(d->getOperator()->getAsString() == "case");
@@ -784,7 +784,7 @@ void EmitCaseConstructHandler(const DagInit* d, const char* IndentLevel,
O << IndentLevel << "else {\n";
}
else {
- O << IndentLevel << "if (";
+ O << IndentLevel << ((i != 0 && EmitElseIf) ? "else if (" : "if (");
EmitCaseTest(Test, IndentLevel, OptDescs, O);
O << ") {\n";
}
@@ -795,7 +795,16 @@ void EmitCaseConstructHandler(const DagInit* d, const char* IndentLevel,
throw "Case construct handler: no corresponding action "
"found for the test " + Test.getAsString() + '!';
- Callback(d->getArg(i), IndentLevel, O);
+ Init* arg = d->getArg(i);
+ if (dynamic_cast<DagInit*>(arg)
+ && static_cast<DagInit*>(arg)->getOperator()->getAsString() == "case") {
+ EmitCaseConstructHandler(static_cast<DagInit*>(arg),
+ (std::string(IndentLevel) + Indent1).c_str(),
+ Callback, EmitElseIf, OptDescs, O);
+ }
+ else {
+ Callback(arg, IndentLevel, O);
+ }
O << IndentLevel << "}\n";
}
}
@@ -1031,7 +1040,7 @@ void EmitGenerateActionMethod (const ToolProperties& P,
else
EmitCaseConstructHandler(&InitPtrToDag(P.CmdLine), Indent2,
EmitCmdLineVecFillCallback(Version, P.Name),
- OptDescs, O);
+ true, OptDescs, O);
// For every understood option, emit handling code.
for (ToolOptionDescriptions::const_iterator B = P.OptDescs.begin(),
@@ -1332,7 +1341,7 @@ void EmitEdgeClass (unsigned N, const std::string& Target,
<< Indent2 << "unsigned ret = 0;\n";
// Handle the 'case' construct.
- EmitCaseConstructHandler(Case, Indent2, IncDecWeight, OptDescs, O);
+ EmitCaseConstructHandler(Case, Indent2, IncDecWeight, false, OptDescs, O);
O << Indent2 << "return ret;\n"
<< Indent1 << "};\n\n};\n\n";
@@ -1420,30 +1429,40 @@ void ExtractHookNames(const Init* CmdLine, StrVector& HookNames) {
}
}
+/// ExtractHookNamesFromCaseConstruct - Extract hook names from the
+/// 'case' expression, handle nesting. Helper function used by
+/// FillInHookNames().
+void ExtractHookNamesFromCaseConstruct(Init* Case, StrVector& HookNames) {
+ const DagInit& d = InitPtrToDag(Case);
+ bool even = false;
+ for (DagInit::const_arg_iterator B = d.arg_begin(), E = d.arg_end();
+ B != E; ++B) {
+ Init* arg = *B;
+ if (even && dynamic_cast<DagInit*>(arg)
+ && static_cast<DagInit*>(arg)->getOperator()->getAsString() == "case")
+ ExtractHookNamesFromCaseConstruct(arg, HookNames);
+ else if (even)
+ ExtractHookNames(arg, HookNames);
+ even = !even;
+ }
+}
+
/// FillInHookNames - Actually extract the hook names from all command
/// line strings. Helper function used by EmitHookDeclarations().
void FillInHookNames(const ToolPropertiesList& TPList,
StrVector& HookNames) {
+ // For all command lines:
for (ToolPropertiesList::const_iterator B = TPList.begin(),
E = TPList.end(); B != E; ++B) {
const ToolProperties& P = *(*B);
if (!P.CmdLine)
continue;
- if (typeid(*P.CmdLine) == typeid(StringInit)) {
+ if (dynamic_cast<StringInit*>(P.CmdLine))
// This is a string.
ExtractHookNames(P.CmdLine, HookNames);
- }
- else {
+ else
// This is a 'case' construct.
- const DagInit& d = InitPtrToDag(P.CmdLine);
- bool even = false;
- for (DagInit::const_arg_iterator B = d.arg_begin(), E = d.arg_end();
- B != E; ++B) {
- if (even)
- ExtractHookNames(*B, HookNames);
- even = !even;
- }
- }
+ ExtractHookNamesFromCaseConstruct(P.CmdLine, HookNames);
}
}