5#ifndef RUNTIME_VM_KERNEL_BINARY_H_
6#define RUNTIME_VM_KERNEL_BINARY_H_
8#if !defined(DART_PRECOMPILED_RUNTIME)
24#define KERNEL_TAG_LIST(V) \
29 V(ExtensionTypeDeclaration, 85) \
34 V(InvalidInitializer, 7) \
35 V(FieldInitializer, 8) \
36 V(SuperInitializer, 9) \
37 V(RedirectingInitializer, 10) \
38 V(LocalInitializer, 11) \
39 V(AssertInitializer, 12) \
40 V(CheckLibraryIsLoaded, 13) \
44 V(StaticTearOff, 17) \
45 V(ConstStaticInvocation, 18) \
46 V(InvalidExpression, 19) \
49 V(AbstractSuperPropertyGet, 22) \
50 V(AbstractSuperPropertySet, 23) \
51 V(SuperPropertyGet, 24) \
52 V(SuperPropertySet, 25) \
55 V(AbstractSuperMethodInvocation, 28) \
56 V(SuperMethodInvocation, 29) \
57 V(StaticInvocation, 30) \
58 V(ConstructorInvocation, 31) \
59 V(ConstConstructorInvocation, 32) \
62 V(LogicalExpression, 34) \
63 V(ConditionalExpression, 35) \
64 V(StringConcatenation, 36) \
65 V(ListConcatenation, 111) \
66 V(SetConcatenation, 112) \
67 V(MapConcatenation, 113) \
68 V(InstanceCreation, 114) \
69 V(FileUriExpression, 116) \
72 V(StringLiteral, 39) \
73 V(DoubleLiteral, 40) \
77 V(SymbolLiteral, 44) \
79 V(ThisExpression, 46) \
85 V(AwaitExpression, 51) \
86 V(FunctionExpression, 52) \
88 V(BlockExpression, 82) \
89 V(Instantiation, 54) \
90 V(PositiveIntLiteral, 55) \
91 V(NegativeIntLiteral, 56) \
92 V(BigIntLiteral, 57) \
93 V(ConstListLiteral, 58) \
94 V(ConstSetLiteral, 110) \
95 V(ConstMapLiteral, 59) \
96 V(ConstructorTearOff, 60) \
97 V(TypedefTearOff, 83) \
98 V(RedirectingFactoryTearOff, 84) \
99 V(RecordIndexGet, 101) \
100 V(RecordNameGet, 102) \
101 V(RecordLiteral, 104) \
102 V(ConstRecordLiteral, 105) \
103 V(ExpressionStatement, 61) \
105 V(EmptyStatement, 63) \
106 V(AssertStatement, 64) \
107 V(LabeledStatement, 65) \
108 V(BreakStatement, 66) \
109 V(WhileStatement, 67) \
111 V(ForStatement, 69) \
112 V(ForInStatement, 70) \
113 V(SwitchStatement, 71) \
114 V(ContinueSwitchStatement, 72) \
116 V(ReturnStatement, 74) \
119 V(YieldStatement, 77) \
120 V(VariableDeclaration, 78) \
121 V(FunctionDeclaration, 79) \
122 V(AsyncForInStatement, 80) \
128 V(InterfaceType, 93) \
129 V(FunctionType, 94) \
130 V(TypeParameterType, 95) \
131 V(SimpleInterfaceType, 96) \
132 V(SimpleFunctionType, 97) \
134 V(IntersectionType, 99) \
136 V(ExtensionType, 103) \
137 V(ConstantExpression, 106) \
138 V(FutureOrType, 107) \
139 V(FileUriConstantExpression, 108) \
140 V(InstanceGet, 118) \
141 V(InstanceSet, 119) \
142 V(InstanceInvocation, 120) \
143 V(InstanceGetterInvocation, 89) \
144 V(InstanceTearOff, 121) \
147 V(DynamicInvocation, 124) \
148 V(FunctionInvocation, 125) \
149 V(FunctionTearOff, 126) \
150 V(LocalFunctionInvocation, 127) \
152 V(AssignedVariablePattern, 129) \
153 V(CastPattern, 130) \
154 V(ConstantPattern, 131) \
155 V(InvalidPattern, 132) \
156 V(ListPattern, 133) \
158 V(NamedPattern, 135) \
159 V(NullAssertPattern, 136) \
160 V(NullCheckPattern, 137) \
161 V(ObjectPattern, 138) \
163 V(RecordPattern, 140) \
164 V(RelationalPattern, 141) \
165 V(RestPattern, 142) \
166 V(VariablePattern, 143) \
167 V(WildcardPattern, 144) \
168 V(MapPatternEntry, 145) \
169 V(MapPatternRestEntry, 146) \
170 V(PatternSwitchStatement, 147) \
171 V(SwitchExpression, 148) \
172 V(IfCaseStatement, 149) \
173 V(PatternAssignment, 150) \
174 V(PatternVariableDeclaration, 151) \
176 V(SpecializedVariableGet, 224) \
177 V(SpecializedVariableSet, 232) \
178 V(SpecializedIntLiteral, 240)
185#define DECLARE(Name, value) k##Name = value,
294 intptr_t fields_before,
296 intptr_t list_index) {
297 intptr_t org_offset =
offset();
300 offset_ = org_offset;
312 intptr_t fields_before,
314 intptr_t list_index) {
315 offset_ = end_offset - (fields_before + list_size - list_index) * 4;
326 ASSERT((size_ >= 8) && (offset_ >= 0) && (offset_ <= size_ - 8));
328 LoadUnaligned(
reinterpret_cast<const double*
>(&raw_buffer_[offset_]));
334 ASSERT((size_ >= 1) && (offset_ >= 0) && (offset_ <= size_ - 1));
336 const uint8_t*
buffer = raw_buffer_;
338 if ((byte0 & 0x80) == 0) {
342 }
else if ((byte0 & 0xc0) == 0x80) {
344 ASSERT((size_ >= 2) && (offset_ >= 0) && (offset_ <= size_ - 2));
346 ((byte0 & ~static_cast<uword>(0x80)) << 8) | (
buffer[offset_ + 1]);
351 ASSERT((size_ >= 4) && (offset_ >= 0) && (offset_ <= size_ - 4));
352 uint32_t
value = ((byte0 & ~static_cast<uword>(0xc0)) << 24) |
353 (
buffer[offset_ + 1] << 16) |
354 (
buffer[offset_ + 2] << 8) | (
buffer[offset_ + 3] << 0);
361 ReadStream stream(raw_buffer_, size_, offset_);
362 const intptr_t
result = stream.ReadSLEB128();
363 offset_ = stream.Position();
368 ReadStream stream(raw_buffer_, size_, offset_);
369 const int64_t
result = stream.ReadSLEB128<int64_t>();
370 offset_ = stream.Position();
389 uint8_t
ReadByte() {
return raw_buffer_[offset_++]; }
391 uint8_t
PeekByte() {
return raw_buffer_[offset_]; }
394 for (
int i = 0; i <
size; i++) {
410 if (payload !=
nullptr) {
415 return static_cast<Tag>(byte);
424 if (payload !=
nullptr) {
429 return static_cast<Tag>(byte);
434 switch (kernel_nullability) {
457 if (offset_ != size_) {
459 "Reading Kernel file: Expected to be at EOF "
460 "(offset: %" Pd ", size: %" Pd ")",
480 intptr_t
offset()
const {
return offset_; }
485 intptr_t
size()
const {
return size_; }
493 return &raw_buffer_[
offset];
504 : thread_(nullptr), raw_buffer_(
buffer), size_(
size) {}
508 raw_buffer_ =
reinterpret_cast<uint8_t*
>(typed_data_->
DataAddr(0));
513 Thread* thread_ =
nullptr;
519 const uint8_t* raw_buffer_ =
nullptr;
522 intptr_t offset_ = 0;
525 intptr_t current_script_id_ = -1;
536 : reader_(reader), saved_offset_(reader_->offset_) {
537 reader_->offset_ = new_position;
541 : reader_(reader), saved_offset_(reader_->offset_) {}
549 const intptr_t saved_offset_;
560 intptr_t new_position)
562 saved_size_(reader_->size_),
563 saved_raw_buffer_(reader_->raw_buffer_),
564 saved_typed_data_(reader_->typed_data_),
565 saved_offset_(reader_->offset_) {
566 reader_->typed_data_ = new_typed_data;
568 reader_->offset_ = new_position;
572 reader_->raw_buffer_ = saved_raw_buffer_;
573 reader_->typed_data_ = saved_typed_data_;
574 reader_->size_ = saved_size_;
575 reader_->offset_ = saved_offset_;
582 intptr_t saved_size_;
583 const uint8_t* saved_raw_buffer_;
585 intptr_t saved_offset_;
599 min_(reader->min_position_),
600 max_(reader->max_position_) {
601 reader->min_position_ = reader->max_position_ = TokenPosition::kNoSource;
static const TokenPosition & Min(const TokenPosition &a, const TokenPosition &b)
static TokenPosition Deserialize(int32_t value)
static const TokenPosition & Max(const TokenPosition &a, const TokenPosition &b)
TypedDataViewPtr ViewFromTo(intptr_t start, intptr_t end, Heap::Space space=Heap::kNew) const
intptr_t LengthInBytes() const
bool IsExternalOrExternalView() const
void * DataAddr(intptr_t byte_offset) const
static uint32_t BigEndianToHost32(uint32_t be_value)
AlternativeReadingScopeWithNewData(Reader *reader, const TypedDataBase *new_typed_data, intptr_t new_position)
~AlternativeReadingScopeWithNewData()
AlternativeReadingScope(Reader *reader, intptr_t new_position)
AlternativeReadingScope(Reader *reader)
~AlternativeReadingScope()
PositionScope(Reader *reader)
const TypedDataBase * typed_data()
static Nullability ConvertNullability(KernelNullability kernel_nullability)
TokenPosition ReadPosition()
uint32_t ReadFromIndexNoReset(intptr_t end_offset, intptr_t fields_before, intptr_t list_size, intptr_t list_index)
void set_offset(intptr_t offset)
TokenPosition min_position()
TokenPosition max_position()
uint32_t ReadUInt32At(intptr_t offset) const
Reader(const TypedDataBase &typed_data)
TypedDataViewPtr ViewFromTo(intptr_t start, intptr_t end)
uint32_t ReadFromIndex(intptr_t end_offset, intptr_t fields_before, intptr_t list_size, intptr_t list_index)
void ReadBytes(uint8_t *buffer, uint8_t size)
TypedDataPtr ReadLineStartsData(intptr_t line_start_count)
Nullability ReadNullability()
Tag ReadTag(uint8_t *payload=nullptr)
int64_t ReadSLEB128AsInt64()
static const char * TagName(Tag tag)
Tag PeekTag(uint8_t *payload=nullptr)
NameIndex ReadCanonicalNameReference()
const uint8_t * BufferAt(intptr_t offset)
intptr_t ReadListLength()
static const uint8_t buffer[]
#define DECLARE(Name, value)
#define KERNEL_TAG_LIST(V)
@ kIsExpressionFlagForLegacy
@ kTypedefTearOffConstant
@ kConstructorTearOffConstant
@ kRedirectingFactoryTearOffConstant
static constexpr int SpecializedIntLiteralBias
@ kYieldStatementFlagYieldStar
static const uint32_t kMagicProgramFile
static constexpr int SourceTableFieldCountFromFirstLibraryOffset
static constexpr int LibraryCountFieldCountFromEnd
static constexpr intptr_t kSpecializedPayloadMask
static constexpr intptr_t kSpecializedTagHighBits
static const uint32_t kSupportedKernelFormatVersion
@ kDynamicInvocationFlagImplicitCall
static constexpr intptr_t kSpecializedTagMask
@ kInstanceInvocationFlagBoundsSafe
@ kInstanceInvocationFlagInvariant
static constexpr int HeaderSize
@ kAsExpressionFlagForLegacy
@ kAsExpressionFlagUnchecked
@ kAsExpressionFlagCovarianceCheck
@ kAsExpressionFlagForDynamic
@ kAsExpressionFlagTypeError
static constexpr int KernelFormatVersionOffset
static T LoadUnaligned(const T *ptr)