|
16 | 16 | #include "Opcode.h"
|
17 | 17 | #include "PrimType.h"
|
18 | 18 | #include "Program.h"
|
| 19 | +#include "clang/AST/ASTDumperUtils.h" |
19 | 20 | #include "clang/AST/DeclCXX.h"
|
20 | 21 | #include "llvm/Support/Compiler.h"
|
21 | 22 | #include "llvm/Support/Format.h"
|
@@ -55,7 +56,10 @@ inline IntegralAP<true> ReadArg<IntegralAP<true>>(Program &P, CodePtr &OpPC) {
|
55 | 56 | LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
|
56 | 57 |
|
57 | 58 | LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
|
58 |
| - OS << getName() << " " << (const void *)this << "\n"; |
| 59 | + { |
| 60 | + ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_GREEN, true}); |
| 61 | + OS << getName() << " " << (const void *)this << "\n"; |
| 62 | + } |
59 | 63 | OS << "frame size: " << getFrameSize() << "\n";
|
60 | 64 | OS << "arg size: " << getArgSize() << "\n";
|
61 | 65 | OS << "rvo: " << hasRVO() << "\n";
|
@@ -83,14 +87,67 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
|
83 | 87 | LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
|
84 | 88 |
|
85 | 89 | LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
|
86 |
| - OS << ":: Program\n"; |
87 |
| - OS << "Global Variables: " << Globals.size() << "\n"; |
88 |
| - OS << "Functions: " << Funcs.size() << "\n"; |
89 |
| - OS << "\n"; |
90 |
| - for (auto &Func : Funcs) { |
| 90 | + { |
| 91 | + ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_RED, true}); |
| 92 | + OS << "\n:: Program\n"; |
| 93 | + } |
| 94 | + |
| 95 | + { |
| 96 | + ColorScope SC(OS, true, {llvm::raw_ostream::WHITE, true}); |
| 97 | + OS << "Total memory : " << Allocator.getTotalMemory() << " bytes\n"; |
| 98 | + OS << "Global Variables: " << Globals.size() << "\n"; |
| 99 | + } |
| 100 | + unsigned GI = 0; |
| 101 | + for (const Global *G : Globals) { |
| 102 | + const Descriptor *Desc = G->block()->getDescriptor(); |
| 103 | + OS << GI << ": " << (void *)G->block() << " "; |
| 104 | + Desc->dump(OS); |
| 105 | + OS << "\n"; |
| 106 | + ++GI; |
| 107 | + } |
| 108 | + |
| 109 | + { |
| 110 | + ColorScope SC(OS, true, {llvm::raw_ostream::WHITE, true}); |
| 111 | + OS << "Functions: " << Funcs.size() << "\n"; |
| 112 | + } |
| 113 | + for (const auto &Func : Funcs) { |
91 | 114 | Func.second->dump();
|
92 | 115 | }
|
93 |
| - for (auto &Anon : AnonFuncs) { |
| 116 | + for (const auto &Anon : AnonFuncs) { |
94 | 117 | Anon->dump();
|
95 | 118 | }
|
96 | 119 | }
|
| 120 | + |
| 121 | +LLVM_DUMP_METHOD void Descriptor::dump() const { |
| 122 | + dump(llvm::errs()); |
| 123 | + llvm::errs() << '\n'; |
| 124 | +} |
| 125 | + |
| 126 | +LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const { |
| 127 | + // Source |
| 128 | + { |
| 129 | + ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true}); |
| 130 | + if (const auto *ND = dyn_cast_if_present<NamedDecl>(asDecl())) |
| 131 | + OS << ND->getName(); |
| 132 | + else if (asExpr()) |
| 133 | + OS << "expr (TODO)"; |
| 134 | + } |
| 135 | + |
| 136 | + // Print a few interesting bits about the descriptor. |
| 137 | + if (isPrimitiveArray()) |
| 138 | + OS << " primitive-array"; |
| 139 | + else if (isCompositeArray()) |
| 140 | + OS << " composite-array"; |
| 141 | + else if (isRecord()) |
| 142 | + OS << " record"; |
| 143 | + else if (isPrimitive()) |
| 144 | + OS << " primitive"; |
| 145 | + |
| 146 | + if (isZeroSizeArray()) |
| 147 | + OS << " zero-size-arrary"; |
| 148 | + else if (isUnknownSizeArray()) |
| 149 | + OS << " unknown-size-array"; |
| 150 | + |
| 151 | + if (isDummy()) |
| 152 | + OS << " dummy"; |
| 153 | +} |
0 commit comments