From 25896af4bbb4171e6a72d7c360258917371c459b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 30 Oct 2010 19:57:17 +0000 Subject: [PATCH] fix a fixme in stringmatcher, having it generate nice looking code if the 'tomatch' code contains \n's. llvm-svn: 117843 --- llvm/utils/TableGen/StringMatcher.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/llvm/utils/TableGen/StringMatcher.cpp b/llvm/utils/TableGen/StringMatcher.cpp index 1c43b6d1c8aa..6aedcbf458a8 100644 --- a/llvm/utils/TableGen/StringMatcher.cpp +++ b/llvm/utils/TableGen/StringMatcher.cpp @@ -51,9 +51,18 @@ EmitStringMatcherForChar(const std::vector &Matches, if (CharNo == Matches[0]->first.size()) { assert(Matches.size() == 1 && "Had duplicate keys to match on"); - // FIXME: If Matches[0].first has embeded \n, this will be bad. - OS << Indent << Matches[0]->second << "\t // \"" << Matches[0]->first - << "\"\n"; + // If the to-execute code has \n's in it, indent each subsequent line. + StringRef Code = Matches[0]->second; + + std::pair Split = Code.split('\n'); + OS << Indent << Split.first << "\t // \"" << Matches[0]->first << "\"\n"; + + Code = Split.second; + while (!Code.empty()) { + Split = Code.split('\n'); + OS << Indent << Split.first << "\n"; + Code = Split.second; + } return false; }