Skip to content

Commit b9079ba

Browse files
authored
[NFC] clang-format utils/TableGen (#80973)
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
1 parent 173e674 commit b9079ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3923
-3841
lines changed

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 326 additions & 267 deletions
Large diffs are not rendered by default.

llvm/utils/TableGen/AsmWriterEmitter.cpp

Lines changed: 135 additions & 107 deletions
Large diffs are not rendered by default.

llvm/utils/TableGen/AsmWriterInst.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,54 +57,55 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
5757
std::string::size_type LastEmitted = 0;
5858
while (LastEmitted != AsmString.size()) {
5959
std::string::size_type DollarPos =
60-
AsmString.find_first_of("$\\", LastEmitted);
61-
if (DollarPos == std::string::npos) DollarPos = AsmString.size();
60+
AsmString.find_first_of("$\\", LastEmitted);
61+
if (DollarPos == std::string::npos)
62+
DollarPos = AsmString.size();
6263

6364
// Emit a constant string fragment.
6465
if (DollarPos != LastEmitted) {
6566
for (; LastEmitted != DollarPos; ++LastEmitted)
6667
switch (AsmString[LastEmitted]) {
67-
case '\n':
68-
AddLiteralString("\\n");
69-
break;
70-
case '\t':
71-
AddLiteralString("\\t");
72-
break;
73-
case '"':
74-
AddLiteralString("\\\"");
75-
break;
76-
case '\\':
77-
AddLiteralString("\\\\");
78-
break;
79-
default:
80-
AddLiteralString(std::string(1, AsmString[LastEmitted]));
81-
break;
68+
case '\n':
69+
AddLiteralString("\\n");
70+
break;
71+
case '\t':
72+
AddLiteralString("\\t");
73+
break;
74+
case '"':
75+
AddLiteralString("\\\"");
76+
break;
77+
case '\\':
78+
AddLiteralString("\\\\");
79+
break;
80+
default:
81+
AddLiteralString(std::string(1, AsmString[LastEmitted]));
82+
break;
8283
}
8384
} else if (AsmString[DollarPos] == '\\') {
84-
if (DollarPos+1 != AsmString.size()) {
85-
if (AsmString[DollarPos+1] == 'n') {
85+
if (DollarPos + 1 != AsmString.size()) {
86+
if (AsmString[DollarPos + 1] == 'n') {
8687
AddLiteralString("\\n");
87-
} else if (AsmString[DollarPos+1] == 't') {
88+
} else if (AsmString[DollarPos + 1] == 't') {
8889
AddLiteralString("\\t");
89-
} else if (std::string("${|}\\").find(AsmString[DollarPos+1])
90-
!= std::string::npos) {
91-
AddLiteralString(std::string(1, AsmString[DollarPos+1]));
90+
} else if (std::string("${|}\\").find(AsmString[DollarPos + 1]) !=
91+
std::string::npos) {
92+
AddLiteralString(std::string(1, AsmString[DollarPos + 1]));
9293
} else {
9394
PrintFatalError(
9495
CGI.TheDef->getLoc(),
9596
"Non-supported escaped character found in instruction '" +
9697
CGI.TheDef->getName() + "'!");
9798
}
98-
LastEmitted = DollarPos+2;
99+
LastEmitted = DollarPos + 2;
99100
continue;
100101
}
101-
} else if (DollarPos+1 != AsmString.size() &&
102-
AsmString[DollarPos+1] == '$') {
103-
AddLiteralString("$"); // "$$" -> $
104-
LastEmitted = DollarPos+2;
102+
} else if (DollarPos + 1 != AsmString.size() &&
103+
AsmString[DollarPos + 1] == '$') {
104+
AddLiteralString("$"); // "$$" -> $
105+
LastEmitted = DollarPos + 2;
105106
} else {
106107
// Get the name of the variable.
107-
std::string::size_type VarEnd = DollarPos+1;
108+
std::string::size_type VarEnd = DollarPos + 1;
108109

109110
// handle ${foo}bar as $foo by detecting whether the character following
110111
// the dollar sign is a curly brace. If so, advance VarEnd and DollarPos
@@ -118,7 +119,8 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
118119

119120
while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
120121
++VarEnd;
121-
StringRef VarName(AsmString.data()+DollarPos+1, VarEnd-DollarPos-1);
122+
StringRef VarName(AsmString.data() + DollarPos + 1,
123+
VarEnd - DollarPos - 1);
122124

123125
// Modifier - Support ${foo:modifier} syntax, where "modifier" is passed
124126
// into printOperand. Also support ${:feature}, which is passed into
@@ -190,13 +192,14 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
190192
/// specified instruction except for one differing operand, return the differing
191193
/// operand number. If more than one operand mismatches, return ~1, otherwise
192194
/// if the instructions are identical return ~0.
193-
unsigned AsmWriterInst::MatchesAllButOneOp(const AsmWriterInst &Other)const{
194-
if (Operands.size() != Other.Operands.size()) return ~1;
195+
unsigned AsmWriterInst::MatchesAllButOneOp(const AsmWriterInst &Other) const {
196+
if (Operands.size() != Other.Operands.size())
197+
return ~1;
195198

196199
unsigned MismatchOperand = ~0U;
197200
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
198201
if (Operands[i] != Other.Operands[i]) {
199-
if (MismatchOperand != ~0U) // Already have one mismatch?
202+
if (MismatchOperand != ~0U) // Already have one mismatch?
200203
return ~1U;
201204
MismatchOperand = i;
202205
}

llvm/utils/TableGen/AsmWriterInst.h

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,88 +20,88 @@
2020
#include <vector>
2121

2222
namespace llvm {
23-
class CodeGenInstruction;
24-
25-
struct AsmWriterOperand {
26-
enum OpType {
27-
// Output this text surrounded by quotes to the asm.
28-
isLiteralTextOperand,
29-
// This is the name of a routine to call to print the operand.
30-
isMachineInstrOperand,
31-
// Output this text verbatim to the asm writer. It is code that
32-
// will output some text to the asm.
33-
isLiteralStatementOperand
34-
} OperandType;
35-
36-
/// MiOpNo - For isMachineInstrOperand, this is the operand number of the
37-
/// machine instruction.
38-
unsigned MIOpNo = 0;
39-
40-
/// Str - For isLiteralTextOperand, this IS the literal text. For
41-
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
42-
/// For isLiteralStatementOperand, this is the code to insert verbatim
43-
/// into the asm writer.
44-
std::string Str;
45-
46-
/// MiModifier - For isMachineInstrOperand, this is the modifier string for
47-
/// an operand, specified with syntax like ${opname:modifier}.
48-
std::string MiModifier;
49-
50-
bool PCRel = false;
51-
52-
// To make VS STL happy
53-
AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
54-
55-
AsmWriterOperand(const std::string &LitStr,
56-
OpType op = isLiteralTextOperand)
57-
: OperandType(op), Str(LitStr) {}
58-
59-
AsmWriterOperand(const std::string &Printer, unsigned _MIOpNo,
60-
const std::string &Modifier,
61-
OpType op = isMachineInstrOperand, bool PCRel = false)
62-
: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier),
63-
PCRel(PCRel) {}
64-
65-
bool operator!=(const AsmWriterOperand &Other) const {
66-
if (OperandType != Other.OperandType || Str != Other.Str) return true;
67-
if (OperandType == isMachineInstrOperand)
68-
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||
69-
PCRel != Other.PCRel;
70-
return false;
71-
}
72-
bool operator==(const AsmWriterOperand &Other) const {
73-
return !operator!=(Other);
74-
}
75-
76-
/// getCode - Return the code that prints this operand.
77-
std::string getCode(bool PassSubtarget) const;
78-
};
79-
80-
class AsmWriterInst {
81-
public:
82-
std::vector<AsmWriterOperand> Operands;
83-
const CodeGenInstruction *CGI;
84-
unsigned CGIIndex;
85-
86-
AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
87-
unsigned Variant);
88-
89-
/// MatchesAllButOneOp - If this instruction is exactly identical to the
90-
/// specified instruction except for one differing operand, return the
91-
/// differing operand number. Otherwise return ~0.
92-
unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
93-
94-
private:
95-
void AddLiteralString(const std::string &Str) {
96-
// If the last operand was already a literal text string, append this to
97-
// it, otherwise add a new operand.
98-
if (!Operands.empty() &&
99-
Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
100-
Operands.back().Str.append(Str);
101-
else
102-
Operands.push_back(AsmWriterOperand(Str));
103-
}
104-
};
105-
}
23+
class CodeGenInstruction;
24+
25+
struct AsmWriterOperand {
26+
enum OpType {
27+
// Output this text surrounded by quotes to the asm.
28+
isLiteralTextOperand,
29+
// This is the name of a routine to call to print the operand.
30+
isMachineInstrOperand,
31+
// Output this text verbatim to the asm writer. It is code that
32+
// will output some text to the asm.
33+
isLiteralStatementOperand
34+
} OperandType;
35+
36+
/// MiOpNo - For isMachineInstrOperand, this is the operand number of the
37+
/// machine instruction.
38+
unsigned MIOpNo = 0;
39+
40+
/// Str - For isLiteralTextOperand, this IS the literal text. For
41+
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
42+
/// For isLiteralStatementOperand, this is the code to insert verbatim
43+
/// into the asm writer.
44+
std::string Str;
45+
46+
/// MiModifier - For isMachineInstrOperand, this is the modifier string for
47+
/// an operand, specified with syntax like ${opname:modifier}.
48+
std::string MiModifier;
49+
50+
bool PCRel = false;
51+
52+
// To make VS STL happy
53+
AsmWriterOperand(OpType op = isLiteralTextOperand) : OperandType(op) {}
54+
55+
AsmWriterOperand(const std::string &LitStr, OpType op = isLiteralTextOperand)
56+
: OperandType(op), Str(LitStr) {}
57+
58+
AsmWriterOperand(const std::string &Printer, unsigned _MIOpNo,
59+
const std::string &Modifier,
60+
OpType op = isMachineInstrOperand, bool PCRel = false)
61+
: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier),
62+
PCRel(PCRel) {}
63+
64+
bool operator!=(const AsmWriterOperand &Other) const {
65+
if (OperandType != Other.OperandType || Str != Other.Str)
66+
return true;
67+
if (OperandType == isMachineInstrOperand)
68+
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||
69+
PCRel != Other.PCRel;
70+
return false;
71+
}
72+
bool operator==(const AsmWriterOperand &Other) const {
73+
return !operator!=(Other);
74+
}
75+
76+
/// getCode - Return the code that prints this operand.
77+
std::string getCode(bool PassSubtarget) const;
78+
};
79+
80+
class AsmWriterInst {
81+
public:
82+
std::vector<AsmWriterOperand> Operands;
83+
const CodeGenInstruction *CGI;
84+
unsigned CGIIndex;
85+
86+
AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
87+
unsigned Variant);
88+
89+
/// MatchesAllButOneOp - If this instruction is exactly identical to the
90+
/// specified instruction except for one differing operand, return the
91+
/// differing operand number. Otherwise return ~0.
92+
unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
93+
94+
private:
95+
void AddLiteralString(const std::string &Str) {
96+
// If the last operand was already a literal text string, append this to
97+
// it, otherwise add a new operand.
98+
if (!Operands.empty() &&
99+
Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
100+
Operands.back().Str.append(Str);
101+
else
102+
Operands.push_back(AsmWriterOperand(Str));
103+
}
104+
};
105+
} // namespace llvm
106106

107107
#endif

llvm/utils/TableGen/CTagsEmitter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- CTagsEmitter.cpp - Generate ctags-compatible index ------------------===//
1+
//===- CTagsEmitter.cpp - Generate ctags-compatible index -----------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -30,6 +30,7 @@ class Tag {
3030
StringRef Id;
3131
StringRef BufferIdentifier;
3232
unsigned Line;
33+
3334
public:
3435
Tag(StringRef Name, const SMLoc Location) : Id(Name) {
3536
const MemoryBuffer *CurMB =
@@ -39,7 +40,8 @@ class Tag {
3940
Line = LineAndColumn.first;
4041
}
4142
int operator<(const Tag &B) const {
42-
return std::make_tuple(Id, BufferIdentifier, Line) < std::make_tuple(B.Id, B.BufferIdentifier, B.Line);
43+
return std::make_tuple(Id, BufferIdentifier, Line) <
44+
std::make_tuple(B.Id, B.BufferIdentifier, B.Line);
4345
}
4446
void emit(raw_ostream &OS) const {
4547
OS << Id << "\t" << BufferIdentifier << "\t" << Line << "\n";
@@ -49,6 +51,7 @@ class Tag {
4951
class CTagsEmitter {
5052
private:
5153
RecordKeeper &Records;
54+
5255
public:
5356
CTagsEmitter(RecordKeeper &R) : Records(R) {}
5457

0 commit comments

Comments
 (0)