brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 404a5ae Raw
54 lines · c
1//===----------------------------------------------------------------------===//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#ifndef LLDB_SOURCE_UTILITY_WASM_VIRTUAL_REGISTERS_H10#define LLDB_SOURCE_UTILITY_WASM_VIRTUAL_REGISTERS_H11 12#include "lldb/lldb-private.h"13 14namespace lldb_private {15 16// LLDB doesn't have an address space to represents WebAssembly locals,17// globals and operand stacks. We encode these elements into virtual18// registers:19//20//   | tag: 2 bits | index: 30 bits |21//22// Where tag is:23//    0: Not a Wasm location24//    1: Local25//    2: Global26//    3: Operand stack value27enum WasmVirtualRegisterKinds {28  eWasmTagNotAWasmLocation = 0,29  eWasmTagLocal = 1,30  eWasmTagGlobal = 2,31  eWasmTagOperandStack = 3,32};33 34static const uint32_t kWasmVirtualRegisterTagMask = 0x03;35static const uint32_t kWasmVirtualRegisterIndexMask = 0x3fffffff;36static const uint32_t kWasmVirtualRegisterTagShift = 30;37 38inline uint32_t GetWasmVirtualRegisterTag(size_t reg) {39  return (reg >> kWasmVirtualRegisterTagShift) & kWasmVirtualRegisterTagMask;40}41 42inline uint32_t GetWasmVirtualRegisterIndex(size_t reg) {43  return reg & kWasmVirtualRegisterIndexMask;44}45 46inline uint32_t GetWasmRegister(uint8_t tag, uint32_t index) {47  return ((tag & kWasmVirtualRegisterTagMask) << kWasmVirtualRegisterTagShift) |48         (index & kWasmVirtualRegisterIndexMask);49}50 51} // namespace lldb_private52 53#endif54