LLVM 22.0.0git
StringMatcher.h
Go to the documentation of this file.
1//===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the StringMatcher class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TABLEGEN_STRINGMATCHER_H
14#define LLVM_TABLEGEN_STRINGMATCHER_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/StringRef.h"
18#include <string>
19#include <utility>
20
21namespace llvm {
22
23class raw_ostream;
24
25/// Given a list of strings and code to execute when they match, output a
26/// simple switch tree to classify the input string.
27///
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.
31public:
32 using StringPair = std::pair<std::string, std::string>;
33
34private:
35 StringRef StrVariableName;
37 raw_ostream &OS;
38
39public:
41 raw_ostream &OS)
42 : StrVariableName(StrVariableName), Matches(Matches), OS(OS) {}
43
44 void Emit(unsigned Indent = 0, bool IgnoreDuplicates = false) const;
45
46private:
47 bool EmitStringMatcherForChar(ArrayRef<const StringPair *> Matches,
48 unsigned CharNo, unsigned IndentCount,
49 bool IgnoreDuplicates) const;
50};
51
52} // end namespace llvm
53
54#endif // LLVM_TABLEGEN_STRINGMATCHER_H
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
StringMatcher(StringRef StrVariableName, ArrayRef< StringPair > Matches, raw_ostream &OS)
void Emit(unsigned Indent=0, bool IgnoreDuplicates=false) const
Emit - Top level entry point.
std::pair< std::string, std::string > StringPair
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.