From 96fe532c6789810e9ec3753c601847cfec643f30 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 6 Sep 2010 03:50:59 +0000 Subject: [PATCH] allow specifying an indentation level for the string matcher. llvm-svn: 113143 --- llvm/utils/TableGen/StringMatcher.cpp | 18 +++++++++++------- llvm/utils/TableGen/StringMatcher.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/llvm/utils/TableGen/StringMatcher.cpp b/llvm/utils/TableGen/StringMatcher.cpp index f9b5924069c6..68fbe7fcf31c 100644 --- a/llvm/utils/TableGen/StringMatcher.cpp +++ b/llvm/utils/TableGen/StringMatcher.cpp @@ -112,7 +112,10 @@ EmitStringMatcherForChar(const std::vector &Matches, /// Emit - Top level entry point. /// -void StringMatcher::Emit() const { +void StringMatcher::Emit(unsigned Indent) const { + // If nothing to match, just fall through. + if (Matches.empty()) return; + // First level categorization: group strings by length. std::map > MatchesByLength; @@ -121,16 +124,17 @@ void StringMatcher::Emit() const { // Output a switch statement on length and categorize the elements within each // bin. - OS << " switch (" << StrVariableName << ".size()) {\n"; - OS << " default: break;\n"; + OS.indent(Indent*2+2) << "switch (" << StrVariableName << ".size()) {\n"; + OS.indent(Indent*2+2) << "default: break;\n"; for (std::map >::iterator LI = MatchesByLength.begin(), E = MatchesByLength.end(); LI != E; ++LI) { - OS << " case " << LI->first << ":\t // " << LI->second.size() + OS.indent(Indent*2+2) << "case " << LI->first << ":\t // " + << LI->second.size() << " string" << (LI->second.size() == 1 ? "" : "s") << " to match.\n"; - if (EmitStringMatcherForChar(LI->second, 0, 0)) - OS << " break;\n"; + if (EmitStringMatcherForChar(LI->second, 0, Indent)) + OS.indent(Indent*2+4) << "break;\n"; } - OS << " }\n"; + OS.indent(Indent*2+2) << "}\n"; } diff --git a/llvm/utils/TableGen/StringMatcher.h b/llvm/utils/TableGen/StringMatcher.h index 79878202943c..1dadc76200b0 100644 --- a/llvm/utils/TableGen/StringMatcher.h +++ b/llvm/utils/TableGen/StringMatcher.h @@ -41,7 +41,7 @@ public: const std::vector &matches, raw_ostream &os) : StrVariableName(strVariableName), Matches(matches), OS(os) {} - void Emit() const; + void Emit(unsigned Indent = 0) const; private: -- GitLab