diff options
author | Chris Lattner <sabre@nondot.org> | 2010-09-06 03:50:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-09-06 03:50:59 +0000 |
commit | 902edf21668f48a279389bc3a585bcce40487c56 (patch) | |
tree | e9e90fdbe300c2440696d1f43cc0bae87f7af995 /utils/TableGen/StringMatcher.cpp | |
parent | 298b176559d5c76d7d9f7fdd06429a75892de043 (diff) |
allow specifying an indentation level for the string matcher.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113143 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/StringMatcher.cpp')
-rw-r--r-- | utils/TableGen/StringMatcher.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/utils/TableGen/StringMatcher.cpp b/utils/TableGen/StringMatcher.cpp index f9b5924069..68fbe7fcf3 100644 --- a/utils/TableGen/StringMatcher.cpp +++ b/utils/TableGen/StringMatcher.cpp @@ -112,7 +112,10 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &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<unsigned, std::vector<const StringPair*> > 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<unsigned, std::vector<const StringPair*> >::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"; } |