65 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/DataFormatters/TypeSummary.h"10#include "lldb/Symbol/CompilerType.h"11 12namespace lldb_private {13 14namespace FormatterBytecode {15 16enum DataType : uint8_t { Any, String, Int, UInt, Object, Type, Selector };17 18enum OpCodes : uint8_t {19#define DEFINE_OPCODE(OP, MNEMONIC, NAME) op_##NAME = OP,20#include "FormatterBytecode.def"21#undef DEFINE_OPCODE22};23 24enum Selectors : uint8_t {25#define DEFINE_SELECTOR(ID, NAME) sel_##NAME = ID,26#include "FormatterBytecode.def"27#undef DEFINE_SELECTOR28};29 30enum Signatures : uint8_t {31#define DEFINE_SIGNATURE(ID, NAME) sig_##NAME = ID,32#include "FormatterBytecode.def"33#undef DEFINE_SIGNATURE34};35 36using ControlStackElement = llvm::StringRef;37using DataStackElement =38 std::variant<std::string, uint64_t, int64_t, lldb::ValueObjectSP,39 CompilerType, Selectors>;40struct 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};56llvm::Error Interpret(std::vector<ControlStackElement> &control,57 DataStack &data, Selectors sel);58} // namespace FormatterBytecode59 60std::string toString(FormatterBytecode::OpCodes op);61std::string toString(FormatterBytecode::Selectors sel);62std::string toString(FormatterBytecode::Signatures sig);63 64} // namespace lldb_private65