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