| 1 | //===--- Disasm.cpp - Disassembler for bytecode functions -------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Dump method for Function which disassembles the bytecode. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "Boolean.h" |
| 14 | #include "Char.h" |
| 15 | #include "Context.h" |
| 16 | #include "EvaluationResult.h" |
| 17 | #include "FixedPoint.h" |
| 18 | #include "Floating.h" |
| 19 | #include "Function.h" |
| 20 | #include "Integral.h" |
| 21 | #include "IntegralAP.h" |
| 22 | #include "InterpFrame.h" |
| 23 | #include "MemberPointer.h" |
| 24 | #include "Opcode.h" |
| 25 | #include "PrimType.h" |
| 26 | #include "Program.h" |
| 27 | #include "clang/AST/ASTDumperUtils.h" |
| 28 | #include "clang/AST/DeclCXX.h" |
| 29 | #include "clang/AST/ExprCXX.h" |
| 30 | #include "llvm/Support/Compiler.h" |
| 31 | #include "llvm/Support/FormatVariadic.h" |
| 32 | |
| 33 | using namespace clang; |
| 34 | using namespace clang::interp; |
| 35 | |
| 36 | template <typename T> |
| 37 | inline static std::string printArg(Program &P, CodePtr &OpPC) { |
| 38 | if constexpr (std::is_pointer_v<T>) { |
| 39 | uint32_t ID = OpPC.read<uint32_t>(); |
| 40 | std::string Result; |
| 41 | llvm::raw_string_ostream SS(Result); |
| 42 | SS << reinterpret_cast<T>(P.getNativePointer(Idx: ID)); |
| 43 | return Result; |
| 44 | } else { |
| 45 | std::string Result; |
| 46 | llvm::raw_string_ostream SS(Result); |
| 47 | auto Arg = OpPC.read<T>(); |
| 48 | // Make sure we print the integral value of chars. |
| 49 | if constexpr (std::is_integral_v<T>) { |
| 50 | if constexpr (sizeof(T) == 1) { |
| 51 | if constexpr (std::is_signed_v<T>) |
| 52 | SS << static_cast<int32_t>(Arg); |
| 53 | else |
| 54 | SS << static_cast<uint32_t>(Arg); |
| 55 | } else { |
| 56 | SS << Arg; |
| 57 | } |
| 58 | } else { |
| 59 | SS << Arg; |
| 60 | } |
| 61 | |
| 62 | return Result; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | template <> inline std::string printArg<Floating>(Program &P, CodePtr &OpPC) { |
| 67 | auto Sem = Floating::deserializeSemantics(Buff: *OpPC); |
| 68 | |
| 69 | unsigned BitWidth = llvm::APFloatBase::semanticsSizeInBits( |
| 70 | llvm::APFloatBase::EnumToSemantics(S: Sem)); |
| 71 | auto Memory = |
| 72 | std::make_unique<uint64_t[]>(num: llvm::APInt::getNumWords(BitWidth)); |
| 73 | Floating Result(Memory.get(), Sem); |
| 74 | Floating::deserialize(Buff: *OpPC, Result: &Result); |
| 75 | |
| 76 | OpPC += align(Size: Result.bytesToSerialize()); |
| 77 | |
| 78 | std::string S; |
| 79 | llvm::raw_string_ostream SS(S); |
| 80 | SS << std::move(Result); |
| 81 | return S; |
| 82 | } |
| 83 | |
| 84 | template <> |
| 85 | inline std::string printArg<IntegralAP<false>>(Program &P, CodePtr &OpPC) { |
| 86 | using T = IntegralAP<false>; |
| 87 | uint32_t BitWidth = T::deserializeSize(Buff: *OpPC); |
| 88 | auto Memory = |
| 89 | std::make_unique<uint64_t[]>(num: llvm::APInt::getNumWords(BitWidth)); |
| 90 | |
| 91 | T Result(Memory.get(), BitWidth); |
| 92 | T::deserialize(Buff: *OpPC, Result: &Result); |
| 93 | |
| 94 | OpPC += align(Size: Result.bytesToSerialize()); |
| 95 | |
| 96 | std::string Str; |
| 97 | llvm::raw_string_ostream SS(Str); |
| 98 | SS << std::move(Result); |
| 99 | return Str; |
| 100 | } |
| 101 | |
| 102 | template <> |
| 103 | inline std::string printArg<IntegralAP<true>>(Program &P, CodePtr &OpPC) { |
| 104 | using T = IntegralAP<true>; |
| 105 | uint32_t BitWidth = T::deserializeSize(Buff: *OpPC); |
| 106 | auto Memory = |
| 107 | std::make_unique<uint64_t[]>(num: llvm::APInt::getNumWords(BitWidth)); |
| 108 | |
| 109 | T Result(Memory.get(), BitWidth); |
| 110 | T::deserialize(Buff: *OpPC, Result: &Result); |
| 111 | |
| 112 | OpPC += align(Size: Result.bytesToSerialize()); |
| 113 | |
| 114 | std::string Str; |
| 115 | llvm::raw_string_ostream SS(Str); |
| 116 | SS << std::move(Result); |
| 117 | return Str; |
| 118 | } |
| 119 | |
| 120 | template <> inline std::string printArg<FixedPoint>(Program &P, CodePtr &OpPC) { |
| 121 | auto F = FixedPoint::deserialize(Buff: *OpPC); |
| 122 | OpPC += align(Size: F.bytesToSerialize()); |
| 123 | |
| 124 | std::string Result; |
| 125 | llvm::raw_string_ostream SS(Result); |
| 126 | SS << std::move(F); |
| 127 | return Result; |
| 128 | } |
| 129 | |
| 130 | static bool isJumpOpcode(Opcode Op) { |
| 131 | return Op == OP_Jmp || Op == OP_Jf || Op == OP_Jt; |
| 132 | } |
| 133 | |
| 134 | static size_t getNumDisplayWidth(size_t N) { |
| 135 | unsigned L = 1u, M = 10u; |
| 136 | while (M <= N && ++L != std::numeric_limits<size_t>::digits10 + 1) |
| 137 | M *= 10u; |
| 138 | |
| 139 | return L; |
| 140 | } |
| 141 | |
| 142 | LLVM_DUMP_METHOD void Function::dump(CodePtr PC) const { |
| 143 | dump(OS&: llvm::errs(), PC); |
| 144 | } |
| 145 | |
| 146 | LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS, |
| 147 | CodePtr OpPC) const { |
| 148 | if (OpPC) { |
| 149 | assert(OpPC >= getCodeBegin()); |
| 150 | assert(OpPC <= getCodeEnd()); |
| 151 | } |
| 152 | { |
| 153 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_GREEN, .Bold: true}); |
| 154 | if (const FunctionDecl *FD = getDecl()) { |
| 155 | FD->getNameForDiagnostic( |
| 156 | OS, Policy: P.getContext().getASTContext().getPrintingPolicy(), |
| 157 | /*Qualified=*/true); |
| 158 | } else { |
| 159 | OS << getName(); |
| 160 | } |
| 161 | OS << " " << (const void *)this << "\n" ; |
| 162 | } |
| 163 | OS << "frame size: " << getFrameSize() << "\n" ; |
| 164 | OS << "arg size: " << getArgSize() << "\n" ; |
| 165 | OS << "rvo: " << hasRVO() << "\n" ; |
| 166 | OS << "this arg: " << hasThisPointer() << "\n" ; |
| 167 | |
| 168 | struct OpText { |
| 169 | size_t Addr; |
| 170 | std::string Op; |
| 171 | bool IsJump; |
| 172 | bool CurrentOp = false; |
| 173 | llvm::SmallVector<std::string> Args; |
| 174 | }; |
| 175 | |
| 176 | auto PrintName = [](const char *Name) -> std::string { |
| 177 | return std::string(Name); |
| 178 | }; |
| 179 | |
| 180 | llvm::SmallVector<OpText> Code; |
| 181 | size_t LongestAddr = 0; |
| 182 | size_t LongestOp = 0; |
| 183 | |
| 184 | for (CodePtr Start = getCodeBegin(), PC = Start; PC != getCodeEnd();) { |
| 185 | size_t Addr = PC - Start; |
| 186 | OpText Text; |
| 187 | auto Op = PC.read<Opcode>(); |
| 188 | Text.Addr = Addr; |
| 189 | Text.IsJump = isJumpOpcode(Op); |
| 190 | Text.CurrentOp = (PC == OpPC); |
| 191 | switch (Op) { |
| 192 | #define GET_DISASM |
| 193 | #include "Opcodes.inc" |
| 194 | #undef GET_DISASM |
| 195 | } |
| 196 | Code.push_back(Elt: Text); |
| 197 | LongestOp = std::max(a: Text.Op.size(), b: LongestOp); |
| 198 | LongestAddr = std::max(a: getNumDisplayWidth(N: Addr), b: LongestAddr); |
| 199 | } |
| 200 | |
| 201 | // Record jumps and their targets. |
| 202 | struct JmpData { |
| 203 | size_t From; |
| 204 | size_t To; |
| 205 | }; |
| 206 | llvm::SmallVector<JmpData> Jumps; |
| 207 | for (auto &Text : Code) { |
| 208 | if (Text.IsJump) |
| 209 | Jumps.push_back(Elt: {.From: Text.Addr, .To: Text.Addr + std::stoi(str: Text.Args[0]) + |
| 210 | align(Size: sizeof(Opcode)) + |
| 211 | align(Size: sizeof(int32_t))}); |
| 212 | } |
| 213 | |
| 214 | llvm::SmallVector<std::string> Text; |
| 215 | Text.reserve(N: Code.size()); |
| 216 | size_t LongestLine = 0; |
| 217 | // Print code to a string, one at a time. |
| 218 | for (const auto &C : Code) { |
| 219 | std::string Line; |
| 220 | llvm::raw_string_ostream LS(Line); |
| 221 | if (OpPC) { |
| 222 | if (C.CurrentOp) |
| 223 | LS << " * " ; |
| 224 | else |
| 225 | LS << " " ; |
| 226 | } |
| 227 | LS << C.Addr; |
| 228 | LS.indent(NumSpaces: LongestAddr - getNumDisplayWidth(N: C.Addr) + 4); |
| 229 | LS << C.Op; |
| 230 | LS.indent(NumSpaces: LongestOp - C.Op.size() + 4); |
| 231 | for (auto &Arg : C.Args) { |
| 232 | LS << Arg << ' '; |
| 233 | } |
| 234 | Text.push_back(Elt: Line); |
| 235 | LongestLine = std::max(a: Line.size(), b: LongestLine); |
| 236 | } |
| 237 | |
| 238 | assert(Code.size() == Text.size()); |
| 239 | |
| 240 | auto spaces = [](unsigned N) -> std::string { |
| 241 | std::string S; |
| 242 | for (unsigned I = 0; I != N; ++I) |
| 243 | S += ' '; |
| 244 | return S; |
| 245 | }; |
| 246 | |
| 247 | // Now, draw the jump lines. |
| 248 | for (auto &J : Jumps) { |
| 249 | if (J.To > J.From) { |
| 250 | bool FoundStart = false; |
| 251 | for (size_t LineIndex = 0; LineIndex != Text.size(); ++LineIndex) { |
| 252 | Text[LineIndex] += spaces(LongestLine - Text[LineIndex].size()); |
| 253 | |
| 254 | if (Code[LineIndex].Addr == J.From) { |
| 255 | Text[LineIndex] += " --+" ; |
| 256 | FoundStart = true; |
| 257 | } else if (Code[LineIndex].Addr == J.To) { |
| 258 | Text[LineIndex] += " <-+" ; |
| 259 | break; |
| 260 | } else if (FoundStart) { |
| 261 | Text[LineIndex] += " |" ; |
| 262 | } |
| 263 | } |
| 264 | LongestLine += 5; |
| 265 | } else { |
| 266 | bool FoundStart = false; |
| 267 | for (ssize_t LineIndex = Text.size() - 1; LineIndex >= 0; --LineIndex) { |
| 268 | Text[LineIndex] += spaces(LongestLine - Text[LineIndex].size()); |
| 269 | if (Code[LineIndex].Addr == J.From) { |
| 270 | Text[LineIndex] += " --+" ; |
| 271 | FoundStart = true; |
| 272 | } else if (Code[LineIndex].Addr == J.To) { |
| 273 | Text[LineIndex] += " <-+" ; |
| 274 | break; |
| 275 | } else if (FoundStart) { |
| 276 | Text[LineIndex] += " |" ; |
| 277 | } |
| 278 | } |
| 279 | LongestLine += 5; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | for (auto &Line : Text) |
| 284 | OS << Line << '\n'; |
| 285 | } |
| 286 | |
| 287 | LLVM_DUMP_METHOD void Program::dump() const { dump(OS&: llvm::errs()); } |
| 288 | |
| 289 | static const char *primTypeToString(PrimType T) { |
| 290 | switch (T) { |
| 291 | case PT_Sint8: |
| 292 | return "Sint8" ; |
| 293 | case PT_Uint8: |
| 294 | return "Uint8" ; |
| 295 | case PT_Sint16: |
| 296 | return "Sint16" ; |
| 297 | case PT_Uint16: |
| 298 | return "Uint16" ; |
| 299 | case PT_Sint32: |
| 300 | return "Sint32" ; |
| 301 | case PT_Uint32: |
| 302 | return "Uint32" ; |
| 303 | case PT_Sint64: |
| 304 | return "Sint64" ; |
| 305 | case PT_Uint64: |
| 306 | return "Uint64" ; |
| 307 | case PT_IntAP: |
| 308 | return "IntAP" ; |
| 309 | case PT_IntAPS: |
| 310 | return "IntAPS" ; |
| 311 | case PT_Bool: |
| 312 | return "Bool" ; |
| 313 | case PT_Float: |
| 314 | return "Float" ; |
| 315 | case PT_Ptr: |
| 316 | return "Ptr" ; |
| 317 | case PT_MemberPtr: |
| 318 | return "MemberPtr" ; |
| 319 | case PT_FixedPoint: |
| 320 | return "FixedPoint" ; |
| 321 | } |
| 322 | llvm_unreachable("Unhandled PrimType" ); |
| 323 | } |
| 324 | |
| 325 | static std::string formatBytes(size_t B) { |
| 326 | std::string Result; |
| 327 | llvm::raw_string_ostream SS(Result); |
| 328 | |
| 329 | if (B < (1u << 10u)) |
| 330 | SS << B << " B" ; |
| 331 | else if (B < (1u << 20u)) |
| 332 | SS << llvm::formatv(Fmt: "{0:F2}" , Vals: B / 1024.) << " KB" ; |
| 333 | else |
| 334 | SS << llvm::formatv(Fmt: "{0:F2}" , Vals: B / 1024. / 1024.) << " MB" ; |
| 335 | |
| 336 | return Result; |
| 337 | } |
| 338 | |
| 339 | LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const { |
| 340 | { |
| 341 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_RED, .Bold: true}); |
| 342 | OS << "\n:: Program\n" ; |
| 343 | } |
| 344 | |
| 345 | { |
| 346 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::WHITE, .Bold: true}); |
| 347 | size_t Bytes = 0; |
| 348 | Bytes += Allocator.getTotalMemory(); |
| 349 | // All the maps. |
| 350 | Bytes += GlobalIndices.getMemorySize(); |
| 351 | Bytes += Records.getMemorySize(); |
| 352 | Bytes += DummyVariables.getMemorySize(); |
| 353 | |
| 354 | // All Records. |
| 355 | for (const Record *R : Records.values()) { |
| 356 | Bytes += sizeof(Record) + R->BaseMap.getMemorySize() + |
| 357 | R->VirtualBaseMap.getMemorySize(); |
| 358 | Bytes += R->Fields.capacity_in_bytes() + R->Bases.capacity_in_bytes() + |
| 359 | R->VirtualBases.capacity_in_bytes(); |
| 360 | } |
| 361 | |
| 362 | // Globals are allocated via the allocator, so already counted. |
| 363 | |
| 364 | OS << "Total memory : " << formatBytes(B: Bytes) << '\n'; |
| 365 | OS << "Global Variables: " << Globals.size() << '\n'; |
| 366 | } |
| 367 | unsigned GI = 0; |
| 368 | for (const Global *G : Globals) { |
| 369 | const Descriptor *Desc = G->block()->getDescriptor(); |
| 370 | Pointer GP = getPtrGlobal(Idx: GI); |
| 371 | |
| 372 | OS << GI << ": " << (const void *)G->block() << " " ; |
| 373 | { |
| 374 | ColorScope SC(OS, true, |
| 375 | GP.isInitialized() |
| 376 | ? TerminalColor{.Color: llvm::raw_ostream::GREEN, .Bold: false} |
| 377 | : TerminalColor{.Color: llvm::raw_ostream::RED, .Bold: false}); |
| 378 | OS << (GP.isInitialized() ? "initialized " : "uninitialized " ); |
| 379 | } |
| 380 | if (GP.block()->isDummy()) |
| 381 | OS << "dummy " ; |
| 382 | Desc->dump(OS); |
| 383 | |
| 384 | if (GP.isInitialized() && Desc->IsTemporary) { |
| 385 | if (const auto *MTE = |
| 386 | dyn_cast_if_present<MaterializeTemporaryExpr>(Val: Desc->asExpr()); |
| 387 | MTE && MTE->getLifetimeExtendedTemporaryDecl()) { |
| 388 | if (const APValue *V = |
| 389 | MTE->getLifetimeExtendedTemporaryDecl()->getValue()) { |
| 390 | OS << " (global temporary value: " ; |
| 391 | { |
| 392 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_MAGENTA, .Bold: true}); |
| 393 | std::string VStr; |
| 394 | llvm::raw_string_ostream SS(VStr); |
| 395 | V->dump(OS&: SS, Context: Ctx.getASTContext()); |
| 396 | |
| 397 | for (unsigned I = 0; I != VStr.size(); ++I) { |
| 398 | if (VStr[I] == '\n') |
| 399 | VStr[I] = ' '; |
| 400 | } |
| 401 | VStr.pop_back(); // Remove the newline (or now space) at the end. |
| 402 | OS << VStr; |
| 403 | } |
| 404 | OS << ')'; |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | OS << "\n" ; |
| 410 | if (GP.isInitialized() && Desc->isPrimitive() && !G->block()->isDummy()) { |
| 411 | OS << " " ; |
| 412 | { |
| 413 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_CYAN, .Bold: false}); |
| 414 | OS << primTypeToString(T: Desc->getPrimType()) << " " ; |
| 415 | } |
| 416 | TYPE_SWITCH(Desc->getPrimType(), { GP.deref<T>().print(OS); }); |
| 417 | OS << "\n" ; |
| 418 | } |
| 419 | ++GI; |
| 420 | } |
| 421 | |
| 422 | { |
| 423 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::WHITE, .Bold: true}); |
| 424 | OS << "Functions: " << Funcs.size() << "\n" ; |
| 425 | } |
| 426 | for (const auto &Func : Funcs) { |
| 427 | Func.second->dump(); |
| 428 | } |
| 429 | for (const auto &Anon : AnonFuncs) { |
| 430 | Anon->dump(); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | LLVM_DUMP_METHOD void Descriptor::dump() const { |
| 435 | dump(OS&: llvm::errs()); |
| 436 | llvm::errs() << '\n'; |
| 437 | } |
| 438 | |
| 439 | LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const { |
| 440 | // Source |
| 441 | { |
| 442 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BLUE, .Bold: true}); |
| 443 | if (const auto *ND = dyn_cast_if_present<NamedDecl>(Val: asDecl())) |
| 444 | ND->printQualifiedName(OS); |
| 445 | else if (asExpr()) |
| 446 | OS << "Expr " << (const void *)asExpr(); |
| 447 | } |
| 448 | |
| 449 | // Print a few interesting bits about the descriptor. |
| 450 | if (isPrimitiveArray()) |
| 451 | OS << " primitive-array " << getNumElems() << ' ' |
| 452 | << primTypeToString(T: getPrimType()); |
| 453 | else if (isCompositeArray()) |
| 454 | OS << " composite-array " << getNumElems(); |
| 455 | else if (isUnion()) |
| 456 | OS << " union(" << ElemRecord->getName() << ")" ; |
| 457 | else if (isRecord()) |
| 458 | OS << " record(" << ElemRecord->getName() << ")" ; |
| 459 | else if (isPrimitive()) |
| 460 | OS << " primitive " << primTypeToString(T: getPrimType()); |
| 461 | |
| 462 | if (isZeroSizeArray()) |
| 463 | OS << " zero-size-array" ; |
| 464 | else if (isUnknownSizeArray()) |
| 465 | OS << " unknown-size-array" ; |
| 466 | |
| 467 | if (IsConstexprUnknown) |
| 468 | OS << " constexpr-unknown" ; |
| 469 | } |
| 470 | |
| 471 | /// Dump descriptor, including all valid offsets. |
| 472 | LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset, |
| 473 | unsigned Indent) const { |
| 474 | unsigned Spaces = Indent * 2; |
| 475 | llvm::raw_ostream &OS = llvm::errs(); |
| 476 | OS.indent(NumSpaces: Spaces); |
| 477 | dump(OS); |
| 478 | OS << '\n'; |
| 479 | OS.indent(NumSpaces: Spaces) << "Metadata: " << getMetadataSize() << " bytes\n" ; |
| 480 | OS.indent(NumSpaces: Spaces) << "Size: " << getSize() << " bytes\n" ; |
| 481 | OS.indent(NumSpaces: Spaces) << "AllocSize: " << getAllocSize() << " bytes\n" ; |
| 482 | Offset += getMetadataSize(); |
| 483 | if (isCompositeArray()) { |
| 484 | OS.indent(NumSpaces: Spaces) << "Elements: " << getNumElems() << '\n'; |
| 485 | unsigned FO = Offset; |
| 486 | for (unsigned I = 0; I != getNumElems(); ++I) { |
| 487 | FO += sizeof(InlineDescriptor); |
| 488 | assert(ElemDesc->getMetadataSize() == 0); |
| 489 | OS.indent(NumSpaces: Spaces) << "Element " << I << " offset: " << FO << '\n'; |
| 490 | ElemDesc->dumpFull(Offset: FO, Indent: Indent + 1); |
| 491 | |
| 492 | FO += ElemDesc->getAllocSize(); |
| 493 | } |
| 494 | } else if (isPrimitiveArray()) { |
| 495 | OS.indent(NumSpaces: Spaces) << "Elements: " << getNumElems() << '\n'; |
| 496 | OS.indent(NumSpaces: Spaces) << "Element type: " << primTypeToString(T: getPrimType()) |
| 497 | << '\n'; |
| 498 | unsigned FO = Offset + sizeof(InitMapPtr); |
| 499 | for (unsigned I = 0; I != getNumElems(); ++I) { |
| 500 | OS.indent(NumSpaces: Spaces) << "Element " << I << " offset: " << FO << '\n'; |
| 501 | FO += getElemSize(); |
| 502 | } |
| 503 | } else if (isRecord()) { |
| 504 | ElemRecord->dump(OS, Indentation: Indent + 1, Offset); |
| 505 | unsigned I = 0; |
| 506 | for (const Record::Field &F : ElemRecord->fields()) { |
| 507 | OS.indent(NumSpaces: Spaces) << "- Field " << I << ": " ; |
| 508 | { |
| 509 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_RED, .Bold: true}); |
| 510 | OS << F.Decl->getName(); |
| 511 | } |
| 512 | OS << ". Offset " << (Offset + F.Offset) << "\n" ; |
| 513 | F.Desc->dumpFull(Offset: Offset + F.Offset, Indent: Indent + 1); |
| 514 | ++I; |
| 515 | } |
| 516 | } else if (isPrimitive()) { |
| 517 | } else { |
| 518 | } |
| 519 | |
| 520 | OS << '\n'; |
| 521 | } |
| 522 | |
| 523 | LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const { |
| 524 | { |
| 525 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BLUE, .Bold: true}); |
| 526 | OS << "InlineDescriptor " << (const void *)this << "\n" ; |
| 527 | } |
| 528 | OS << "Offset: " << Offset << "\n" ; |
| 529 | OS << "IsConst: " << IsConst << "\n" ; |
| 530 | OS << "IsInitialized: " << IsInitialized << "\n" ; |
| 531 | OS << "IsBase: " << IsBase << "\n" ; |
| 532 | OS << "IsActive: " << IsActive << "\n" ; |
| 533 | OS << "InUnion: " << InUnion << "\n" ; |
| 534 | OS << "IsFieldMutable: " << IsFieldMutable << "\n" ; |
| 535 | OS << "IsArrayElement: " << IsArrayElement << "\n" ; |
| 536 | OS << "IsConstInMutable: " << IsConstInMutable << '\n'; |
| 537 | OS << "Desc: " ; |
| 538 | if (Desc) |
| 539 | Desc->dump(OS); |
| 540 | else |
| 541 | OS << "nullptr" ; |
| 542 | OS << "\n" ; |
| 543 | } |
| 544 | |
| 545 | LLVM_DUMP_METHOD void InterpFrame::dump(llvm::raw_ostream &OS, |
| 546 | unsigned Indent) const { |
| 547 | unsigned Spaces = Indent * 2; |
| 548 | { |
| 549 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BLUE, .Bold: true}); |
| 550 | OS.indent(NumSpaces: Spaces); |
| 551 | if (getCallee()) |
| 552 | describe(OS); |
| 553 | else |
| 554 | OS << "Frame (Depth: " << getDepth() << ")" ; |
| 555 | OS << "\n" ; |
| 556 | } |
| 557 | OS.indent(NumSpaces: Spaces) << "Function: " << getFunction(); |
| 558 | if (const Function *F = getFunction()) { |
| 559 | OS << " (" << F->getName() << ")" ; |
| 560 | } |
| 561 | OS << "\n" ; |
| 562 | if (hasThisPointer()) |
| 563 | OS.indent(NumSpaces: Spaces) << "This: " << getThis() << "\n" ; |
| 564 | else |
| 565 | OS.indent(NumSpaces: Spaces) << "This: -\n" ; |
| 566 | if (Func && Func->hasRVO()) |
| 567 | OS.indent(NumSpaces: Spaces) << "RVO: " << getRVOPtr() << "\n" ; |
| 568 | else |
| 569 | OS.indent(NumSpaces: Spaces) << "RVO: -\n" ; |
| 570 | OS.indent(NumSpaces: Spaces) << "Depth: " << Depth << "\n" ; |
| 571 | OS.indent(NumSpaces: Spaces) << "ArgSize: " << ArgSize << "\n" ; |
| 572 | OS.indent(NumSpaces: Spaces) << "Args: " << (void *)Args << "\n" ; |
| 573 | #ifndef NDEBUG |
| 574 | OS.indent(Spaces) << "FrameOffset: " << FrameOffset << "\n" ; |
| 575 | #endif |
| 576 | OS.indent(NumSpaces: Spaces) << "FrameSize: " << (Func ? Func->getFrameSize() : 0) |
| 577 | << "\n" ; |
| 578 | |
| 579 | for (const InterpFrame *F = this->Caller; F; F = F->Caller) { |
| 580 | F->dump(OS, Indent: Indent + 1); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | LLVM_DUMP_METHOD void Record::dump(llvm::raw_ostream &OS, unsigned Indentation, |
| 585 | unsigned Offset) const { |
| 586 | unsigned Indent = Indentation * 2; |
| 587 | OS.indent(NumSpaces: Indent); |
| 588 | { |
| 589 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BLUE, .Bold: true}); |
| 590 | OS << getName() << "\n" ; |
| 591 | } |
| 592 | |
| 593 | unsigned I = 0; |
| 594 | for (const Record::Base &B : bases()) { |
| 595 | OS.indent(NumSpaces: Indent) << "- Base " << I << ". Offset " << (Offset + B.Offset) |
| 596 | << "\n" ; |
| 597 | B.R->dump(OS, Indentation: Indentation + 1, Offset: Offset + B.Offset); |
| 598 | ++I; |
| 599 | } |
| 600 | |
| 601 | I = 0; |
| 602 | for (const Record::Field &F : fields()) { |
| 603 | OS.indent(NumSpaces: Indent) << "- Field " << I << ": " ; |
| 604 | { |
| 605 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_RED, .Bold: true}); |
| 606 | OS << F.Decl->getName(); |
| 607 | } |
| 608 | OS << ". Offset " << (Offset + F.Offset) << "\n" ; |
| 609 | ++I; |
| 610 | } |
| 611 | |
| 612 | I = 0; |
| 613 | for (const Record::Base &B : virtual_bases()) { |
| 614 | OS.indent(NumSpaces: Indent) << "- Virtual Base " << I << ". Offset " |
| 615 | << (Offset + B.Offset) << "\n" ; |
| 616 | B.R->dump(OS, Indentation: Indentation + 1, Offset: Offset + B.Offset); |
| 617 | ++I; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) const { |
| 622 | { |
| 623 | ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_BLUE, .Bold: true}); |
| 624 | OS << "Block " << (const void *)this; |
| 625 | } |
| 626 | OS << " (" ; |
| 627 | Desc->dump(OS); |
| 628 | OS << ")\n" ; |
| 629 | unsigned NPointers = 0; |
| 630 | for (const Pointer *P = Pointers; P; P = P->asBlockPointer().Next) { |
| 631 | ++NPointers; |
| 632 | } |
| 633 | OS << " EvalID: " << EvalID << '\n'; |
| 634 | OS << " DeclID: " ; |
| 635 | if (DeclID) |
| 636 | OS << *DeclID << '\n'; |
| 637 | else |
| 638 | OS << "-\n" ; |
| 639 | OS << " Pointers: " << NPointers << "\n" ; |
| 640 | OS << " Dead: " << isDead() << "\n" ; |
| 641 | OS << " Static: " << IsStatic << "\n" ; |
| 642 | OS << " Extern: " << isExtern() << "\n" ; |
| 643 | OS << " Initialized: " << IsInitialized << "\n" ; |
| 644 | OS << " Weak: " << isWeak() << "\n" ; |
| 645 | OS << " Dummy: " << isDummy() << '\n'; |
| 646 | OS << " Dynamic: " << isDynamic() << "\n" ; |
| 647 | } |
| 648 | |
| 649 | LLVM_DUMP_METHOD void EvaluationResult::dump() const { |
| 650 | auto &OS = llvm::errs(); |
| 651 | |
| 652 | if (empty()) { |
| 653 | OS << "Empty\n" ; |
| 654 | } else if (isInvalid()) { |
| 655 | OS << "Invalid\n" ; |
| 656 | } else { |
| 657 | OS << "Value: " ; |
| 658 | #ifndef NDEBUG |
| 659 | assert(Ctx); |
| 660 | Value.dump(OS, Ctx->getASTContext()); |
| 661 | #endif |
| 662 | } |
| 663 | } |
| 664 | |