Skip to content

[NFC] clang-format utils/TableGen #80973

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

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
593 changes: 326 additions & 267 deletions llvm/utils/TableGen/AsmMatcherEmitter.cpp

Large diffs are not rendered by default.

242 changes: 135 additions & 107 deletions llvm/utils/TableGen/AsmWriterEmitter.cpp

Large diffs are not rendered by default.

69 changes: 36 additions & 33 deletions llvm/utils/TableGen/AsmWriterInst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,54 +57,55 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
std::string::size_type LastEmitted = 0;
while (LastEmitted != AsmString.size()) {
std::string::size_type DollarPos =
AsmString.find_first_of("$\\", LastEmitted);
if (DollarPos == std::string::npos) DollarPos = AsmString.size();
AsmString.find_first_of("$\\", LastEmitted);
if (DollarPos == std::string::npos)
DollarPos = AsmString.size();

// Emit a constant string fragment.
if (DollarPos != LastEmitted) {
for (; LastEmitted != DollarPos; ++LastEmitted)
switch (AsmString[LastEmitted]) {
case '\n':
AddLiteralString("\\n");
break;
case '\t':
AddLiteralString("\\t");
break;
case '"':
AddLiteralString("\\\"");
break;
case '\\':
AddLiteralString("\\\\");
break;
default:
AddLiteralString(std::string(1, AsmString[LastEmitted]));
break;
case '\n':
Copy link
Contributor Author

Choose a reason for hiding this comment

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

idem

AddLiteralString("\\n");
break;
case '\t':
AddLiteralString("\\t");
break;
case '"':
AddLiteralString("\\\"");
break;
case '\\':
AddLiteralString("\\\\");
break;
default:
AddLiteralString(std::string(1, AsmString[LastEmitted]));
break;
}
} else if (AsmString[DollarPos] == '\\') {
if (DollarPos+1 != AsmString.size()) {
if (AsmString[DollarPos+1] == 'n') {
if (DollarPos + 1 != AsmString.size()) {
if (AsmString[DollarPos + 1] == 'n') {
AddLiteralString("\\n");
} else if (AsmString[DollarPos+1] == 't') {
} else if (AsmString[DollarPos + 1] == 't') {
AddLiteralString("\\t");
} else if (std::string("${|}\\").find(AsmString[DollarPos+1])
!= std::string::npos) {
AddLiteralString(std::string(1, AsmString[DollarPos+1]));
} else if (std::string("${|}\\").find(AsmString[DollarPos + 1]) !=
std::string::npos) {
AddLiteralString(std::string(1, AsmString[DollarPos + 1]));
} else {
PrintFatalError(
CGI.TheDef->getLoc(),
"Non-supported escaped character found in instruction '" +
CGI.TheDef->getName() + "'!");
}
LastEmitted = DollarPos+2;
LastEmitted = DollarPos + 2;
continue;
}
} else if (DollarPos+1 != AsmString.size() &&
AsmString[DollarPos+1] == '$') {
AddLiteralString("$"); // "$$" -> $
LastEmitted = DollarPos+2;
} else if (DollarPos + 1 != AsmString.size() &&
AsmString[DollarPos + 1] == '$') {
AddLiteralString("$"); // "$$" -> $
LastEmitted = DollarPos + 2;
} else {
// Get the name of the variable.
std::string::size_type VarEnd = DollarPos+1;
std::string::size_type VarEnd = DollarPos + 1;

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

while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
++VarEnd;
StringRef VarName(AsmString.data()+DollarPos+1, VarEnd-DollarPos-1);
StringRef VarName(AsmString.data() + DollarPos + 1,
VarEnd - DollarPos - 1);

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

unsigned MismatchOperand = ~0U;
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
if (Operands[i] != Other.Operands[i]) {
if (MismatchOperand != ~0U) // Already have one mismatch?
if (MismatchOperand != ~0U) // Already have one mismatch?
return ~1U;
MismatchOperand = i;
}
Expand Down
166 changes: 83 additions & 83 deletions llvm/utils/TableGen/AsmWriterInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,88 @@
#include <vector>

namespace llvm {
class CodeGenInstruction;

struct AsmWriterOperand {
enum OpType {
// Output this text surrounded by quotes to the asm.
isLiteralTextOperand,
// This is the name of a routine to call to print the operand.
isMachineInstrOperand,
// Output this text verbatim to the asm writer. It is code that
// will output some text to the asm.
isLiteralStatementOperand
} OperandType;

/// MiOpNo - For isMachineInstrOperand, this is the operand number of the
/// machine instruction.
unsigned MIOpNo = 0;

/// Str - For isLiteralTextOperand, this IS the literal text. For
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
/// For isLiteralStatementOperand, this is the code to insert verbatim
/// into the asm writer.
std::string Str;

/// MiModifier - For isMachineInstrOperand, this is the modifier string for
/// an operand, specified with syntax like ${opname:modifier}.
std::string MiModifier;

bool PCRel = false;

// To make VS STL happy
AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}

AsmWriterOperand(const std::string &LitStr,
OpType op = isLiteralTextOperand)
: OperandType(op), Str(LitStr) {}

AsmWriterOperand(const std::string &Printer, unsigned _MIOpNo,
const std::string &Modifier,
OpType op = isMachineInstrOperand, bool PCRel = false)
: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier),
PCRel(PCRel) {}

bool operator!=(const AsmWriterOperand &Other) const {
if (OperandType != Other.OperandType || Str != Other.Str) return true;
if (OperandType == isMachineInstrOperand)
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||
PCRel != Other.PCRel;
return false;
}
bool operator==(const AsmWriterOperand &Other) const {
return !operator!=(Other);
}

/// getCode - Return the code that prints this operand.
std::string getCode(bool PassSubtarget) const;
};

class AsmWriterInst {
public:
std::vector<AsmWriterOperand> Operands;
const CodeGenInstruction *CGI;
unsigned CGIIndex;

AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
unsigned Variant);

/// MatchesAllButOneOp - If this instruction is exactly identical to the
/// specified instruction except for one differing operand, return the
/// differing operand number. Otherwise return ~0.
unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;

private:
void AddLiteralString(const std::string &Str) {
// If the last operand was already a literal text string, append this to
// it, otherwise add a new operand.
if (!Operands.empty() &&
Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
Operands.back().Str.append(Str);
else
Operands.push_back(AsmWriterOperand(Str));
}
};
}
class CodeGenInstruction;

struct AsmWriterOperand {
enum OpType {
// Output this text surrounded by quotes to the asm.
isLiteralTextOperand,
// This is the name of a routine to call to print the operand.
isMachineInstrOperand,
// Output this text verbatim to the asm writer. It is code that
// will output some text to the asm.
isLiteralStatementOperand
} OperandType;

/// MiOpNo - For isMachineInstrOperand, this is the operand number of the
/// machine instruction.
unsigned MIOpNo = 0;

/// Str - For isLiteralTextOperand, this IS the literal text. For
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
/// For isLiteralStatementOperand, this is the code to insert verbatim
/// into the asm writer.
std::string Str;

/// MiModifier - For isMachineInstrOperand, this is the modifier string for
/// an operand, specified with syntax like ${opname:modifier}.
std::string MiModifier;

bool PCRel = false;

// To make VS STL happy
AsmWriterOperand(OpType op = isLiteralTextOperand) : OperandType(op) {}

AsmWriterOperand(const std::string &LitStr, OpType op = isLiteralTextOperand)
: OperandType(op), Str(LitStr) {}

AsmWriterOperand(const std::string &Printer, unsigned _MIOpNo,
const std::string &Modifier,
OpType op = isMachineInstrOperand, bool PCRel = false)
: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier),
PCRel(PCRel) {}

bool operator!=(const AsmWriterOperand &Other) const {
if (OperandType != Other.OperandType || Str != Other.Str)
return true;
if (OperandType == isMachineInstrOperand)
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||
PCRel != Other.PCRel;
return false;
}
bool operator==(const AsmWriterOperand &Other) const {
return !operator!=(Other);
}

/// getCode - Return the code that prints this operand.
std::string getCode(bool PassSubtarget) const;
};

class AsmWriterInst {
public:
std::vector<AsmWriterOperand> Operands;
const CodeGenInstruction *CGI;
unsigned CGIIndex;

AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
unsigned Variant);

/// MatchesAllButOneOp - If this instruction is exactly identical to the
/// specified instruction except for one differing operand, return the
/// differing operand number. Otherwise return ~0.
unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;

private:
void AddLiteralString(const std::string &Str) {
// If the last operand was already a literal text string, append this to
// it, otherwise add a new operand.
if (!Operands.empty() &&
Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
Operands.back().Str.append(Str);
else
Operands.push_back(AsmWriterOperand(Str));
}
};
} // namespace llvm

#endif
7 changes: 5 additions & 2 deletions llvm/utils/TableGen/CTagsEmitter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- CTagsEmitter.cpp - Generate ctags-compatible index ------------------===//
//===- CTagsEmitter.cpp - Generate ctags-compatible index -----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -30,6 +30,7 @@ class Tag {
StringRef Id;
StringRef BufferIdentifier;
unsigned Line;

public:
Tag(StringRef Name, const SMLoc Location) : Id(Name) {
const MemoryBuffer *CurMB =
Expand All @@ -39,7 +40,8 @@ class Tag {
Line = LineAndColumn.first;
}
int operator<(const Tag &B) const {
return std::make_tuple(Id, BufferIdentifier, Line) < std::make_tuple(B.Id, B.BufferIdentifier, B.Line);
return std::make_tuple(Id, BufferIdentifier, Line) <
std::make_tuple(B.Id, B.BufferIdentifier, B.Line);
}
void emit(raw_ostream &OS) const {
OS << Id << "\t" << BufferIdentifier << "\t" << Line << "\n";
Expand All @@ -49,6 +51,7 @@ class Tag {
class CTagsEmitter {
private:
RecordKeeper &Records;

public:
CTagsEmitter(RecordKeeper &R) : Records(R) {}

Expand Down
Loading