aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/DAGISelMatcherEmitter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-02-16 06:52:01 +0000
committerChris Lattner <sabre@nondot.org>2010-02-16 06:52:01 +0000
commite02ea54cfd71dee378ca6b11243710d1760ea7c1 (patch)
tree9886c10db1dee6a3785a21819c129a39adac8d1e /utils/TableGen/DAGISelMatcherEmitter.cpp
parente2de49d9a1f26a16963739eab94aeba894df16a7 (diff)
downloadexternal_llvm-e02ea54cfd71dee378ca6b11243710d1760ea7c1.zip
external_llvm-e02ea54cfd71dee378ca6b11243710d1760ea7c1.tar.gz
external_llvm-e02ea54cfd71dee378ca6b11243710d1760ea7c1.tar.bz2
refactor some code into a local class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96334 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelMatcherEmitter.cpp')
-rw-r--r--utils/TableGen/DAGISelMatcherEmitter.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/utils/TableGen/DAGISelMatcherEmitter.cpp b/utils/TableGen/DAGISelMatcherEmitter.cpp
index ee838d0..3d2791d 100644
--- a/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -24,10 +24,6 @@ enum {
};
}
-static unsigned EmitMatcherAndChildren(const MatcherNode *N,
- formatted_raw_ostream &FOS,
- unsigned Indent);
-
/// ClassifyInt - Classify an integer by size, return '1','2','4','8' if this
/// fits in 1, 2, 4, or 8 sign extended bytes.
static char ClassifyInt(int64_t Val) {
@@ -67,10 +63,22 @@ static unsigned EmitInt(int64_t Val, formatted_raw_ostream &OS) {
return BytesEmitted;
}
+namespace {
+class MatcherTableEmitter {
+ formatted_raw_ostream &OS;
+public:
+ MatcherTableEmitter(formatted_raw_ostream &os) : OS(os) {}
+
+ unsigned EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent);
+private:
+ unsigned EmitMatcher(const MatcherNode *N, unsigned Indent);
+};
+} // end anonymous namespace.
+
/// EmitMatcherOpcodes - Emit bytes for the specified matcher and return
/// the number of bytes emitted.
-static unsigned EmitMatcher(const MatcherNode *N, formatted_raw_ostream &OS,
- unsigned Indent) {
+unsigned MatcherTableEmitter::
+EmitMatcher(const MatcherNode *N, unsigned Indent) {
OS.PadToColumn(Indent*2);
switch (N->getKind()) {
@@ -163,9 +171,8 @@ static unsigned EmitMatcher(const MatcherNode *N, formatted_raw_ostream &OS,
}
/// EmitMatcherAndChildren - Emit the bytes for the specified matcher subtree.
-static unsigned EmitMatcherAndChildren(const MatcherNode *N,
- formatted_raw_ostream &OS,
- unsigned Indent) {
+unsigned MatcherTableEmitter::
+EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent) {
unsigned Size = 0;
while (1) {
// Push is a special case since it is binary.
@@ -179,8 +186,7 @@ static unsigned EmitMatcherAndChildren(const MatcherNode *N,
raw_svector_ostream OS(TmpBuf);
formatted_raw_ostream FOS(OS);
ChildSize =
- EmitMatcherAndChildren(cast<PushMatcherNode>(N)->getChild(), FOS,
- Indent+1);
+ EmitMatcherAndChildren(cast<PushMatcherNode>(N)->getChild(),Indent+1);
}
if (ChildSize > 255) {
@@ -199,7 +205,7 @@ static unsigned EmitMatcherAndChildren(const MatcherNode *N,
continue;
}
- Size += EmitMatcher(N, OS, Indent);
+ Size += EmitMatcher(N, Indent);
// If there are children of this node, iterate to them, otherwise we're
// done.
@@ -216,8 +222,10 @@ void llvm::EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &O) {
OS << "// The main instruction selector code.\n";
OS << "SDNode *SelectCode2(SDNode *N) {\n";
+ MatcherTableEmitter MatcherEmitter(OS);
+
OS << " static const unsigned char MatcherTable[] = {\n";
- unsigned TotalSize = EmitMatcherAndChildren(Matcher, OS, 2);
+ unsigned TotalSize = MatcherEmitter.EmitMatcherAndChildren(Matcher, 2);
OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
- OS << " return SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable));\n}\n";
+ OS << " return SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n}\n";
}