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 //===----------------------------------------------------------------------===//
17 #include "clang/AST/DeclCXX.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/Format.h"
21 using namespace clang;
22 using namespace clang::interp;
24 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
26 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
28 if (auto *Cons = dyn_cast<CXXConstructorDecl>(F)) {
29 const std::string &Name = Cons->getParent()->getNameAsString();
30 OS << Name << "::" << Name << ":\n";
32 OS << F->getNameAsString() << ":\n";
38 OS << "frame size: " << getFrameSize() << "\n";
39 OS << "arg size: " << getArgSize() << "\n";
40 OS << "rvo: " << hasRVO() << "\n";
42 auto PrintName = [&OS](const char *Name) {
44 for (long I = 0, N = strlen(Name); I < 30 - N; ++I) {
49 for (CodePtr Start = getCodeBegin(), PC = Start; PC != getCodeEnd();) {
50 size_t Addr = PC - Start;
51 auto Op = PC.read<Opcode>();
52 OS << llvm::format("%8d", Addr) << " ";
55 #include "Opcodes.inc"
61 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
63 LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
64 for (auto &Func : Funcs) {
67 for (auto &Anon : AnonFuncs) {