diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-09-06 02:01:51 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-09-06 02:01:51 +0000 |
| commit | ca5a3554b575ccdde60d46cf52b8927e5b186fc3 (patch) | |
| tree | bb15d02e8c00260ed24d1660284a81c98ea27565 /llvm/utils/TableGen/StringMatcher.h | |
| parent | fb43da66b59ad34493af16d690885b119c197951 (diff) | |
| download | bcm5719-llvm-ca5a3554b575ccdde60d46cf52b8927e5b186fc3.tar.gz bcm5719-llvm-ca5a3554b575ccdde60d46cf52b8927e5b186fc3.zip | |
factor the snazzy string matcher code that Daniel hates
out of AsmMatcherEmitter.cpp into its own class.
llvm-svn: 113137
Diffstat (limited to 'llvm/utils/TableGen/StringMatcher.h')
| -rw-r--r-- | llvm/utils/TableGen/StringMatcher.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/StringMatcher.h b/llvm/utils/TableGen/StringMatcher.h new file mode 100644 index 00000000000..79878202943 --- /dev/null +++ b/llvm/utils/TableGen/StringMatcher.h @@ -0,0 +1,54 @@ +//===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the StringMatcher class. +// +//===----------------------------------------------------------------------===// + +#ifndef STRINGMATCHER_H +#define STRINGMATCHER_H + +#include <vector> +#include <string> +#include <utility> +#include "llvm/ADT/StringRef.h" + +namespace llvm { + class raw_ostream; + +/// StringMatcher - Given a list of strings and code to execute when they match, +/// output a simple switch tree to classify the input string. +/// +/// If a match is found, the code in Vals[i].second is executed; control must +/// not exit this code fragment. If nothing matches, execution falls through. +/// +class StringMatcher { +public: + typedef std::pair<std::string, std::string> StringPair; +private: + StringRef StrVariableName; + const std::vector<StringPair> &Matches; + raw_ostream &OS; + +public: + StringMatcher(StringRef strVariableName, + const std::vector<StringPair> &matches, raw_ostream &os) + : StrVariableName(strVariableName), Matches(matches), OS(os) {} + + void Emit() const; + + +private: + bool EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches, + unsigned CharNo, unsigned IndentCount) const; +}; + +} // end llvm namespace. + +#endif |

