tblgen: Factor out common code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171951 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sean Silva 2013-01-09 04:49:14 +00:00
parent 1ced208be9
commit 9cceede447
2 changed files with 18 additions and 17 deletions

View File

@ -1861,6 +1861,17 @@ bool TGParser::ParseBody(Record *CurRec) {
return false; 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 /// 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 /// optional ClassList followed by a Body. CurRec is the current def or class
/// that is being parsed. /// that is being parsed.
@ -1891,12 +1902,8 @@ bool TGParser::ParseObjectBody(Record *CurRec) {
} }
} }
// Process any variables on the let stack. if (ApplyLetStack(CurRec))
for (unsigned i = 0, e = LetStack.size(); i != e; ++i) return true;
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 ParseBody(CurRec); return ParseBody(CurRec);
} }
@ -2355,11 +2362,8 @@ bool TGParser::ResolveMulticlassDef(MultiClass &MC,
Record *DefProto, Record *DefProto,
SMLoc DefmPrefixLoc) { SMLoc DefmPrefixLoc) {
// If the mdef is inside a 'let' expression, add to each def. // If the mdef is inside a 'let' expression, add to each def.
for (unsigned i = 0, e = LetStack.size(); i != e; ++i) if (ApplyLetStack(CurRec))
for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j) return Error(DefmPrefixLoc, "when instantiating this defm");
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");
// Don't create a top level definition for defm inside multiclasses, // Don't create a top level definition for defm inside multiclasses,
// instead, only update the prototypes and bind the template args // instead, only update the prototypes and bind the template args
@ -2483,12 +2487,8 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
if (AddSubClass(CurRec, SubClass)) if (AddSubClass(CurRec, SubClass))
return true; return true;
// Process any variables on the let stack. if (ApplyLetStack(CurRec))
for (unsigned i = 0, e = LetStack.size(); i != e; ++i) return true;
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 (Lex.getCode() != tgtok::comma) break; if (Lex.getCode() != tgtok::comma) break;

View File

@ -183,6 +183,7 @@ private: // Parser methods.
Init *ParseObjectName(MultiClass *CurMultiClass); Init *ParseObjectName(MultiClass *CurMultiClass);
Record *ParseClassID(); Record *ParseClassID();
MultiClass *ParseMultiClassID(); MultiClass *ParseMultiClassID();
bool ApplyLetStack(Record *CurRec);
}; };
} // end namespace llvm } // end namespace llvm