Skip to content
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

[TableGen] Refactor SequenceToOffsetTable class #104986

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
27 changes: 12 additions & 15 deletions llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
#ifndef LLVM_UTILS_TABLEGEN_BASIC_SEQUENCETOOFFSETTABLE_H
#define LLVM_UTILS_TABLEGEN_BASIC_SEQUENCETOOFFSETTABLE_H

#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <functional>
#include <map>

namespace llvm {
extern llvm::cl::opt<bool> EmitLongStrLiterals;
extern cl::opt<bool> EmitLongStrLiterals;

static inline void printChar(raw_ostream &OS, char C) {
inline void printChar(raw_ostream &OS, char C) {
unsigned char UC(C);
if (isalnum(UC) || ispunct(UC)) {
if (isAlnum(UC) || isPunct(UC)) {
jurahul marked this conversation as resolved.
Show resolved Hide resolved
OS << '\'';
if (C == '\\' || C == '\'')
OS << '\\';
Expand Down Expand Up @@ -126,7 +126,7 @@ class SequenceToOffsetTable {
/// initializer, where each element is a C string literal terminated by
/// `\0`. Falls back to emitting a comma-separated integer list if
/// `EmitLongStrLiterals` is false
void emitStringLiteralDef(raw_ostream &OS, const llvm::Twine &Decl) const {
void emitStringLiteralDef(raw_ostream &OS, const Twine &Decl) const {
assert(Entries && "Call layout() before emitStringLiteralDef()");
if (!EmitLongStrLiterals) {
OS << Decl << " = {\n";
Expand All @@ -140,9 +140,9 @@ class SequenceToOffsetTable {
<< "#pragma GCC diagnostic ignored \"-Woverlength-strings\"\n"
<< "#endif\n"
<< Decl << " = {\n";
for (auto I : Seqs) {
OS << " /* " << I.second << " */ \"";
OS.write_escaped(I.first);
for (const auto &[Seq, Offset] : Seqs) {
OS << " /* " << Offset << " */ \"";
OS.write_escaped(Seq);
OS << "\\0\"\n";
}
OS << "};\n"
Expand All @@ -156,13 +156,10 @@ class SequenceToOffsetTable {
void emit(raw_ostream &OS, void (*Print)(raw_ostream &, ElemT),
const char *Term = "0") const {
assert((empty() || Entries) && "Call layout() before emit()");
for (typename SeqMap::const_iterator I = Seqs.begin(), E = Seqs.end();
I != E; ++I) {
OS << " /* " << I->second << " */ ";
for (typename SeqT::const_iterator SI = I->first.begin(),
SE = I->first.end();
SI != SE; ++SI) {
Print(OS, *SI);
for (const auto &[Seq, Offset] : Seqs) {
OS << " /* " << Offset << " */ ";
for (const ElemT &Element : Seq) {
Print(OS, Element);
OS << ", ";
}
OS << Term << ",\n";
Expand Down
Loading