diff options
author | Sean Silva <silvas@purdue.edu> | 2013-01-09 04:49:14 +0000 |
---|---|---|
committer | Sean Silva <silvas@purdue.edu> | 2013-01-09 04:49:14 +0000 |
commit | cb1a75e730cbc1b393d730457c99311ad10558b3 (patch) | |
tree | e10643c6270346ad1298d1e1fb9f4176a88f1f01 | |
parent | bf7bc4966c876608506c48d40c43c723173cb945 (diff) | |
download | bcm5719-llvm-cb1a75e730cbc1b393d730457c99311ad10558b3.tar.gz bcm5719-llvm-cb1a75e730cbc1b393d730457c99311ad10558b3.zip |
tblgen: Factor out common code.
llvm-svn: 171951
-rw-r--r-- | llvm/lib/TableGen/TGParser.cpp | 34 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.h | 1 |
2 files changed, 18 insertions, 17 deletions
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index b6c80923952..1561e2cba22 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/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/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h index 70fc9df4683..215cbfcca7b 100644 --- a/llvm/lib/TableGen/TGParser.h +++ b/llvm/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 |