1 //===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the StringMatcher class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TABLEGEN_STRINGMATCHER_H
15 #define LLVM_TABLEGEN_STRINGMATCHER_H
17 #include "llvm/ADT/StringRef.h"
26 /// StringMatcher - Given a list of strings and code to execute when they match,
27 /// output a simple switch tree to classify the input string.
29 /// If a match is found, the code in Vals[i].second is executed; control must
30 /// not exit this code fragment. If nothing matches, execution falls through.
34 using StringPair = std::pair<std::string, std::string>;
37 StringRef StrVariableName;
38 const std::vector<StringPair> &Matches;
42 StringMatcher(StringRef strVariableName,
43 const std::vector<StringPair> &matches, raw_ostream &os)
44 : StrVariableName(strVariableName), Matches(matches), OS(os) {}
46 void Emit(unsigned Indent = 0, bool IgnoreDuplicates = false) const;
49 bool EmitStringMatcherForChar(const std::vector<const StringPair *> &Matches,
50 unsigned CharNo, unsigned IndentCount,
51 bool IgnoreDuplicates) const;
54 } // end namespace llvm
56 #endif // LLVM_TABLEGEN_STRINGMATCHER_H