Skip to content

[NFC] Run clang-format on TGLexer and TGParser #151509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Jul 31, 2025

In #149248, clang-format applied some formatting to lines untouched by that PR, because the existing code is not clang-format compliant. Hence applying clang-format on the entire files here.

In llvm#149248, clang-format
applied some formatting to lines untouched by that PR, because the
existing code is not clang-formatted well. Hence applying clang-format
on the entire files here.
@jurahul jurahul marked this pull request as ready for review July 31, 2025 13:57
@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2025

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes

In #149248, clang-format applied some formatting to lines untouched by that PR, because the existing code is not clang-formatted well. Hence applying clang-format on the entire files here.


Patch is 44.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/151509.diff

4 Files Affected:

  • (modified) llvm/lib/TableGen/TGLexer.cpp (+33-29)
  • (modified) llvm/lib/TableGen/TGLexer.h (+2-6)
  • (modified) llvm/lib/TableGen/TGParser.cpp (+237-152)
  • (modified) llvm/lib/TableGen/TGParser.h (+5-7)
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index c369916a48f0d..7b23736169bba 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -93,9 +93,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
   }
 }
 
-SMLoc TGLexer::getLoc() const {
-  return SMLoc::getFromPointer(TokStart);
-}
+SMLoc TGLexer::getLoc() const { return SMLoc::getFromPointer(TokStart); }
 
 SMRange TGLexer::getLocRange() const {
   return {getLoc(), SMLoc::getFromPointer(CurPtr)};
@@ -162,16 +160,13 @@ int TGLexer::getNextChar() {
     // Handle the newline character by ignoring it and incrementing the line
     // count. However, be careful about 'dos style' files with \n\r in them.
     // Only treat a \n\r or \r\n as a single line.
-    if ((*CurPtr == '\n' || (*CurPtr == '\r')) &&
-        *CurPtr != CurChar)
-      ++CurPtr;  // Eat the two char newline sequence.
+    if ((*CurPtr == '\n' || (*CurPtr == '\r')) && *CurPtr != CurChar)
+      ++CurPtr; // Eat the two char newline sequence.
     return '\n';
   }
 }
 
-int TGLexer::peekNextChar(int Index) const {
-  return *(CurPtr + Index);
-}
+int TGLexer::peekNextChar(int Index) const { return *(CurPtr + Index); }
 
 tgtok::TokKind TGLexer::LexToken(bool FileOrLineStart) {
   while (true) {
@@ -367,7 +362,9 @@ tgtok::TokKind TGLexer::LexString() {
     ++CurPtr;
 
     switch (*CurPtr) {
-    case '\\': case '\'': case '"':
+    case '\\':
+    case '\'':
+    case '"':
       // These turn into their literal character.
       CurStrVal += *CurPtr++;
       break;
@@ -421,7 +418,7 @@ tgtok::TokKind TGLexer::LexIdentifier() {
     ++CurPtr;
 
   // Check to see if this identifier is a reserved keyword.
-  StringRef Str(IdentStart, CurPtr-IdentStart);
+  StringRef Str(IdentStart, CurPtr - IdentStart);
 
   tgtok::TokKind Kind = StringSwitch<tgtok::TokKind>(Str)
                             .Case("int", tgtok::Int)
@@ -454,14 +451,15 @@ tgtok::TokKind TGLexer::LexIdentifier() {
 
   // A couple of tokens require special processing.
   switch (Kind) {
-    case tgtok::Include:
-      if (LexInclude()) return tgtok::Error;
-      return Lex();
-    case tgtok::Id:
-      CurStrVal.assign(Str.begin(), Str.end());
-      break;
-    default:
-      break;
+  case tgtok::Include:
+    if (LexInclude())
+      return tgtok::Error;
+    return Lex();
+  case tgtok::Id:
+    CurStrVal.assign(Str.begin(), Str.end());
+    break;
+  default:
+    break;
   }
 
   return Kind;
@@ -472,7 +470,8 @@ tgtok::TokKind TGLexer::LexIdentifier() {
 bool TGLexer::LexInclude() {
   // The token after the include must be a string.
   tgtok::TokKind Tok = LexToken();
-  if (Tok == tgtok::Error) return true;
+  if (Tok == tgtok::Error)
+    return true;
   if (Tok != tgtok::StrVal) {
     PrintError(getLoc(), "expected filename after include");
     return true;
@@ -501,7 +500,7 @@ bool TGLexer::LexInclude() {
 /// SkipBCPLComment - Skip over the comment by finding the next CR or LF.
 /// Or we may end up at the end of the buffer.
 void TGLexer::SkipBCPLComment() {
-  ++CurPtr;  // skip the second slash.
+  ++CurPtr; // skip the second slash.
   auto EOLPos = CurBuf.find_first_of("\r\n", CurPtr - CurBuf.data());
   CurPtr = (EOLPos == StringRef::npos) ? CurBuf.end() : CurBuf.data() + EOLPos;
 }
@@ -509,7 +508,7 @@ void TGLexer::SkipBCPLComment() {
 /// SkipCComment - This skips C-style /**/ comments. The only difference from C
 /// is that we allow nesting.
 bool TGLexer::SkipCComment() {
-  ++CurPtr;  // skip the star.
+  ++CurPtr; // skip the star.
   unsigned CommentDepth = 1;
 
   while (true) {
@@ -520,15 +519,17 @@ bool TGLexer::SkipCComment() {
       return true;
     case '*':
       // End of the comment?
-      if (CurPtr[0] != '/') break;
+      if (CurPtr[0] != '/')
+        break;
 
-      ++CurPtr;   // End the */.
+      ++CurPtr; // End the */.
       if (--CommentDepth == 0)
         return false;
       break;
     case '/':
       // Start of a nested comment?
-      if (CurPtr[0] != '*') break;
+      if (CurPtr[0] != '*')
+        break;
       ++CurPtr;
       ++CommentDepth;
       break;
@@ -608,14 +609,17 @@ tgtok::TokKind TGLexer::LexBracket() {
   const char *CodeStart = CurPtr;
   while (true) {
     int Char = getNextChar();
-    if (Char == EOF) break;
+    if (Char == EOF)
+      break;
 
-    if (Char != '}') continue;
+    if (Char != '}')
+      continue;
 
     Char = getNextChar();
-    if (Char == EOF) break;
+    if (Char == EOF)
+      break;
     if (Char == ']') {
-      CurStrVal.assign(CodeStart, CurPtr-2);
+      CurStrVal.assign(CodeStart, CurPtr - 2);
       return tgtok::CodeFragment;
     }
   }
diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h
index 5725e391d0c4d..753470dfb5374 100644
--- a/llvm/lib/TableGen/TGLexer.h
+++ b/llvm/lib/TableGen/TGLexer.h
@@ -216,13 +216,9 @@ class TGLexer {
 public:
   TGLexer(SourceMgr &SrcMgr, ArrayRef<std::string> Macros);
 
-  tgtok::TokKind Lex() {
-    return CurCode = LexToken(CurPtr == CurBuf.begin());
-  }
+  tgtok::TokKind Lex() { return CurCode = LexToken(CurPtr == CurBuf.begin()); }
 
-  const DependenciesSetTy &getDependencies() const {
-    return Dependencies;
-  }
+  const DependenciesSetTy &getDependencies() const { return Dependencies; }
 
   tgtok::TokKind getCode() const { return CurCode; }
 
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 81b61b19f687b..0c6add59cb282 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -99,11 +99,11 @@ static void checkConcrete(Record &R) {
     if (const Init *V = RV.getValue()) {
       bool Ok = isa<BitsInit>(V) ? checkBitsConcrete(R, RV) : V->isConcrete();
       if (!Ok) {
-        PrintError(R.getLoc(),
-                   Twine("Initializer of '") + RV.getNameInitAsString() +
-                   "' in '" + R.getNameInitAsString() +
-                   "' could not be fully resolved: " +
-                   RV.getValue()->getAsString());
+        PrintError(R.getLoc(), Twine("Initializer of '") +
+                                   RV.getNameInitAsString() + "' in '" +
+                                   R.getNameInitAsString() +
+                                   "' could not be fully resolved: " +
+                                   RV.getValue()->getAsString());
       }
     }
   }
@@ -218,9 +218,10 @@ bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) {
     // The value already exists in the class, treat this as a set.
     if (ERV->setValue(RV.getValue()))
       return Error(Loc, "New definition of '" + RV.getName() + "' of type '" +
-                   RV.getType()->getAsString() + "' is incompatible with " +
-                   "previous definition of type '" +
-                   ERV->getType()->getAsString() + "'");
+                            RV.getType()->getAsString() +
+                            "' is incompatible with " +
+                            "previous definition of type '" +
+                            ERV->getType()->getAsString() + "'");
   } else {
     CurRec->addValue(RV);
   }
@@ -232,14 +233,16 @@ bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) {
 bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName,
                         ArrayRef<unsigned> BitList, const Init *V,
                         bool AllowSelfAssignment, bool OverrideDefLoc) {
-  if (!V) return false;
+  if (!V)
+    return false;
 
-  if (!CurRec) CurRec = &CurMultiClass->Rec;
+  if (!CurRec)
+    CurRec = &CurMultiClass->Rec;
 
   RecordVal *RV = CurRec->getValue(ValName);
   if (!RV)
-    return Error(Loc, "Value '" + ValName->getAsUnquotedString() +
-                 "' unknown!");
+    return Error(Loc,
+                 "Value '" + ValName->getAsUnquotedString() + "' unknown!");
 
   // Do not allow assignments like 'X = X'. This will just cause infinite loops
   // in the resolution machinery.
@@ -254,7 +257,7 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName,
     const auto *CurVal = dyn_cast<BitsInit>(RV->getValue());
     if (!CurVal)
       return Error(Loc, "Value '" + ValName->getAsUnquotedString() +
-                   "' is not a bits type");
+                            "' is not a bits type");
 
     // Convert the incoming value to a bits type of the appropriate size...
     const Init *BI = V->getCastTo(BitsRecTy::get(Records, BitList.size()));
@@ -268,7 +271,8 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName,
       unsigned Bit = BitList[i];
       if (NewBits[Bit])
         return Error(Loc, "Cannot set bit #" + Twine(Bit) + " of value '" +
-                     ValName->getAsUnquotedString() + "' more than once");
+                              ValName->getAsUnquotedString() +
+                              "' more than once");
       NewBits[Bit] = BI->getBit(i);
     }
 
@@ -283,7 +287,8 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const Init *ValName,
     std::string InitType;
     if (const auto *BI = dyn_cast<BitsInit>(V))
       InitType = (Twine("' of type bit initializer with length ") +
-                  Twine(BI->getNumBits())).str();
+                  Twine(BI->getNumBits()))
+                     .str();
     else if (const auto *TI = dyn_cast<TypedInit>(V))
       InitType =
           (Twine("' of type '") + TI->getType()->getAsString() + "'").str();
@@ -416,9 +421,8 @@ bool TGParser::addEntry(RecordsEntry E) {
 ///
 /// The resulting records are stored in \p Dest if non-null. Otherwise, they
 /// are added to the global record keeper.
-bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs,
-                       bool Final, std::vector<RecordsEntry> *Dest,
-                       SMLoc *Loc) {
+bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs, bool Final,
+                       std::vector<RecordsEntry> *Dest, SMLoc *Loc) {
 
   MapResolver R;
   for (const auto &S : Substs)
@@ -437,28 +441,28 @@ bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs,
     R.setFinal(true);
     const Init *LHS = OldLHS->resolveReferences(R);
     if (LHS == OldLHS) {
-      PrintError(Loop.Loc,
-                 Twine("unable to resolve if condition '") +
-                 LHS->getAsString() + "' at end of containing scope");
+      PrintError(Loop.Loc, Twine("unable to resolve if condition '") +
+                               LHS->getAsString() +
+                               "' at end of containing scope");
       return true;
     }
     const Init *MHS = TI->getMHS();
     const Init *RHS = TI->getRHS();
     List = TernOpInit::get(TernOpInit::IF, LHS, MHS, RHS, TI->getType())
-      ->Fold(nullptr);
+               ->Fold(nullptr);
   }
 
   const auto *LI = dyn_cast<ListInit>(List);
   if (!LI) {
     if (!Final) {
-      Dest->emplace_back(std::make_unique<ForeachLoop>(Loop.Loc, Loop.IterVar,
-                                                  List));
+      Dest->emplace_back(
+          std::make_unique<ForeachLoop>(Loop.Loc, Loop.IterVar, List));
       return resolve(Loop.Entries, Substs, Final, &Dest->back().Loop->Entries,
                      Loc);
     }
 
     PrintError(Loop.Loc, Twine("attempting to loop over '") +
-                              List->getAsString() + "', expected a list");
+                             List->getAsString() + "', expected a list");
     return true;
   }
 
@@ -571,7 +575,7 @@ bool TGParser::addDefOne(std::unique_ptr<Record> Rec) {
     if (!I->getType()->typeIsA(Defset->EltTy)) {
       PrintError(Rec->getLoc(), Twine("adding record of incompatible type '") +
                                     I->getType()->getAsString() +
-                                     "' to defset");
+                                    "' to defset");
       PrintNote(Defset->Loc, "location of defset declaration");
       return true;
     }
@@ -751,8 +755,8 @@ MultiClass *TGParser::ParseMultiClassID() {
 ///  SubClassRef ::= ClassID
 ///  SubClassRef ::= ClassID '<' ArgValueList '>'
 ///
-SubClassReference TGParser::
-ParseSubClassReference(Record *CurRec, bool isDefm) {
+SubClassReference TGParser::ParseSubClassReference(Record *CurRec,
+                                                   bool isDefm) {
   SubClassReference Result;
   Result.RefRange.Start = Lex.getLoc();
 
@@ -762,7 +766,8 @@ ParseSubClassReference(Record *CurRec, bool isDefm) {
   } else {
     Result.Rec = ParseClassID();
   }
-  if (!Result.Rec) return Result;
+  if (!Result.Rec)
+    return Result;
 
   // If there is no template arg list, we're done.
   if (!consume(tgtok::less)) {
@@ -793,13 +798,14 @@ ParseSubClassReference(Record *CurRec, bool isDefm) {
 ///  SubMultiClassRef ::= MultiClassID
 ///  SubMultiClassRef ::= MultiClassID '<' ArgValueList '>'
 ///
-SubMultiClassReference TGParser::
-ParseSubMultiClassReference(MultiClass *CurMC) {
+SubMultiClassReference
+TGParser::ParseSubMultiClassReference(MultiClass *CurMC) {
   SubMultiClassReference Result;
   Result.RefRange.Start = Lex.getLoc();
 
   Result.MC = ParseMultiClassID();
-  if (!Result.MC) return Result;
+  if (!Result.MC)
+    return Result;
 
   // If there is no template arg list, we're done.
   if (!consume(tgtok::less)) {
@@ -1049,7 +1055,8 @@ bool TGParser::ParseOptionalRangeList(SmallVectorImpl<unsigned> &Ranges) {
 
   // Parse the range list.
   ParseRangeList(Ranges);
-  if (Ranges.empty()) return true;
+  if (Ranges.empty())
+    return true;
 
   if (!consume(tgtok::greater)) {
     TokError("expected '>' at end of range list");
@@ -1068,7 +1075,8 @@ bool TGParser::ParseOptionalBitList(SmallVectorImpl<unsigned> &Ranges) {
 
   // Parse the range list.
   ParseRangeList(Ranges);
-  if (Ranges.empty()) return true;
+  if (Ranges.empty())
+    return true;
 
   if (!consume(tgtok::r_brace)) {
     TokError("expected '}' at end of bit list");
@@ -1090,7 +1098,9 @@ bool TGParser::ParseOptionalBitList(SmallVectorImpl<unsigned> &Ranges) {
 ///
 const RecTy *TGParser::ParseType() {
   switch (Lex.getCode()) {
-  default: TokError("Unknown token when expecting a type"); return nullptr;
+  default:
+    TokError("Unknown token when expecting a type");
+    return nullptr;
   case tgtok::String:
   case tgtok::Code:
     Lex.Lex();
@@ -1129,7 +1139,7 @@ const RecTy *TGParser::ParseType() {
       TokError("expected '>' at end of bits<n> type");
       return nullptr;
     }
-    Lex.Lex();  // Eat '>'
+    Lex.Lex(); // Eat '>'
     return BitsRecTy::get(Records, Val);
   }
   case tgtok::List: {
@@ -1137,9 +1147,10 @@ const RecTy *TGParser::ParseType() {
       TokError("expected '<' after list type");
       return nullptr;
     }
-    Lex.Lex();  // Eat '<'
+    Lex.Lex(); // Eat '<'
     const RecTy *SubType = ParseType();
-    if (!SubType) return nullptr;
+    if (!SubType)
+      return nullptr;
 
     if (!consume(tgtok::greater)) {
       TokError("expected '>' at end of list<ty> type");
@@ -1206,9 +1217,10 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
     const RecTy *Type = nullptr;
 
     switch (Lex.getCode()) {
-    default: llvm_unreachable("Unhandled code!");
+    default:
+      llvm_unreachable("Unhandled code!");
     case tgtok::XCast:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       Code = UnOpInit::CAST;
 
       Type = ParseOperatorType();
@@ -1235,7 +1247,7 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
       Type = StringRecTy::get(Records);
       break;
     case tgtok::XNOT:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       Code = UnOpInit::NOT;
       Type = IntRecTy::get(Records);
       break;
@@ -1245,16 +1257,16 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
       Type = IntRecTy::get(Records); // Bogus type used here.
       break;
     case tgtok::XLOG2:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       Code = UnOpInit::LOG2;
       Type = IntRecTy::get(Records);
       break;
     case tgtok::XHead:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       Code = UnOpInit::HEAD;
       break;
     case tgtok::XTail:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       Code = UnOpInit::TAIL;
       break;
     case tgtok::XSize:
@@ -1263,12 +1275,12 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
       Type = IntRecTy::get(Records);
       break;
     case tgtok::XEmpty:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       Code = UnOpInit::EMPTY;
       Type = IntRecTy::get(Records);
       break;
     case tgtok::XGetDagOp:
-      Lex.Lex();  // eat the operation
+      Lex.Lex(); // eat the operation
       if (Lex.getCode() == tgtok::less) {
         // Parse an optional type suffix, so that you can say
         // !getdagop<BaseClass>(someDag) as a shorthand for
@@ -1306,7 +1318,8 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
     }
 
     const Init *LHS = ParseValue(CurRec);
-    if (!LHS) return nullptr;
+    if (!LHS)
+      return nullptr;
 
     if (Code == UnOpInit::EMPTY || Code == UnOpInit::SIZE) {
       const auto *LHSl = dyn_cast<ListInit>(LHS);
@@ -1314,12 +1327,14 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
       const auto *LHSd = dyn_cast<DagInit>(LHS);
       const auto *LHSt = dyn_cast<TypedInit>(LHS);
       if (!LHSl && !LHSs && !LHSd && !LHSt) {
-        TokError("expected string, list, or dag type argument in unary operator");
+        TokError(
+            "expected string, list, or dag type argument in unary operator");
         return nullptr;
       }
       if (LHSt) {
         if (!isa<ListRecTy, StringRecTy, DagRecTy>(LHSt->getType())) {
-          TokError("expected string, list, or dag type argument in unary operator");
+          TokError(
+              "expected string, list, or dag type argument in unary operator");
           return nullptr;
         }
       }
@@ -1525,39 +1540,84 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
   case tgtok::XSetDagOpName: { // Value ::= !binop '(' Value ',' Value ')'
     tgtok::TokKind OpTok = Lex.getCode();
     SMLoc OpLoc = Lex.getLoc();
-    Lex.Lex();  // eat the operation
+    Lex.Lex(); // eat the operation
 
     BinOpInit::BinaryOp Code;
     switch (OpTok) {
-    default: llvm_unreachable("Unhandled code!");
-    case tgtok::XConcat: Code = BinOpInit::CONCAT; break;
+    default:
+      llvm_unreachable("Unhandled code!");
+    case tgtok::XConcat:
+      Code = BinOpInit::CONCAT;
+      break;
     case tgtok::XMatch:
       Code = BinOpInit::MATCH;
       break;
-    case tgtok::XADD:    Code = BinOpInit::ADD; break;
-    case tgtok::XSUB:    Code = BinOpInit::SUB; break;
-    case tgtok::XMUL:    Code = BinOpInit::MUL; break;
-    case tgtok::XDIV:    Code = BinOpInit::DIV; break;
-    case tgtok::XAND:    Code = BinOpInit::AND; break;
-    case tgtok::XOR:     Code = BinOpInit::OR; break;
-    case tgtok::XXOR:    Code = BinOpInit::XOR; break;
-    case tgtok::XSRA:    Code = BinOpInit::SRA; break;
-    case tgtok::XSRL:    Code = BinOpInit::SRL; break;
-    case tgtok::XSHL:    Code = BinOpInit::SHL; break;
-    case tgtok::XEq:     Code = BinOpInit::EQ; break;
-    case tgtok::XNe:     Code = BinOpInit::NE; break;
-    case tgtok::XLe:     Code = BinOpInit::LE; break;
-    case tgtok::XLt:     Code = BinOpInit::LT; break;
-    case tgtok::XGe:     Code = BinOpInit::GE; break;
-    case tgtok::XGt:     Code = BinOpInit::GT; break;
-    case tgtok::XListConcat: Code = BinOpInit::LISTCONCAT; break;
-    case tgtok::XListSplat:  Code = BinOpInit::LISTSPLAT; break;
+    case tgtok::XADD:
+      Code = BinOpInit::ADD;
+      break;
+    case tgtok::XSUB:
+      Code = BinOpInit::SUB;
+      break;
+    case tgtok::XMUL:
+      Code = BinOpInit::MUL;
+      break;
+    case tgtok::XDIV:
+      Code = BinOpInit::DIV;
+      break;
+    case tgtok::XAND:
+      Code = BinOpInit::AND;
+      break;
+    case tgtok::XOR:
+      Code = BinOpInit::OR;
+      break;
+    case tgtok::XXOR:
+      Code = BinOpInit::XOR;
+      break;
+    case tgtok::XSRA:
+      Code...
[truncated]

Copy link
Member

@nemanjai nemanjai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM...

The TLDR version:
I am personally in favour of doing this since it demonstrably can cause unrelated formatting changes in the immediate vicinity of changed code when running git-clang-format on the diff. However, I know that there are those in the community that prefer to only run clang-format locally when modifying code (i.e. to produce the aforementioned unrelated formatting changes). As the code owner of this part of the llvm project, it is ultimately up to you which approach you prefer for TableGen, but I certainly approve.

@@ -1525,39 +1540,84 @@ const Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
case tgtok::XSetDagOpName: { // Value ::= !binop '(' Value ',' Value ')'
tgtok::TokKind OpTok = Lex.getCode();
SMLoc OpLoc = Lex.getLoc();
Lex.Lex(); // eat the operation
Lex.Lex(); // eat the operation

BinOpInit::BinaryOp Code;
switch (OpTok) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but it might make this code more readable if this switch and the one on line 1634 were actually pulled out into a separate function with internal linkage that would set Code, Type, ArgType rather than having two nested switch statements in one case of the outer one.

@jurahul jurahul requested a review from arsenm August 4, 2025 17:21
@jurahul
Copy link
Contributor Author

jurahul commented Aug 4, 2025

Thanks, will get one more approval before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants