@@ -1900,11 +1900,10 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
19001900 ParseValueList (Vals, CurRec);
19011901 if (Vals.empty ()) return nullptr ;
19021902 }
1903- if (Lex. getCode () != tgtok::r_brace) {
1903+ if (! consume ( tgtok::r_brace) ) {
19041904 TokError (" expected '}' at end of bit list value" );
19051905 return nullptr ;
19061906 }
1907- Lex.Lex (); // eat the '}'
19081907
19091908 SmallVector<Init *, 16 > NewBits;
19101909
@@ -2566,9 +2565,8 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
25662565 if (!ParseDeclaration (CurRec, false ))
25672566 return true ;
25682567
2569- if (Lex. getCode () != tgtok::semi)
2568+ if (! consume ( tgtok::semi) )
25702569 return TokError (" expected ';' after declaration" );
2571- Lex.Lex ();
25722570 return false ;
25732571 }
25742572
@@ -2585,9 +2583,8 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
25852583 return true ;
25862584 std::reverse (BitList.begin (), BitList.end ());
25872585
2588- if (Lex. getCode () != tgtok::equal)
2586+ if (! consume ( tgtok::equal) )
25892587 return TokError (" expected '=' in let expression" );
2590- Lex.Lex (); // eat the '='.
25912588
25922589 RecordVal *Field = CurRec->getValue (FieldName);
25932590 if (!Field)
@@ -2603,9 +2600,8 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
26032600 Init *Val = ParseValue (CurRec, Type);
26042601 if (!Val) return true ;
26052602
2606- if (Lex. getCode () != tgtok::semi)
2603+ if (! consume ( tgtok::semi) )
26072604 return TokError (" expected ';' after let expression" );
2608- Lex.Lex ();
26092605
26102606 return SetValue (CurRec, IdLoc, FieldName, BitList, Val);
26112607}
@@ -2684,8 +2680,8 @@ bool TGParser::ParseObjectBody(Record *CurRec) {
26842680 if (AddSubClass (CurRec, SubClass))
26852681 return true ;
26862682
2687- if (Lex. getCode () != tgtok::comma) break ;
2688- Lex. Lex (); // eat ','.
2683+ if (! consume ( tgtok::comma))
2684+ break ;
26892685 SubClass = ParseSubClassReference (CurRec, false );
26902686 }
26912687 }
@@ -2760,11 +2756,10 @@ bool TGParser::ParseDefset() {
27602756 if (Err)
27612757 return true ;
27622758
2763- if (Lex. getCode () != tgtok::r_brace) {
2759+ if (! consume ( tgtok::r_brace) ) {
27642760 TokError (" expected '}' at end of defset" );
27652761 return Error (BraceLoc, " to match this '{'" );
27662762 }
2767- Lex.Lex (); // Eat the '}'
27682763
27692764 Records.addExtraGlobal (DeclName->getValue (),
27702765 ListInit::get (Defset.Elements , Defset.EltTy ));
@@ -2790,17 +2785,16 @@ bool TGParser::ParseDefvar() {
27902785 return TokError (" def or global variable of this name already exists" );
27912786 }
27922787
2793- if (Lex.Lex () != tgtok::equal) // Eat the identifier
2788+ Lex.Lex ();
2789+ if (!consume (tgtok::equal))
27942790 return TokError (" expected '='" );
2795- Lex.Lex (); // Eat the '='
27962791
27972792 Init *Value = ParseValue (nullptr );
27982793 if (!Value)
27992794 return true ;
28002795
2801- if (Lex. getCode () != tgtok::semi)
2796+ if (! consume ( tgtok::semi) )
28022797 return TokError (" expected ';'" );
2803- Lex.Lex (); // Eat the ';'
28042798
28052799 if (CurLocalScope)
28062800 CurLocalScope->addVar (DeclName->getValue (), Value);
@@ -2828,9 +2822,8 @@ bool TGParser::ParseForeach(MultiClass *CurMultiClass) {
28282822 if (!IterName)
28292823 return TokError (" expected declaration in for" );
28302824
2831- if (Lex. getCode () != tgtok::In)
2825+ if (! consume ( tgtok::In) )
28322826 return TokError (" Unknown tok" );
2833- Lex.Lex (); // Eat the in
28342827
28352828 // Create a loop object and remember it.
28362829 Loops.push_back (std::make_unique<ForeachLoop>(Loc, IterName, ListValue));
@@ -2851,11 +2844,10 @@ bool TGParser::ParseForeach(MultiClass *CurMultiClass) {
28512844 if (ParseObjectList (CurMultiClass))
28522845 return true ;
28532846
2854- if (Lex. getCode () != tgtok::r_brace) {
2847+ if (! consume ( tgtok::r_brace) ) {
28552848 TokError (" expected '}' at end of foreach command" );
28562849 return Error (BraceLoc, " to match this '{'" );
28572850 }
2858- Lex.Lex (); // Eat the }
28592851 }
28602852
28612853 PopLocalScope (ForeachScope);
@@ -2883,9 +2875,8 @@ bool TGParser::ParseIf(MultiClass *CurMultiClass) {
28832875 if (!Condition)
28842876 return true ;
28852877
2886- if (Lex. getCode () != tgtok::Then)
2878+ if (! consume ( tgtok::Then) )
28872879 return TokError (" Unknown tok" );
2888- Lex.Lex (); // Eat the 'then'
28892880
28902881 // We have to be able to save if statements to execute later, and they have
28912882 // to live on the same stack as foreach loops. The simplest implementation
@@ -2962,12 +2953,10 @@ bool TGParser::ParseIfBody(MultiClass *CurMultiClass, StringRef Kind) {
29622953 if (ParseObjectList (CurMultiClass))
29632954 return true ;
29642955
2965- if (Lex. getCode () != tgtok::r_brace) {
2956+ if (! consume ( tgtok::r_brace) ) {
29662957 TokError (" expected '}' at end of '" + Kind + " ' clause" );
29672958 return Error (BraceLoc, " to match this '{'" );
29682959 }
2969-
2970- Lex.Lex (); // Eat the }
29712960 }
29722961
29732962 PopLocalScope (BodyScope);
@@ -3018,7 +3007,7 @@ bool TGParser::ParseClass() {
30183007// / LetItem ::= ID OptionalRangeList '=' Value
30193008// /
30203009void TGParser::ParseLetList (SmallVectorImpl<LetRecord> &Result) {
3021- while ( true ) {
3010+ do {
30223011 if (Lex.getCode () != tgtok::Id) {
30233012 TokError (" expected identifier in let definition" );
30243013 Result.clear ();
@@ -3037,12 +3026,11 @@ void TGParser::ParseLetList(SmallVectorImpl<LetRecord> &Result) {
30373026 }
30383027 std::reverse (Bits.begin (), Bits.end ());
30393028
3040- if (Lex. getCode () != tgtok::equal) {
3029+ if (! consume ( tgtok::equal) ) {
30413030 TokError (" expected '=' in let expression" );
30423031 Result.clear ();
30433032 return ;
30443033 }
3045- Lex.Lex (); // eat the '='.
30463034
30473035 Init *Val = ParseValue (nullptr );
30483036 if (!Val) {
@@ -3052,11 +3040,7 @@ void TGParser::ParseLetList(SmallVectorImpl<LetRecord> &Result) {
30523040
30533041 // Now that we have everything, add the record.
30543042 Result.emplace_back (Name, Bits, Val, NameLoc);
3055-
3056- if (Lex.getCode () != tgtok::comma)
3057- return ;
3058- Lex.Lex (); // eat the comma.
3059- }
3043+ } while (consume (tgtok::comma));
30603044}
30613045
30623046// / ParseTopLevelLet - Parse a 'let' at top level. This can be a couple of
@@ -3075,9 +3059,8 @@ bool TGParser::ParseTopLevelLet(MultiClass *CurMultiClass) {
30753059 if (LetInfo.empty ()) return true ;
30763060 LetStack.push_back (std::move (LetInfo));
30773061
3078- if (Lex. getCode () != tgtok::In)
3062+ if (! consume ( tgtok::In) )
30793063 return TokError (" expected 'in' at end of top-level 'let'" );
3080- Lex.Lex ();
30813064
30823065 TGLocalVarScope *LetScope = PushLocalScope ();
30833066
@@ -3095,11 +3078,10 @@ bool TGParser::ParseTopLevelLet(MultiClass *CurMultiClass) {
30953078 if (ParseObjectList (CurMultiClass))
30963079 return true ;
30973080
3098- if (Lex. getCode () != tgtok::r_brace) {
3081+ if (! consume ( tgtok::r_brace) ) {
30993082 TokError (" expected '}' at end of top level let command" );
31003083 return Error (BraceLoc, " to match this '{'" );
31013084 }
3102- Lex.Lex ();
31033085 }
31043086
31053087 PopLocalScope (LetScope);
0 commit comments