xref: /freebsd/contrib/llvm-project/lldb/source/DataFormatters/FormatterBytecode.h (revision 770cf0a5f02dc8983a89c6568d741fbc25baa999)
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 #include "lldb/DataFormatters/TypeSummary.h"
10 #include "lldb/Symbol/CompilerType.h"
11 
12 namespace lldb_private {
13 
14 namespace FormatterBytecode {
15 
16 enum DataType : uint8_t { Any, String, Int, UInt, Object, Type, Selector };
17 
18 enum OpCodes : uint8_t {
19 #define DEFINE_OPCODE(OP, MNEMONIC, NAME) op_##NAME = OP,
20 #include "FormatterBytecode.def"
21 #undef DEFINE_OPCODE
22 };
23 
24 enum Selectors : uint8_t {
25 #define DEFINE_SELECTOR(ID, NAME) sel_##NAME = ID,
26 #include "FormatterBytecode.def"
27 #undef DEFINE_SELECTOR
28 };
29 
30 enum Signatures : uint8_t {
31 #define DEFINE_SIGNATURE(ID, NAME) sig_##NAME = ID,
32 #include "FormatterBytecode.def"
33 #undef DEFINE_SIGNATURE
34 };
35 
36 using ControlStackElement = llvm::StringRef;
37 using DataStackElement =
38     std::variant<std::string, uint64_t, int64_t, lldb::ValueObjectSP,
39                  CompilerType, Selectors>;
40 struct DataStack : public std::vector<DataStackElement> {
41   DataStack() = default;
42   DataStack(lldb::ValueObjectSP initial_value)
43       : std::vector<DataStackElement>({initial_value}) {}
44   void Push(DataStackElement el) { push_back(el); }
45   template <typename T> T Pop() {
46     T el = std::get<T>(back());
47     pop_back();
48     return el;
49   }
50   DataStackElement PopAny() {
51     DataStackElement el = back();
52     pop_back();
53     return el;
54   }
55 };
56 llvm::Error Interpret(std::vector<ControlStackElement> &control,
57                       DataStack &data, Selectors sel);
58 } // namespace FormatterBytecode
59 
60 std::string toString(FormatterBytecode::OpCodes op);
61 std::string toString(FormatterBytecode::Selectors sel);
62 std::string toString(FormatterBytecode::Signatures sig);
63 
64 } // namespace lldb_private
65