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/. */
7 #ifndef jit_CacheIRReader_h
8 #define jit_CacheIRReader_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
14 #include "NamespaceImports.h"
16 #include "jit/CacheIR.h"
17 #include "jit/CacheIRWriter.h"
18 #include "jit/CompactBuffer.h"
19 #include "js/ScalarType.h"
21 #include "wasm/WasmValType.h"
23 enum class JSOp
: uint8_t;
27 enum class UnaryMathFunction
: uint8_t;
30 enum class AllocKind
: uint8_t;
35 class CacheIRStubInfo
;
37 // Helper class for reading CacheIR bytecode.
38 class MOZ_RAII CacheIRReader
{
39 CompactBufferReader buffer_
;
41 CacheIRReader(const CacheIRReader
&) = delete;
42 CacheIRReader
& operator=(const CacheIRReader
&) = delete;
45 CacheIRReader(const uint8_t* start
, const uint8_t* end
)
46 : buffer_(start
, end
) {}
47 explicit CacheIRReader(const CacheIRWriter
& writer
)
48 : CacheIRReader(writer
.codeStart(), writer
.codeEnd()) {}
49 explicit CacheIRReader(const CacheIRStubInfo
* stubInfo
);
51 bool more() const { return buffer_
.more(); }
53 CacheOp
readOp() { return CacheOp(buffer_
.readFixedUint16_t()); }
54 CacheOp
peekOp() { return CacheOp(buffer_
.peekFixedUint16_t()); }
56 // Skip data not currently used.
57 void skip() { buffer_
.readByte(); }
58 void skip(uint32_t skipLength
) {
60 buffer_
.seek(buffer_
.currentPosition(), skipLength
);
64 ValOperandId
valOperandId() { return ValOperandId(buffer_
.readByte()); }
65 ValueTagOperandId
valueTagOperandId() {
66 return ValueTagOperandId(buffer_
.readByte());
69 IntPtrOperandId
intPtrOperandId() {
70 return IntPtrOperandId(buffer_
.readByte());
73 ObjOperandId
objOperandId() { return ObjOperandId(buffer_
.readByte()); }
74 NumberOperandId
numberOperandId() {
75 return NumberOperandId(buffer_
.readByte());
77 StringOperandId
stringOperandId() {
78 return StringOperandId(buffer_
.readByte());
81 SymbolOperandId
symbolOperandId() {
82 return SymbolOperandId(buffer_
.readByte());
85 BigIntOperandId
bigIntOperandId() {
86 return BigIntOperandId(buffer_
.readByte());
89 BooleanOperandId
booleanOperandId() {
90 return BooleanOperandId(buffer_
.readByte());
93 Int32OperandId
int32OperandId() { return Int32OperandId(buffer_
.readByte()); }
95 uint32_t rawOperandId() { return buffer_
.readByte(); }
97 uint32_t stubOffset() { return buffer_
.readByte() * sizeof(uintptr_t); }
98 GuardClassKind
guardClassKind() { return GuardClassKind(buffer_
.readByte()); }
99 ArrayBufferViewKind
arrayBufferViewKind() {
100 return ArrayBufferViewKind(buffer_
.readByte());
102 ValueType
valueType() { return ValueType(buffer_
.readByte()); }
103 wasm::ValType::Kind
wasmValType() {
104 return wasm::ValType::Kind(buffer_
.readByte());
106 gc::AllocKind
allocKind() { return gc::AllocKind(buffer_
.readByte()); }
107 CompletionKind
completionKind() { return CompletionKind(buffer_
.readByte()); }
108 RealmFuses::FuseIndex
realmFuseIndex() {
109 return RealmFuses::FuseIndex(buffer_
.readByte());
112 Scalar::Type
scalarType() { return Scalar::Type(buffer_
.readByte()); }
113 JSWhyMagic
whyMagic() { return JSWhyMagic(buffer_
.readByte()); }
114 JSOp
jsop() { return JSOp(buffer_
.readByte()); }
115 int32_t int32Immediate() { return int32_t(buffer_
.readFixedUint32_t()); }
116 uint32_t uint32Immediate() { return buffer_
.readFixedUint32_t(); }
117 void* pointer() { return buffer_
.readRawPointer(); }
119 UnaryMathFunction
unaryMathFunction() {
120 return UnaryMathFunction(buffer_
.readByte());
123 CallFlags
callFlags() {
124 // See CacheIRWriter::writeCallFlagsImm()
125 uint8_t encoded
= buffer_
.readByte();
126 CallFlags::ArgFormat format
=
127 CallFlags::ArgFormat(encoded
& CallFlags::ArgFormatMask
);
128 bool isConstructing
= encoded
& CallFlags::IsConstructing
;
129 bool isSameRealm
= encoded
& CallFlags::IsSameRealm
;
130 bool needsUninitializedThis
= encoded
& CallFlags::NeedsUninitializedThis
;
131 MOZ_ASSERT_IF(needsUninitializedThis
, isConstructing
);
133 // FunCall and FunApply can't be constructors.
134 MOZ_ASSERT_IF(format
== CallFlags::FunCall
, !isConstructing
);
135 MOZ_ASSERT_IF(format
== CallFlags::FunApplyArgsObj
, !isConstructing
);
136 MOZ_ASSERT_IF(format
== CallFlags::FunApplyArray
, !isConstructing
);
137 MOZ_ASSERT_IF(format
== CallFlags::FunApplyNullUndefined
, !isConstructing
);
139 return CallFlags(format
, isConstructing
, isSameRealm
,
140 needsUninitializedThis
);
143 uint8_t readByte() { return buffer_
.readByte(); }
145 uint8_t b
= buffer_
.readByte();
150 const uint8_t* currentPosition() const { return buffer_
.currentPosition(); }
156 #endif /* jit_CacheIRReader_h */