1 //===--- Disasm.cpp - Disassembler for bytecode functions -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Dump method for Function which disassembles the bytecode.
11 //===----------------------------------------------------------------------===//
18 #include "clang/AST/DeclCXX.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/Format.h"
22 using namespace clang
;
23 using namespace clang::interp
;
25 template <typename T
> inline T
ReadArg(Program
&P
, CodePtr
&OpPC
) {
26 if constexpr (std::is_pointer_v
<T
>) {
27 uint32_t ID
= OpPC
.read
<uint32_t>();
28 return reinterpret_cast<T
>(P
.getNativePointer(ID
));
30 return OpPC
.read
<T
>();
34 template <> inline Floating ReadArg
<Floating
>(Program
&P
, CodePtr
&OpPC
) {
35 Floating F
= Floating::deserialize(*OpPC
);
36 OpPC
+= align(F
.bytesToSerialize());
40 LLVM_DUMP_METHOD
void Function::dump() const { dump(llvm::errs()); }
42 LLVM_DUMP_METHOD
void Function::dump(llvm::raw_ostream
&OS
) const {
43 OS
<< getName() << " " << (const void *)this << "\n";
44 OS
<< "frame size: " << getFrameSize() << "\n";
45 OS
<< "arg size: " << getArgSize() << "\n";
46 OS
<< "rvo: " << hasRVO() << "\n";
47 OS
<< "this arg: " << hasThisPointer() << "\n";
49 auto PrintName
= [&OS
](const char *Name
) {
51 long N
= 30 - strlen(Name
);
56 for (CodePtr Start
= getCodeBegin(), PC
= Start
; PC
!= getCodeEnd();) {
57 size_t Addr
= PC
- Start
;
58 auto Op
= PC
.read
<Opcode
>();
59 OS
<< llvm::format("%8d", Addr
) << " ";
62 #include "Opcodes.inc"
68 LLVM_DUMP_METHOD
void Program::dump() const { dump(llvm::errs()); }
70 LLVM_DUMP_METHOD
void Program::dump(llvm::raw_ostream
&OS
) const {
72 OS
<< "Global Variables: " << Globals
.size() << "\n";
73 OS
<< "Functions: " << Funcs
.size() << "\n";
75 for (auto &Func
: Funcs
) {
78 for (auto &Anon
: AnonFuncs
) {