Debian Codegraph @

js/src/jit/CacheIRReader.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 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jit_CacheIRReader_h
8 #define jit_CacheIRReader_h
9
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12
13 #include <stdint.h>
14 #include "NamespaceImports.h"
15
16 #include "jit/CacheIR.h"
17 #include "jit/CacheIRWriter.h"
18 #include "jit/CompactBuffer.h"
19 #include "js/ScalarType.h"
20 #include "js/Value.h"
21 #include "vm/TypeofEqOperand.h" // TypeofEqOperand
22 #include "wasm/WasmValType.h"
23
24 enum class JSOp : uint8_t;
25
26 namespace js {
27
28 enum class UnaryMathFunction : uint8_t;
29
30 namespace gc {
31 enum class AllocKind : uint8_t;
32 }
33
34 namespace jit {
35
36 class CacheIRStubInfo;
37
38 // Helper class for reading CacheIR bytecode.
39 class MOZ_RAII CacheIRReader {
40 CompactBufferReader buffer_;
41
42 CacheIRReader(const CacheIRReader&) = delete;
43 CacheIRReader& operator=(const CacheIRReader&) = delete;
44
45 public:
46 CacheIRReader(const uint8_t* start, const uint8_t* end)
47 : buffer_(start, end) {}
48 explicit CacheIRReader(const CacheIRWriter& writer)
49 : CacheIRReader(writer.codeStart(), writer.codeEnd()) {}
50 explicit CacheIRReader(const CacheIRStubInfo* stubInfo);
51
52 bool more() const { return buffer_.more(); }
53
54 CacheOp readOp() { return CacheOp(buffer_.readFixedUint16_t()); }
55 CacheOp peekOp() { return CacheOp(buffer_.peekFixedUint16_t()); }
56
57 // Skip data not currently used.
58 void skip() { buffer_.readByte(); }
59 void skip(uint32_t skipLength) {
60 if (skipLength > 0) {
61 buffer_.seek(buffer_.currentPosition(), skipLength);
62 }
63 }
64
65 ValOperandId valOperandId() { return ValOperandId(buffer_.readByte()); }
66 ValueTagOperandId valueTagOperandId() {
67 return ValueTagOperandId(buffer_.readByte());
68 }
69
70 IntPtrOperandId intPtrOperandId() {
71 return IntPtrOperandId(buffer_.readByte());
72 }
73
74 ObjOperandId objOperandId() { return ObjOperandId(buffer_.readByte()); }
75 NumberOperandId numberOperandId() {
76 return NumberOperandId(buffer_.readByte());
77 }
78 StringOperandId stringOperandId() {
79 return StringOperandId(buffer_.readByte());
80 }
81
82 SymbolOperandId symbolOperandId() {
83 return SymbolOperandId(buffer_.readByte());
84 }
85
86 BigIntOperandId bigIntOperandId() {
87 return BigIntOperandId(buffer_.readByte());
88 }
89
90 BooleanOperandId booleanOperandId() {
91 return BooleanOperandId(buffer_.readByte());
92 }
93
94 Int32OperandId int32OperandId() { return Int32OperandId(buffer_.readByte()); }
95
96 uint32_t rawOperandId() { return buffer_.readByte(); }
97
98 uint32_t stubOffset() { return buffer_.readByte() * sizeof(uintptr_t); }
99 GuardClassKind guardClassKind() { return GuardClassKind(buffer_.readByte()); }
100 ArrayBufferViewKind arrayBufferViewKind() {
101 return ArrayBufferViewKind(buffer_.readByte());
102 }
103 ValueType valueType() { return ValueType(buffer_.readByte()); }
104 wasm::ValType::Kind wasmValType() {
105 return wasm::ValType::Kind(buffer_.readByte());
106 }
107 gc::AllocKind allocKind() { return gc::AllocKind(buffer_.readByte()); }
108 CompletionKind completionKind() { return CompletionKind(buffer_.readByte()); }
109 RealmFuses::FuseIndex realmFuseIndex() {
110 return RealmFuses::FuseIndex(buffer_.readByte());
111 }
112
113 Scalar::Type scalarType() { return Scalar::Type(buffer_.readByte()); }
114 JSWhyMagic whyMagic() { return JSWhyMagic(buffer_.readByte()); }
115 JSOp jsop() { return JSOp(buffer_.readByte()); }
116 TypeofEqOperand typeofEqOperand() {
117 return TypeofEqOperand::fromRawValue(buffer_.readByte());
118 }
119 int32_t int32Immediate() { return int32_t(buffer_.readFixedUint32_t()); }
120 uint32_t uint32Immediate() { return buffer_.readFixedUint32_t(); }
121 void* pointer() { return buffer_.readRawPointer(); }
122
123 UnaryMathFunction unaryMathFunction() {
124 return UnaryMathFunction(buffer_.readByte());
125 }
126
127 CallFlags callFlags() {
128 // See CacheIRWriter::writeCallFlagsImm()
129 uint8_t encoded = buffer_.readByte();
130 CallFlags::ArgFormat format =
131 CallFlags::ArgFormat(encoded & CallFlags::ArgFormatMask);
132 bool isConstructing = encoded & CallFlags::IsConstructing;
133 bool isSameRealm = encoded & CallFlags::IsSameRealm;
134 bool needsUninitializedThis = encoded & CallFlags::NeedsUninitializedThis;
135 MOZ_ASSERT_IF(needsUninitializedThis, isConstructing);
136
137 // FunCall and FunApply can't be constructors.
138 MOZ_ASSERT_IF(format == CallFlags::FunCall, !isConstructing);
139 MOZ_ASSERT_IF(format == CallFlags::FunApplyArgsObj, !isConstructing);
140 MOZ_ASSERT_IF(format == CallFlags::FunApplyArray, !isConstructing);
141 MOZ_ASSERT_IF(format == CallFlags::FunApplyNullUndefined, !isConstructing);
142
143 return CallFlags(format, isConstructing, isSameRealm,
144 needsUninitializedThis);
145 }
146
147 uint8_t readByte() { return buffer_.readByte(); }
148 bool readBool() {
149 uint8_t b = buffer_.readByte();
150 MOZ_ASSERT(b <= 1);
151 return bool(b);
152 }
153
154 const uint8_t* currentPosition() const { return buffer_.currentPosition(); }
155 };
156
157 } // namespace jit
158 } // namespace js
159
160 #endif /* jit_CacheIRReader_h */