summaryrefslogtreecommitdiff
path: root/lib/TableGen
diff options
context:
space:
mode:
authorSean Silva <silvas@purdue.edu>2013-01-09 04:49:14 +0000
committerSean Silva <silvas@purdue.edu>2013-01-09 04:49:14 +0000
commit9cceede447118852df76e340252387d1a2cce37d (patch)
tree9ccab088466e51a2e14c9add8f3e9910b49ccc20 /lib/TableGen
parent1ced208be9cab0f994c5df9000da36bc313b2507 (diff)
downloadllvm-9cceede447118852df76e340252387d1a2cce37d.tar.gz
llvm-9cceede447118852df76e340252387d1a2cce37d.tar.bz2
llvm-9cceede447118852df76e340252387d1a2cce37d.tar.xz
tblgen: Factor out common code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171951 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen')
-rw-r--r--lib/TableGen/TGParser.cpp34
-rw-r--r--lib/TableGen/TGParser.h1
2 files changed, 18 insertions, 17 deletions
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp
index b6c8092395..1561e2cba2 100644
--- a/lib/TableGen/TGParser.cpp
+++ b/lib/TableGen/TGParser.cpp
@@ -1861,6 +1861,17 @@ bool TGParser::ParseBody(Record *CurRec) {
return false;
}
+/// \brief Apply the current let bindings to \a CurRec.
+/// \returns true on error, false otherwise.
+bool TGParser::ApplyLetStack(Record *CurRec) {
+ for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
+ for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
+ if (SetValue(CurRec, LetStack[i][j].Loc, LetStack[i][j].Name,
+ LetStack[i][j].Bits, LetStack[i][j].Value))
+ return true;
+ return false;
+}
+
/// ParseObjectBody - Parse the body of a def or class. This consists of an
/// optional ClassList followed by a Body. CurRec is the current def or class
/// that is being parsed.
@@ -1891,12 +1902,8 @@ bool TGParser::ParseObjectBody(Record *CurRec) {
}
}
- // Process any variables on the let stack.
- for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
- for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
- if (SetValue(CurRec, LetStack[i][j].Loc, LetStack[i][j].Name,
- LetStack[i][j].Bits, LetStack[i][j].Value))
- return true;
+ if (ApplyLetStack(CurRec))
+ return true;
return ParseBody(CurRec);
}
@@ -2355,11 +2362,8 @@ bool TGParser::ResolveMulticlassDef(MultiClass &MC,
Record *DefProto,
SMLoc DefmPrefixLoc) {
// If the mdef is inside a 'let' expression, add to each def.
- for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
- for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
- if (SetValue(CurRec, LetStack[i][j].Loc, LetStack[i][j].Name,
- LetStack[i][j].Bits, LetStack[i][j].Value))
- return Error(DefmPrefixLoc, "when instantiating this defm");
+ if (ApplyLetStack(CurRec))
+ return Error(DefmPrefixLoc, "when instantiating this defm");
// Don't create a top level definition for defm inside multiclasses,
// instead, only update the prototypes and bind the template args
@@ -2483,12 +2487,8 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
if (AddSubClass(CurRec, SubClass))
return true;
- // Process any variables on the let stack.
- for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
- for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
- if (SetValue(CurRec, LetStack[i][j].Loc, LetStack[i][j].Name,
- LetStack[i][j].Bits, LetStack[i][j].Value))
- return true;
+ if (ApplyLetStack(CurRec))
+ return true;
}
if (Lex.getCode() != tgtok::comma) break;
diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h
index 70fc9df468..215cbfcca7 100644
--- a/lib/TableGen/TGParser.h
+++ b/lib/TableGen/TGParser.h
@@ -183,6 +183,7 @@ private: // Parser methods.
Init *ParseObjectName(MultiClass *CurMultiClass);
Record *ParseClassID();
MultiClass *ParseMultiClassID();
+ bool ApplyLetStack(Record *CurRec);
};
} // end namespace llvm