Skip to content

Commit

Permalink
[FIRRTL][LOA][NFC] Tweak structure dump/print. (#5570)
Browse files Browse the repository at this point in the history
Squelch warning, and LLVM-style-ify dump method.
(sometimes elided, always marked noinline, sometimes mark used)
  • Loading branch information
dtzSiFive committed Jul 12, 2023
1 parent 0e47744 commit 91573dc
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions lib/Dialect/FIRRTL/Transforms/LowerOpenAggs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ struct NonHWField {
bool isFlip;
/// String suffix naming this field.
SmallString<16> suffix;

/// Print this structure to the specified stream.
void print(raw_ostream &os) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print this structure to llvm::errs().
void dump() const;
LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
#endif
};

/// Mapped port info
Expand All @@ -71,35 +77,50 @@ struct PortMappingInfo {
return 1;
return fields.size() + (hwType ? 1 : 0) + (includeErased ? 1 : 0);
}
void dump() const;

/// Print this structure to the specified stream.
void print(raw_ostream &os) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print this structure to llvm::errs().
LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
#endif
};

llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const NonHWField &field) {
return os << llvm::formatv(
"non-HW(type={0}, fieldID={1}, isFlip={2}, suffix={3})",
field.type, field.fieldID, field.isFlip, field.suffix);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const NonHWField &field) {
field.print(os);
return os;
}

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const PortMappingInfo &pmi) {
pmi.print(os);
return os;
}

llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const PortMappingInfo &pmi) {
if (pmi.identity)
return os << "(identity)";
} // namespace

void NonHWField::print(llvm::raw_ostream &os) const {
os << llvm::formatv("non-HW(type={0}, fieldID={1}, isFlip={2}, suffix={3})",
type, fieldID, isFlip, suffix);
}
void PortMappingInfo::print(llvm::raw_ostream &os) const {
if (identity) {
os << "(identity)";
return;
}

os << "[[hw portion: ";
if (pmi.hwType)
os << pmi.hwType;
if (hwType)
os << hwType;
else
os << "(none)";
os << ", fields: ";
llvm::interleaveComma(pmi.fields, os);
return os << "]]";
llvm::interleaveComma(fields, os);
os << "]]";
}

} // namespace

void NonHWField::dump() const { llvm::errs() << *this; }
void PortMappingInfo::dump() const { llvm::errs() << *this; }

template <typename Range>
LogicalResult walkPortMappings(
Range &&range, bool includeErased,
Expand Down

0 comments on commit 91573dc

Please sign in to comment.