1 //===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the StringMatcher class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TABLEGEN_STRINGMATCHER_H
14 #define LLVM_TABLEGEN_STRINGMATCHER_H
16 #include "llvm/ADT/StringRef.h"
25 /// Given a list of strings and code to execute when they match, output a
26 /// simple switch tree to classify the input string.
28 /// If a match is found, the code in Matches[i].second is executed; control must
29 /// not exit this code fragment. If nothing matches, execution falls through.
32 using StringPair = std::pair<std::string, std::string>;
35 StringRef StrVariableName;
36 const std::vector<StringPair> &Matches;
40 StringMatcher(StringRef strVariableName,
41 const std::vector<StringPair> &matches, raw_ostream &os)
42 : StrVariableName(strVariableName), Matches(matches), OS(os) {}
44 void Emit(unsigned Indent = 0, bool IgnoreDuplicates = false) const;
47 bool EmitStringMatcherForChar(const std::vector<const StringPair *> &Matches,
48 unsigned CharNo, unsigned IndentCount,
49 bool IgnoreDuplicates) const;
52 } // end namespace llvm
54 #endif // LLVM_TABLEGEN_STRINGMATCHER_H