LLDB mainline
FormatterBytecode.h
Go to the documentation of this file.
1//===-- FormatterBytecode.h -------------------------------------*- 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#ifndef LLDB_DATAFORMATTERS_FORMATTERBYTECODE_H
10#define LLDB_DATAFORMATTERS_FORMATTERBYTECODE_H
11
14#include "llvm/ADT/APSInt.h"
15#include "llvm/ADT/StringMap.h"
16#include <memory>
17
18namespace lldb_private {
19
21
22enum DataType : uint8_t {
25 Int, ///< Deprecated: use Integer.
26 UInt, ///< Deprecated: use Integer.
31 // Named `Dict` to avoid colliding with the `Dictionary` class, since this
32 // enumerator is scoped to the enclosing namespace.
34};
35
36enum OpCodes : uint8_t {
37#define DEFINE_OPCODE(OP, MNEMONIC, NAME) op_##NAME = OP,
38#include "FormatterBytecode.def"
39#undef DEFINE_OPCODE
40};
41
42enum Selectors : uint8_t {
43#define DEFINE_SELECTOR(ID, NAME) sel_##NAME = ID,
44#include "FormatterBytecode.def"
45#undef DEFINE_SELECTOR
46};
47
48enum Signatures : uint8_t {
49#define DEFINE_SIGNATURE(ID, NAME) sig_##NAME = ID,
50#include "FormatterBytecode.def"
51#undef DEFINE_SIGNATURE
52};
53
54using ControlStackElement = llvm::StringRef;
55using ControlStack = std::vector<ControlStackElement>;
56
57// A Dictionary mapping String keys to DataStackElements. It is always wrapped
58// in a shared_ptr for two reasons:
59// 1. To allow DataStackElement to hold a dictionary, breaking the type
60// reference cyle.
61// 2. To provide reference type behavior. This means `op_dict_set` can mutate
62// the same instance that other stack slots refer to (ex via `dup`).
63class Dictionary;
64using DictionarySP = std::shared_ptr<Dictionary>;
65
66// uint64_t and int64_t are kept for compatibility with the deprecated
67// uint/int opcodes. New code should instead use APSInt (op_lit_integer).
69 std::variant<std::string, uint64_t, int64_t, lldb::ValueObjectSP,
70 CompilerType, Selectors, llvm::APSInt, DictionarySP>;
71
72class Dictionary : public llvm::StringMap<DataStackElement> {};
73
74struct DataStack : public std::vector<DataStackElement> {
75 DataStack() = default;
77 : std::vector<DataStackElement>({initial_value}) {}
78 void Push(DataStackElement el) { push_back(el); }
79 template <typename T> T Pop() {
80 T el = std::get<T>(back());
81 pop_back();
82 return el;
83 }
85 DataStackElement el = back();
86 pop_back();
87 return el;
88 }
89};
90
91llvm::Error Interpret(ControlStack &control, DataStack &data, Signatures sig);
92
93} // namespace FormatterBytecode
94
98
99} // namespace lldb_private
100
101#endif
Generic representation of a type in a programming language.
std::vector< ControlStackElement > ControlStack
std::variant< std::string, uint64_t, int64_t, lldb::ValueObjectSP, CompilerType, Selectors, llvm::APSInt, DictionarySP > DataStackElement
std::shared_ptr< Dictionary > DictionarySP
llvm::Error Interpret(ControlStack &control, DataStack &data, Signatures sig)
@ Int
Deprecated: use Integer.
@ UInt
Deprecated: use Integer.
A class that represents a running process on the host machine.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
DataStack(lldb::ValueObjectSP initial_value)