Debian Codegraph @

js/src/wasm/WasmBCClass-inl.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 *
4 * Copyright 2016 Mozilla Foundation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 // This is an INTERNAL header for Wasm baseline compiler: inline BaseCompiler
20 // methods that don't fit in any other group in particular.
21
22 #ifndef wasm_wasm_baseline_object_inl_h
23 #define wasm_wasm_baseline_object_inl_h
24
25 namespace js {
26 namespace wasm {
27
28 const FuncType& BaseCompiler::funcType() const {
29 return codeMeta_.getFuncType(func_.index);
30 }
31
32 bool BaseCompiler::usesMemory() const {
33 return codeMeta_.memories.length() > 0;
34 }
35
36 bool BaseCompiler::usesSharedMemory(uint32_t memoryIndex) const {
37 return codeMeta_.usesSharedMemory(memoryIndex);
38 }
39
40 const Local& BaseCompiler::localFromSlot(uint32_t slot, MIRType type) {
41 MOZ_ASSERT(localInfo_[slot].type == type);
42 return localInfo_[slot];
43 }
44
45 BytecodeOffset BaseCompiler::bytecodeOffset() const {
46 return iter_.bytecodeOffset();
47 }
48
49 TrapSiteDesc BaseCompiler::trapSiteDesc() const {
50 return TrapSiteDesc(bytecodeOffset());
51 }
52
53 bool BaseCompiler::isMem32(uint32_t memoryIndex) const {
54 return codeMeta_.memories[memoryIndex].addressType() == AddressType::I32;
55 }
56
57 bool BaseCompiler::isMem64(uint32_t memoryIndex) const {
58 return codeMeta_.memories[memoryIndex].addressType() == AddressType::I64;
59 }
60
61 bool BaseCompiler::hugeMemoryEnabled(uint32_t memoryIndex) const {
62 return codeMeta_.hugeMemoryEnabled(memoryIndex);
63 }
64
65 uint32_t BaseCompiler::instanceOffsetOfMemoryBase(uint32_t memoryIndex) const {
66 if (memoryIndex == 0) {
67 return Instance::offsetOfMemory0Base();
68 }
69 return Instance::offsetInData(
70 codeMeta_.offsetOfMemoryInstanceData(memoryIndex) +
71 offsetof(MemoryInstanceData, base));
72 }
73
74 uint32_t BaseCompiler::instanceOffsetOfBoundsCheckLimit(
75 uint32_t memoryIndex) const {
76 if (memoryIndex == 0) {
77 return Instance::offsetOfMemory0BoundsCheckLimit();
78 }
79 return Instance::offsetInData(
80 codeMeta_.offsetOfMemoryInstanceData(memoryIndex) +
81 offsetof(MemoryInstanceData, boundsCheckLimit));
82 }
83
84 // The results parameter for BaseCompiler::emitCallArgs is used for
85 // regular Wasm calls.
86 struct NormalCallResults final {
87 const StackResultsLoc& results;
88 explicit NormalCallResults(const StackResultsLoc& results)
89 : results(results) {}
90 inline uint32_t onStackCount() const { return results.count(); }
91 inline StackResults stackResults() const { return results.stackResults(); }
92 inline void getStackResultArea(BaseStackFrame fr, RegPtr dest) const {
93 fr.computeOutgoingStackResultAreaPtr(results, dest);
94 }
95 };
96
97 // The results parameter for BaseCompiler::emitCallArgs is used for
98 // Wasm return/tail calls.
99 struct TailCallResults final {
100 bool hasStackResults;
101 explicit TailCallResults(const FuncType& funcType) {
102 hasStackResults =
103 ABIResultIter::HasStackResults(ResultType::Vector(funcType.results()));
104 }
105 inline uint32_t onStackCount() const { return 0; }
106 inline StackResults stackResults() const {
107 return hasStackResults ? StackResults::HasStackResults
108 : StackResults::NoStackResults;
109 }
110 inline void getStackResultArea(BaseStackFrame fr, RegPtr dest) const {
111 fr.loadIncomingStackResultAreaPtr(dest);
112 }
113 };
114
115 // The results parameter for BaseCompiler::emitCallArgs is used when
116 // no result (area) is expected.
117 struct NoCallResults final {
118 inline uint32_t onStackCount() const { return 0; }
119 inline StackResults stackResults() const {
120 return StackResults::NoStackResults;
121 }
122 inline void getStackResultArea(BaseStackFrame fr, RegPtr dest) const {
123 MOZ_CRASH();
124 }
125 };
126
127 } // namespace wasm
128 } // namespace js
129
130 #endif // wasm_wasm_baseline_object_inl_h