Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
kernel.h
Go to the documentation of this file.
1// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_KERNEL_H_
6#define RUNTIME_VM_KERNEL_H_
7
8#include <memory>
9
10#include "platform/assert.h"
11#include "vm/allocation.h"
12#include "vm/globals.h"
13#include "vm/growable_array.h"
14#include "vm/object.h"
15#include "vm/token_position.h"
16
17namespace dart {
18namespace kernel {
19class NameIndex {
20 public:
21 static constexpr int kInvalidName = -1;
22
23 NameIndex() : value_(kInvalidName) {}
24 explicit NameIndex(int value) : value_(value) {}
25
26 operator int() const { return value_; }
27
28 private:
29 int value_;
30};
31} // namespace kernel
32} // namespace dart
33
34#if !defined(DART_PRECOMPILED_RUNTIME)
35namespace dart {
36
37class BitVector;
38class Field;
39class ParsedFunction;
40class Zone;
41
42namespace kernel {
43
44class Reader;
45struct ProcedureAttributesMetadata;
46class TableSelectorMetadata;
47class UnboxingInfoMetadata;
48
49class StringIndex {
50 public:
51 StringIndex() : value_(-1) {}
52 explicit StringIndex(int value) : value_(value) {}
53
54 operator int() const { return value_; }
55
56 private:
57 int value_;
58};
59
60enum LogicalOperator { kAnd, kOr };
61
62class Program {
63 public:
64 // Read a kernel Program from the given Reader. Note the returned Program
65 // can potentially contain several "sub programs", though the library count
66 // etc will reference the last "sub program" only.
67 static std::unique_ptr<Program> ReadFrom(Reader* reader,
68 const char** error = nullptr);
69
70 static std::unique_ptr<Program> ReadFromFile(const char* script_uri,
71 const char** error = nullptr);
72 static std::unique_ptr<Program> ReadFromBuffer(const uint8_t* buffer,
73 intptr_t buffer_length,
74 const char** error = nullptr);
75 static std::unique_ptr<Program> ReadFromTypedData(
76 const ExternalTypedData& typed_data,
77 const char** error = nullptr);
78
79 bool is_single_program() { return single_program_; }
80 NameIndex main_method() { return main_method_reference_; }
81 intptr_t source_table_offset() const { return source_table_offset_; }
82 intptr_t string_table_offset() const { return string_table_offset_; }
83 intptr_t name_table_offset() const { return name_table_offset_; }
84 intptr_t metadata_payloads_offset() const {
85 return metadata_payloads_offset_;
86 }
87 intptr_t metadata_mappings_offset() const {
88 return metadata_mappings_offset_;
89 }
90 intptr_t constant_table_offset() { return constant_table_offset_; }
91 intptr_t component_index_offset() { return component_index_offset_; }
92 intptr_t library_count() { return library_count_; }
93
94 // The data of the kernel file (single or multiple encoded components).
95 const TypedDataBase& binary() { return *binary_; }
96
97 private:
98 explicit Program(const TypedDataBase* binary) : binary_(binary) {}
99
100 bool single_program_;
101 NameIndex main_method_reference_; // Procedure.
102 intptr_t library_count_;
103
104 // The offset from the start of the binary to the start of the source table.
105 intptr_t source_table_offset_;
106
107 // The offset from the start of the binary to the start of the constant table.
108 intptr_t constant_table_offset_;
109
110 // The offset from the start of the binary to the start of the ending-index.
111 intptr_t component_index_offset_;
112
113 // The offset from the start of the binary to the canonical name table.
114 intptr_t name_table_offset_;
115
116 // The offset from the start of the binary to the metadata payloads.
117 intptr_t metadata_payloads_offset_;
118
119 // The offset from the start of the binary to the metadata mappings.
120 intptr_t metadata_mappings_offset_;
121
122 // The offset from the start of the binary to the start of the string table.
123 intptr_t string_table_offset_;
124
125 const TypedDataBase* binary_ = nullptr;
126
128};
129
130class KernelLineStartsReader {
131 public:
132 KernelLineStartsReader(const dart::TypedData& line_starts_data,
133 dart::Zone* zone);
134
135 ~KernelLineStartsReader() { delete helper_; }
136
137 uint32_t At(intptr_t index) const {
138 return helper_->At(line_starts_data_, index);
139 }
140
141 uint32_t MaxPosition() const;
142
143 // Returns whether the given offset corresponds to a valid source offset
144 // If it does, then *line and *column (if column is not nullptr) are set
145 // to the line and column the token starts at.
146 DART_WARN_UNUSED_RESULT bool LocationForPosition(
147 intptr_t position,
148 intptr_t* line,
149 intptr_t* col = nullptr) const;
150
151 // Returns whether any tokens were found for the given line. When found,
152 // *first_token_index and *last_token_index are set to the first and
153 // last token on the line, respectively.
154 DART_WARN_UNUSED_RESULT bool TokenRangeAtLine(
155 intptr_t line_number,
156 dart::TokenPosition* first_token_index,
157 dart::TokenPosition* last_token_index) const;
158
159 private:
160 class KernelLineStartsHelper {
161 public:
162 KernelLineStartsHelper() {}
163 virtual ~KernelLineStartsHelper() {}
164 virtual uint32_t At(const dart::TypedData& data, intptr_t index) const = 0;
165
166 private:
167 DISALLOW_COPY_AND_ASSIGN(KernelLineStartsHelper);
168 };
169
170 class KernelUint16LineStartsHelper : public KernelLineStartsHelper {
171 public:
172 KernelUint16LineStartsHelper() {}
173 virtual uint32_t At(const dart::TypedData& data, intptr_t index) const;
174
175 private:
176 DISALLOW_COPY_AND_ASSIGN(KernelUint16LineStartsHelper);
177 };
178
179 class KernelUint32LineStartsHelper : public KernelLineStartsHelper {
180 public:
181 KernelUint32LineStartsHelper() {}
182 virtual uint32_t At(const dart::TypedData& data, intptr_t index) const;
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(KernelUint32LineStartsHelper);
186 };
187
188 const dart::TypedData& line_starts_data_;
189 KernelLineStartsHelper* helper_;
190
191 DISALLOW_COPY_AND_ASSIGN(KernelLineStartsReader);
192};
193
194ObjectPtr EvaluateStaticConstFieldInitializer(const Field& field);
195ObjectPtr EvaluateMetadata(const Library& library,
196 intptr_t kernel_offset,
197 bool is_annotations_offset);
198ObjectPtr BuildParameterDescriptor(const Function& function);
199
200// Fills in [is_covariant] and [is_generic_covariant_impl] vectors
201// according to covariance attributes of [function] parameters.
202//
203// [is_covariant] and [is_generic_covariant_impl] should contain bitvectors
204// of function.NumParameters() length.
205void ReadParameterCovariance(const Function& function,
206 BitVector* is_covariant,
207 BitVector* is_generic_covariant_impl);
208
209// Returns true if the given function needs dynamic invocation forwarder:
210// that is if any of the arguments require checking on the dynamic
211// call-site: if function has no parameters or has only covariant parameters
212// as such function already checks all of its parameters.
213bool NeedsDynamicInvocationForwarder(const Function& function);
214
215ProcedureAttributesMetadata ProcedureAttributesOf(const Function& function,
216 Zone* zone);
217
218ProcedureAttributesMetadata ProcedureAttributesOf(const Field& field,
219 Zone* zone);
220
221UnboxingInfoMetadata* UnboxingInfoMetadataOf(const Function& function,
222 Zone* zone);
223
224TableSelectorMetadata* TableSelectorMetadataForProgram(
225 const KernelProgramInfo& info,
226 Zone* zone);
227
228} // namespace kernel
229} // namespace dart
230
231#endif // !defined(DART_PRECOMPILED_RUNTIME)
232#endif // RUNTIME_VM_KERNEL_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
Type::kYUV Type::kRGBA() int(0.7 *637)
NameIndex(int value)
Definition kernel.h:24
static constexpr int kInvalidName
Definition kernel.h:21
#define DART_WARN_UNUSED_RESULT
Definition dart_api.h:66
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
Dart_NativeFunction function
Definition fuchsia.cc:51
void ReadFromFile(char *path, char **buffer_pointer)
Definition unit_test.cc:31
static int8_t data[kExtLength]
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581