diff --git a/llvm/utils/TableGen/StringMatcher.cpp b/llvm/utils/TableGen/StringMatcher.cpp index f9b5924069c65bbc3efde2bd93b528a03b66ae07..68fbe7fcf31c1ebbbe0d98913d06437e64979e3f 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 79878202943cb7256d87d8a31c49adb2fd3672fa..1dadc76200b045e4b6030dc985695eb57f45fbad 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: