Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: runtime/vm/kernel_binary_flowgraph.h

Issue 2854393002: [kernel] [partial] Streaming of kernel binary without AST nodes (Closed)
Patch Set: Address comments; small fixes; rebased. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/kernel_binary.cc ('k') | runtime/vm/kernel_binary_flowgraph.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ 5 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_
6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ 6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_
7 7
8 #if !defined(DART_PRECOMPILED_RUNTIME) 8 #if !defined(DART_PRECOMPILED_RUNTIME)
9 9
10 #include <map> 10 #include <map>
11 11
12 #include "vm/kernel.h" 12 #include "vm/kernel.h"
13 #include "vm/kernel_binary.h" 13 #include "vm/kernel_binary.h"
14 #include "vm/kernel_to_il.h" 14 #include "vm/kernel_to_il.h"
15 #include "vm/object.h" 15 #include "vm/object.h"
16 16
17 namespace dart { 17 namespace dart {
18 namespace kernel { 18 namespace kernel {
19 19
20 class StreamingDartTypeTranslator {
21 public:
22 StreamingDartTypeTranslator(StreamingFlowGraphBuilder* builder,
23 bool finalize = false);
24
25 // Can return a malformed type.
26 AbstractType& BuildType();
27 // Will return `TypeArguments::null()` in case any of the arguments are
28 // malformed.
29 const TypeArguments& BuildTypeArguments(intptr_t length);
30
31 // Will return `TypeArguments::null()` in case any of the arguments are
32 // malformed.
33 const TypeArguments& BuildInstantiatedTypeArguments(
34 const dart::Class& receiver_class,
35 intptr_t length);
36
37 const Type& ReceiverType(const dart::Class& klass);
38
39 private:
40 // Can build a malformed type.
41 void BuildTypeInternal();
42 void BuildInterfaceType(bool simple);
43 void BuildFunctionType(bool simple);
44 void BuildTypeParameterType();
45
46 class TypeParameterScope {
47 public:
48 TypeParameterScope(StreamingDartTypeTranslator* translator,
49 intptr_t* parameters,
50 intptr_t parameters_count)
51 : parameters_(parameters),
52 parameters_count_(parameters_count),
53 outer_(translator->type_parameter_scope_),
54 translator_(translator) {
55 translator_->type_parameter_scope_ = this;
56 }
57 ~TypeParameterScope() {
58 delete[] parameters_;
59 translator_->type_parameter_scope_ = outer_;
60 }
61
62 TypeParameterScope* outer() const { return outer_; }
63 intptr_t* parameters() const { return parameters_; }
64 intptr_t parameters_count() const { return parameters_count_; }
65
66 private:
67 intptr_t* parameters_;
68 intptr_t parameters_count_;
69 TypeParameterScope* outer_;
70 StreamingDartTypeTranslator* translator_;
71 };
72
73 StreamingFlowGraphBuilder* builder_;
74 TranslationHelper& translation_helper_;
75 ActiveClass* active_class_;
76 TypeParameterScope* type_parameter_scope_;
77 Zone* zone_;
78 AbstractType& result_;
79 bool finalize_;
80 };
81
82
20 class StreamingConstantEvaluator { 83 class StreamingConstantEvaluator {
21 public: 84 public:
22 StreamingConstantEvaluator(StreamingFlowGraphBuilder* builder, 85 explicit StreamingConstantEvaluator(StreamingFlowGraphBuilder* builder);
23 Zone* zone,
24 TranslationHelper* h,
25 DartTypeTranslator* type_translator);
26 86
27 virtual ~StreamingConstantEvaluator() {} 87 virtual ~StreamingConstantEvaluator() {}
28 88
29 Instance& EvaluateExpression(); 89 Instance& EvaluateExpression(intptr_t offset, bool reset_position = true);
30 90 Instance& EvaluateListLiteral(intptr_t offset, bool reset_position = true);
31 void EvaluateStaticGet(); 91 Instance& EvaluateMapLiteral(intptr_t offset, bool reset_position = true);
32 void EvaluateSymbolLiteral(); 92 Instance& EvaluateConstructorInvocation(intptr_t offset,
33 void EvaluateDoubleLiteral(); 93 bool reset_position = true);
94 Object& EvaluateExpressionSafe(intptr_t offset);
34 95
35 private: 96 private:
97 void EvaluateVariableGet();
98 void EvaluateVariableGet(uint8_t payload);
99 void EvaluatePropertyGet();
100 void EvaluateStaticGet();
101 void EvaluateMethodInvocation();
102 void EvaluateStaticInvocation();
103 void EvaluateConstructorInvocationInternal();
104 void EvaluateNot();
105 void EvaluateLogicalExpression();
106 void EvaluateConditionalExpression();
107 void EvaluateStringConcatenation();
108 void EvaluateSymbolLiteral();
109 void EvaluateTypeLiteral();
110 void EvaluateListLiteralInternal();
111 void EvaluateMapLiteralInternal();
112 void EvaluateLet();
113 void EvaluateBigIntLiteral();
114 void EvaluateStringLiteral();
115 void EvaluateIntLiteral(uint8_t payload);
116 void EvaluateIntLiteral(bool is_negative);
117 void EvaluateDoubleLiteral();
118 void EvaluateBoolLiteral(bool value);
119 void EvaluateNullLiteral();
120
121 const Object& RunFunction(const Function& function,
122 intptr_t argument_count,
123 const Instance* receiver,
124 const TypeArguments* type_args);
125
126 const Object& RunFunction(const Function& function,
127 const Array& arguments,
128 const Array& names);
129
36 RawObject* EvaluateConstConstructorCall(const dart::Class& type_class, 130 RawObject* EvaluateConstConstructorCall(const dart::Class& type_class,
37 const TypeArguments& type_arguments, 131 const TypeArguments& type_arguments,
38 const Function& constructor, 132 const Function& constructor,
39 const Object& argument); 133 const Object& argument);
40 134
135 const TypeArguments* TranslateTypeArguments(const Function& target,
136 dart::Class* target_klass);
137
138 void AssertBoolInCheckedMode() {
139 if (isolate_->type_checks() && !result_.IsBool()) {
140 translation_helper_.ReportError("Expected boolean expression.");
141 }
142 }
143
144 bool EvaluateBooleanExpressionHere();
145
41 bool GetCachedConstant(intptr_t kernel_offset, Instance* value); 146 bool GetCachedConstant(intptr_t kernel_offset, Instance* value);
42 void CacheConstantValue(intptr_t kernel_offset, const Instance& value); 147 void CacheConstantValue(intptr_t kernel_offset, const Instance& value);
43 148
44 StreamingFlowGraphBuilder* builder_; 149 StreamingFlowGraphBuilder* builder_;
45 Isolate* isolate_; 150 Isolate* isolate_;
46 Zone* zone_; 151 Zone* zone_;
47 TranslationHelper& translation_helper_; 152 TranslationHelper& translation_helper_;
48 // DartTypeTranslator& type_translator_; 153 StreamingDartTypeTranslator& type_translator_;
49 154
50 Script& script_; 155 Script& script_;
51 Instance& result_; 156 Instance& result_;
52 }; 157 };
53 158
54 159
55 class StreamingFlowGraphBuilder { 160 class StreamingFlowGraphBuilder {
56 public: 161 public:
57 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, 162 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder,
58 const uint8_t* buffer, 163 const uint8_t* buffer,
59 intptr_t buffer_length) 164 intptr_t buffer_length)
60 : flow_graph_builder_(flow_graph_builder), 165 : flow_graph_builder_(flow_graph_builder),
61 translation_helper_(flow_graph_builder->translation_helper_), 166 translation_helper_(flow_graph_builder->translation_helper_),
62 zone_(flow_graph_builder->zone_), 167 zone_(flow_graph_builder->zone_),
63 reader_(new Reader(buffer, buffer_length)), 168 reader_(new Reader(buffer, buffer_length)),
64 constant_evaluator_(this, 169 constant_evaluator_(this),
65 flow_graph_builder->zone_, 170 type_translator_(this, /* finalize= */ true) {}
66 &flow_graph_builder->translation_helper_,
67 &flow_graph_builder->type_translator_) {}
68 171
69 virtual ~StreamingFlowGraphBuilder() {} 172 Fragment BuildExpressionAt(intptr_t kernel_offset);
70 173 Fragment BuildStatementAt(intptr_t kernel_offset);
71 Fragment BuildAt(intptr_t kernel_offset);
72 174
73 private: 175 private:
176 Fragment BuildExpression(TokenPosition* position = NULL);
177 Fragment BuildStatement();
178
74 intptr_t ReaderOffset(); 179 intptr_t ReaderOffset();
75 void SetOffset(intptr_t offset); 180 void SetOffset(intptr_t offset);
76 void SkipBytes(intptr_t skip); 181 void SkipBytes(intptr_t skip);
182 bool ReadBool();
183 uint8_t ReadByte();
77 uint32_t ReadUInt(); 184 uint32_t ReadUInt();
185 uint32_t PeekUInt();
78 intptr_t ReadListLength(); 186 intptr_t ReadListLength();
187 StringIndex ReadStringReference();
79 NameIndex ReadCanonicalNameReference(); 188 NameIndex ReadCanonicalNameReference();
189 StringIndex ReadNameAsStringIndex();
190 const dart::String& ReadNameAsMethodName();
191 const dart::String& ReadNameAsGetterName();
192 const dart::String& ReadNameAsSetterName();
193 void SkipStringReference();
194 void SkipCanonicalNameReference();
195 void SkipDartType();
196 void SkipOptionalDartType();
197 void SkipInterfaceType(bool simple);
198 void SkipFunctionType(bool simple);
199 void SkipExpression();
200 void SkipStatement();
201 void SkipName();
202 void SkipArguments();
203 void SkipVariableDeclaration();
80 TokenPosition ReadPosition(bool record = true); 204 TokenPosition ReadPosition(bool record = true);
81 Tag ReadTag(uint8_t* payload = NULL); 205 Tag ReadTag(uint8_t* payload = NULL);
206 Tag PeekTag(uint8_t* payload = NULL);
207 word ReadFlags();
82 208
209 void loop_depth_inc();
210 void loop_depth_dec();
211 intptr_t for_in_depth();
212 void for_in_depth_inc();
213 void for_in_depth_dec();
214 void catch_depth_inc();
215 void catch_depth_dec();
216 void try_depth_inc();
217 void try_depth_dec();
218 intptr_t CurrentTryIndex();
219 intptr_t AllocateTryIndex();
220 LocalVariable* CurrentException();
221 LocalVariable* CurrentStackTrace();
83 CatchBlock* catch_block(); 222 CatchBlock* catch_block();
223 ActiveClass* active_class();
84 ScopeBuildingResult* scopes(); 224 ScopeBuildingResult* scopes();
85 ParsedFunction* parsed_function(); 225 ParsedFunction* parsed_function();
226 TryFinallyBlock* try_finally_block();
227 SwitchBlock* switch_block();
228 BreakableBlock* breakable_block();
229 GrowableArray<YieldContinuation>& yield_continuations();
230 Value* stack();
231 Value* Pop();
86 232
233 Tag PeekArgumentsFirstPositionalTag();
234 const TypeArguments& PeekArgumentsInstantiatedType(const dart::Class& klass);
235 intptr_t PeekArgumentsCount();
236 intptr_t PeekArgumentsTypeCount();
237 void SkipArgumentsBeforeActualArguments();
238
239 LocalVariable* LookupVariable(intptr_t kernel_offset);
240 LocalVariable* MakeTemporary();
241 Token::Kind MethodKind(const dart::String& name);
242 dart::RawFunction* LookupMethodByMember(NameIndex target,
243 const dart::String& method_name);
244
245 bool NeedsDebugStepCheck(const Function& function, TokenPosition position);
246 bool NeedsDebugStepCheck(Value* value, TokenPosition position);
247
248 void InlineBailout(const char* reason);
87 Fragment DebugStepCheck(TokenPosition position); 249 Fragment DebugStepCheck(TokenPosition position);
88 Fragment LoadLocal(LocalVariable* variable); 250 Fragment LoadLocal(LocalVariable* variable);
251 Fragment Return(TokenPosition position);
89 Fragment PushArgument(); 252 Fragment PushArgument();
253 Fragment EvaluateAssertion();
90 Fragment RethrowException(TokenPosition position, int catch_try_index); 254 Fragment RethrowException(TokenPosition position, int catch_try_index);
91 Fragment ThrowNoSuchMethodError(); 255 Fragment ThrowNoSuchMethodError();
92 Fragment Constant(const Object& value); 256 Fragment Constant(const Object& value);
93 Fragment IntConstant(int64_t value); 257 Fragment IntConstant(int64_t value);
94 Fragment LoadStaticField(); 258 Fragment LoadStaticField();
95 Fragment StaticCall(TokenPosition position, 259 Fragment StaticCall(TokenPosition position,
96 const Function& target, 260 const Function& target,
97 intptr_t argument_count); 261 intptr_t argument_count);
262 Fragment StaticCall(TokenPosition position,
263 const Function& target,
264 intptr_t argument_count,
265 const Array& argument_names);
266 Fragment InstanceCall(TokenPosition position,
267 const dart::String& name,
268 Token::Kind kind,
269 intptr_t argument_count,
270 intptr_t num_args_checked = 1);
271 Fragment InstanceCall(TokenPosition position,
272 const dart::String& name,
273 Token::Kind kind,
274 intptr_t argument_count,
275 const Array& argument_names,
276 intptr_t num_args_checked);
277 Fragment ThrowException(TokenPosition position);
278 Fragment BooleanNegate();
279 Fragment TranslateInstantiatedTypeArguments(
280 const TypeArguments& type_arguments);
281 Fragment StrictCompare(Token::Kind kind, bool number_check = false);
282 Fragment AllocateObject(const dart::Class& klass, intptr_t argument_count);
283 Fragment StoreLocal(TokenPosition position, LocalVariable* variable);
284 Fragment StoreStaticField(TokenPosition position, const dart::Field& field);
285 Fragment StringInterpolate(TokenPosition position);
286 Fragment StringInterpolateSingle(TokenPosition position);
287 Fragment ThrowTypeError();
288 Fragment LoadInstantiatorTypeArguments();
289 Fragment LoadFunctionTypeArguments();
290 Fragment InstantiateType(const AbstractType& type);
291 Fragment CreateArray();
292 Fragment StoreIndexed(intptr_t class_id);
293 Fragment CheckStackOverflow();
294 Fragment CloneContext();
295 Fragment TranslateFinallyFinalizers(TryFinallyBlock* outer_finally,
296 intptr_t target_context_depth);
297 Fragment BranchIfTrue(TargetEntryInstr** then_entry,
298 TargetEntryInstr** otherwise_entry,
299 bool negate);
300 Fragment BranchIfEqual(TargetEntryInstr** then_entry,
301 TargetEntryInstr** otherwise_entry,
302 bool negate);
303 Fragment BranchIfNull(TargetEntryInstr** then_entry,
304 TargetEntryInstr** otherwise_entry,
305 bool negate = false);
306 Fragment CatchBlockEntry(const Array& handler_types,
307 intptr_t handler_index,
308 bool needs_stacktrace);
309 Fragment TryCatch(int try_handler_index);
310 Fragment Drop();
311 Fragment NullConstant();
312 JoinEntryInstr* BuildJoinEntry();
313 JoinEntryInstr* BuildJoinEntry(intptr_t try_index);
314 Fragment Goto(JoinEntryInstr* destination);
315 Fragment BuildImplicitClosureCreation(const Function& target);
316 Fragment CheckBooleanInCheckedMode();
317 Fragment CheckAssignableInCheckedMode(const dart::AbstractType& dst_type,
318 const dart::String& dst_name);
319 Fragment CheckVariableTypeInCheckedMode(intptr_t variable_kernel_position);
320 Fragment CheckVariableTypeInCheckedMode(const AbstractType& dst_type,
321 const dart::String& name_symbol);
322 Fragment EnterScope(intptr_t kernel_offset, bool* new_context = NULL);
323 Fragment ExitScope(intptr_t kernel_offset);
98 324
99 Fragment BuildInvalidExpression(); 325 Fragment TranslateCondition(bool* negate);
100 Fragment BuildStaticGet(); 326 const TypeArguments& BuildTypeArguments();
101 Fragment BuildSymbolLiteral(); 327 Fragment BuildArguments(Array* argument_names,
102 Fragment BuildThisExpression(); 328 intptr_t* argument_count,
103 Fragment BuildRethrow(); 329 bool skip_push_arguments = false,
104 Fragment BuildBigIntLiteral(); 330 bool do_drop = false);
105 Fragment BuildStringLiteral(); 331 Fragment BuildArgumentsFromActualArguments(Array* argument_names,
106 Fragment BuildIntLiteral(uint8_t payload); 332 bool skip_push_arguments = false,
107 Fragment BuildIntLiteral(bool is_negative); 333 bool do_drop = false);
108 Fragment BuildDoubleLiteral(); 334
109 Fragment BuildBoolLiteral(bool value); 335 Fragment BuildInvalidExpression(TokenPosition* position);
110 Fragment BuildNullLiteral(); 336 Fragment BuildVariableGet(TokenPosition* position);
337 Fragment BuildVariableGet(uint8_t payload, TokenPosition* position);
338 Fragment BuildVariableSet(TokenPosition* position);
339 Fragment BuildVariableSet(uint8_t payload, TokenPosition* position);
340 Fragment BuildPropertyGet(TokenPosition* position);
341 Fragment BuildPropertySet(TokenPosition* position);
342 Fragment BuildDirectPropertyGet(TokenPosition* position);
343 Fragment BuildDirectPropertySet(TokenPosition* position);
344 Fragment BuildStaticGet(TokenPosition* position);
345 Fragment BuildStaticSet(TokenPosition* position);
346 Fragment BuildMethodInvocation(TokenPosition* position);
347 Fragment BuildDirectMethodInvocation(TokenPosition* position);
348 Fragment BuildStaticInvocation(bool is_const, TokenPosition* position);
349 Fragment BuildConstructorInvocation(bool is_const, TokenPosition* position);
350 Fragment BuildNot(TokenPosition* position);
351 Fragment BuildLogicalExpression(TokenPosition* position);
352 Fragment BuildConditionalExpression(TokenPosition* position);
353 Fragment BuildStringConcatenation(TokenPosition* position);
354 Fragment BuildIsExpression(TokenPosition* position);
355 Fragment BuildAsExpression(TokenPosition* position);
356 Fragment BuildSymbolLiteral(TokenPosition* position);
357 Fragment BuildTypeLiteral(TokenPosition* position);
358 Fragment BuildThisExpression(TokenPosition* position);
359 Fragment BuildRethrow(TokenPosition* position);
360 Fragment BuildThrow(TokenPosition* position);
361 Fragment BuildListLiteral(bool is_const, TokenPosition* position);
362 Fragment BuildMapLiteral(bool is_const, TokenPosition* position);
363 Fragment BuildLet(TokenPosition* position);
364 Fragment BuildBigIntLiteral(TokenPosition* position);
365 Fragment BuildStringLiteral(TokenPosition* position);
366 Fragment BuildIntLiteral(uint8_t payload, TokenPosition* position);
367 Fragment BuildIntLiteral(bool is_negative, TokenPosition* position);
368 Fragment BuildDoubleLiteral(TokenPosition* position);
369 Fragment BuildBoolLiteral(bool value, TokenPosition* position);
370 Fragment BuildNullLiteral(TokenPosition* position);
371
372 Fragment BuildInvalidStatement();
373 Fragment BuildExpressionStatement();
374 Fragment BuildBlock();
375 Fragment BuildEmptyStatement();
376 Fragment BuildAssertStatement();
377 Fragment BuildLabeledStatement();
378 Fragment BuildBreakStatement();
379 Fragment BuildWhileStatement();
380 Fragment BuildDoStatement();
381 Fragment BuildForStatement();
382 Fragment BuildForInStatement(bool async);
383 Fragment BuildSwitchStatement();
384 Fragment BuildContinueSwitchStatement();
385 Fragment BuildIfStatement();
386 Fragment BuildReturnStatement();
387 Fragment BuildTryCatch();
388 Fragment BuildTryFinally();
389 Fragment BuildYieldStatement();
390 Fragment BuildVariableDeclaration(bool has_tag);
111 391
112 FlowGraphBuilder* flow_graph_builder_; 392 FlowGraphBuilder* flow_graph_builder_;
113 TranslationHelper& translation_helper_; 393 TranslationHelper& translation_helper_;
114 Zone* zone_; 394 Zone* zone_;
115 Reader* reader_; 395 Reader* reader_;
116 StreamingConstantEvaluator constant_evaluator_; 396 StreamingConstantEvaluator constant_evaluator_;
397 StreamingDartTypeTranslator type_translator_;
117 398
118 friend class StreamingConstantEvaluator; 399 friend class StreamingConstantEvaluator;
400 friend class StreamingDartTypeTranslator;
119 }; 401 };
120 402
121 403
122 } // namespace kernel 404 } // namespace kernel
123 } // namespace dart 405 } // namespace dart
124 406
125 #endif // !defined(DART_PRECOMPILED_RUNTIME) 407 #endif // !defined(DART_PRECOMPILED_RUNTIME)
126 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ 408 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_
OLDNEW
« no previous file with comments | « runtime/vm/kernel_binary.cc ('k') | runtime/vm/kernel_binary_flowgraph.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698