Skip to content

Commit a551cce

Browse files
committed
[clang][Interp][NFC] Print primitive global values in dump()
1 parent 818e027 commit a551cce

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

clang/lib/AST/Interp/Disasm.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "Boolean.h"
1314
#include "Floating.h"
1415
#include "Function.h"
16+
#include "FunctionPointer.h"
17+
#include "Integral.h"
1518
#include "IntegralAP.h"
1619
#include "Opcode.h"
1720
#include "PrimType.h"
@@ -86,6 +89,40 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
8689

8790
LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
8891

92+
static const char *primTypeToString(PrimType T) {
93+
switch (T) {
94+
case PT_Sint8:
95+
return "Sint8";
96+
case PT_Uint8:
97+
return "Uint8";
98+
case PT_Sint16:
99+
return "Sint16";
100+
case PT_Uint16:
101+
return "Uint16";
102+
case PT_Sint32:
103+
return "Sint32";
104+
case PT_Uint32:
105+
return "Uint32";
106+
case PT_Sint64:
107+
return "Sint64";
108+
case PT_Uint64:
109+
return "Uint64";
110+
case PT_IntAP:
111+
return "IntAP";
112+
case PT_IntAPS:
113+
return "IntAPS";
114+
case PT_Bool:
115+
return "Bool";
116+
case PT_Float:
117+
return "Float";
118+
case PT_Ptr:
119+
return "Ptr";
120+
case PT_FnPtr:
121+
return "FnPtr";
122+
}
123+
llvm_unreachable("Unhandled PrimType");
124+
}
125+
89126
LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
90127
{
91128
ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_RED, true});
@@ -100,9 +137,10 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
100137
unsigned GI = 0;
101138
for (const Global *G : Globals) {
102139
const Descriptor *Desc = G->block()->getDescriptor();
140+
Pointer GP = getPtrGlobal(GI);
141+
103142
OS << GI << ": " << (void *)G->block() << " ";
104143
{
105-
Pointer GP = getPtrGlobal(GI);
106144
ColorScope SC(OS, true,
107145
GP.isInitialized()
108146
? TerminalColor{llvm::raw_ostream::GREEN, false}
@@ -111,6 +149,15 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
111149
}
112150
Desc->dump(OS);
113151
OS << "\n";
152+
if (Desc->isPrimitive() && !Desc->isDummy()) {
153+
OS << " ";
154+
{
155+
ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_CYAN, false});
156+
OS << primTypeToString(Desc->getPrimType()) << " ";
157+
}
158+
TYPE_SWITCH(Desc->getPrimType(), { GP.deref<T>().print(OS); });
159+
OS << "\n";
160+
}
114161
++GI;
115162
}
116163

0 commit comments

Comments
 (0)