1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_COMPILER_ASSEMBLER_DISASSEMBLER_KBC_H_
6#define RUNTIME_VM_COMPILER_ASSEMBLER_DISASSEMBLER_KBC_H_
7
8#include "vm/globals.h"
9#if !defined(DART_PRECOMPILED_RUNTIME)
10
11#include "vm/compiler/assembler/disassembler.h"
12
13namespace dart {
14
15// Disassemble instructions.
16class KernelBytecodeDisassembler : public AllStatic {
17 public:
18 // Disassemble instructions between start and end.
19 // (The assumption is that start is at a valid instruction).
20 // Return true if all instructions were successfully decoded, false otherwise.
21 static void Disassemble(uword start,
22 uword end,
23 DisassemblyFormatter* formatter,
24 const Bytecode& bytecode);
25
26 static void Disassemble(uword start,
27 uword end,
28 DisassemblyFormatter* formatter) {
29 Disassemble(start, end, formatter, Bytecode::Handle());
30 }
31
32 static void Disassemble(uword start, uword end, const Bytecode& bytecode) {
33#if !defined(PRODUCT)
34 DisassembleToStdout stdout_formatter;
35 LogBlock lb;
36 Disassemble(start, end, &stdout_formatter, bytecode);
37#else
38 UNREACHABLE();
39#endif
40 }
41
42 static void Disassemble(uword start, uword end) {
43#if !defined(PRODUCT)
44 DisassembleToStdout stdout_formatter;
45 LogBlock lb;
46 Disassemble(start, end, &stdout_formatter);
47#else
48 UNREACHABLE();
49#endif
50 }
51
52 static void Disassemble(uword start,
53 uword end,
54 char* buffer,
55 uintptr_t buffer_size) {
56#if !defined(PRODUCT)
57 DisassembleToMemory memory_formatter(buffer, buffer_size);
58 LogBlock lb;
59 Disassemble(start, end, &memory_formatter);
60#else
61 UNREACHABLE();
62#endif
63 }
64
65 // Decodes one instruction.
66 // Writes a hexadecimal representation into the hex_buffer and a
67 // human-readable representation into the human_buffer.
68 // Writes the length of the decoded instruction in bytes in out_instr_len.
69 static void DecodeInstruction(char* hex_buffer,
70 intptr_t hex_size,
71 char* human_buffer,
72 intptr_t human_size,
73 int* out_instr_len,
74 const Bytecode& bytecode,
75 Object** object,
76 uword pc);
77
78 static void Disassemble(const Function& function);
79
80 private:
81 static const int kHexadecimalBufferSize = 32;
82 static const int kUserReadableBufferSize = 256;
83};
84
85} // namespace dart
86
87#endif // !defined(DART_PRECOMPILED_RUNTIME)
88
89#endif // RUNTIME_VM_COMPILER_ASSEMBLER_DISASSEMBLER_KBC_H_
90