Skip to content
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
21 changes: 18 additions & 3 deletions clang/lib/AST/ByteCode/Disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,16 @@ static size_t getNumDisplayWidth(size_t N) {
return L;
}

LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
LLVM_DUMP_METHOD void Function::dump(CodePtr PC) const {
dump(llvm::errs(), PC);
}

LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS,
CodePtr OpPC) const {
if (OpPC) {
assert(OpPC >= getCodeBegin());
assert(OpPC <= getCodeEnd());
}
{
ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_GREEN, true});
OS << getName() << " " << (const void *)this << "\n";
Expand All @@ -154,6 +161,7 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
size_t Addr;
std::string Op;
bool IsJump;
bool CurrentOp = false;
llvm::SmallVector<std::string> Args;
};

Expand All @@ -171,6 +179,7 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
auto Op = PC.read<Opcode>();
Text.Addr = Addr;
Text.IsJump = isJumpOpcode(Op);
Text.CurrentOp = (PC == OpPC);
switch (Op) {
#define GET_DISASM
#include "Opcodes.inc"
Expand Down Expand Up @@ -198,9 +207,15 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
Text.reserve(Code.size());
size_t LongestLine = 0;
// Print code to a string, one at a time.
for (auto C : Code) {
for (const auto &C : Code) {
std::string Line;
llvm::raw_string_ostream LS(Line);
if (OpPC) {
if (C.CurrentOp)
LS << " * ";
else
LS << " ";
}
LS << C.Addr;
LS.indent(LongestAddr - getNumDisplayWidth(C.Addr) + 4);
LS << C.Op;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ class Function final {

public:
/// Dumps the disassembled bytecode to \c llvm::errs().
void dump() const;
void dump(llvm::raw_ostream &OS) const;
void dump(CodePtr PC = {}) const;
void dump(llvm::raw_ostream &OS, CodePtr PC = {}) const;
};

} // namespace interp
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/ByteCode/Source.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CodePtr final {
explicit operator bool() const { return Ptr; }
bool operator<=(const CodePtr &RHS) const { return Ptr <= RHS.Ptr; }
bool operator>=(const CodePtr &RHS) const { return Ptr >= RHS.Ptr; }
bool operator==(const CodePtr RHS) const { return Ptr == RHS.Ptr; }

/// Reads data and advances the pointer.
template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() {
Expand Down