11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#if !V8_ENABLE_WEBASSEMBLY
61cb0ef41Sopenharmony_ci#error This header should only be included if WebAssembly is enabled.
71cb0ef41Sopenharmony_ci#endif  // !V8_ENABLE_WEBASSEMBLY
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#ifndef V8_WASM_OBJECT_ACCESS_H_
101cb0ef41Sopenharmony_ci#define V8_WASM_OBJECT_ACCESS_H_
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#include "src/common/globals.h"
131cb0ef41Sopenharmony_ci#include "src/objects/fixed-array.h"
141cb0ef41Sopenharmony_ci#include "src/objects/js-function.h"
151cb0ef41Sopenharmony_ci#include "src/objects/js-objects.h"
161cb0ef41Sopenharmony_ci#include "src/objects/shared-function-info.h"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cinamespace v8 {
191cb0ef41Sopenharmony_cinamespace internal {
201cb0ef41Sopenharmony_cinamespace wasm {
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciclass ObjectAccess : public AllStatic {
231cb0ef41Sopenharmony_ci public:
241cb0ef41Sopenharmony_ci  // Convert an offset into an object to an offset into a tagged object.
251cb0ef41Sopenharmony_ci  static constexpr int ToTagged(int offset) { return offset - kHeapObjectTag; }
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  // Get the offset into a fixed array for a given {index}.
281cb0ef41Sopenharmony_ci  static constexpr int ElementOffsetInTaggedFixedArray(int index) {
291cb0ef41Sopenharmony_ci    return ToTagged(FixedArray::OffsetOfElementAt(index));
301cb0ef41Sopenharmony_ci  }
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  // Get the offset of the context stored in a {JSFunction} object.
331cb0ef41Sopenharmony_ci  static constexpr int ContextOffsetInTaggedJSFunction() {
341cb0ef41Sopenharmony_ci    return ToTagged(JSFunction::kContextOffset);
351cb0ef41Sopenharmony_ci  }
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  // Get the offset of the shared function info in a {JSFunction} object.
381cb0ef41Sopenharmony_ci  static constexpr int SharedFunctionInfoOffsetInTaggedJSFunction() {
391cb0ef41Sopenharmony_ci    return ToTagged(JSFunction::kSharedFunctionInfoOffset);
401cb0ef41Sopenharmony_ci  }
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  // Get the offset of the formal parameter count in a {SharedFunctionInfo}
431cb0ef41Sopenharmony_ci  // object.
441cb0ef41Sopenharmony_ci  static constexpr int FormalParameterCountOffsetInSharedFunctionInfo() {
451cb0ef41Sopenharmony_ci    return ToTagged(SharedFunctionInfo::kFormalParameterCountOffset);
461cb0ef41Sopenharmony_ci  }
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  // Get the offset of the flags in a {SharedFunctionInfo} object.
491cb0ef41Sopenharmony_ci  static constexpr int FlagsOffsetInSharedFunctionInfo() {
501cb0ef41Sopenharmony_ci    return ToTagged(SharedFunctionInfo::kFlagsOffset);
511cb0ef41Sopenharmony_ci  }
521cb0ef41Sopenharmony_ci};
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci}  // namespace wasm
551cb0ef41Sopenharmony_ci}  // namespace internal
561cb0ef41Sopenharmony_ci}  // namespace v8
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci#endif  // V8_WASM_OBJECT_ACCESS_H_
59