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

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

Issue 2854393002: [kernel] [partial] Streaming of kernel binary without AST nodes (Closed)
Patch Set: 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
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_H_ 5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_
6 #define RUNTIME_VM_KERNEL_BINARY_H_ 6 #define RUNTIME_VM_KERNEL_BINARY_H_
7 7
8 #if !defined(DART_PRECOMPILED_RUNTIME) 8 #if !defined(DART_PRECOMPILED_RUNTIME)
9 9
10 #include <map> 10 #include <map>
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 explicit TypeParameterScope(T* builder) : builder_(builder) { 260 explicit TypeParameterScope(T* builder) : builder_(builder) {
261 builder_->type_parameters().EnterScope(); 261 builder_->type_parameters().EnterScope();
262 } 262 }
263 ~TypeParameterScope() { builder_->type_parameters().LeaveScope(); } 263 ~TypeParameterScope() { builder_->type_parameters().LeaveScope(); }
264 264
265 private: 265 private:
266 T* builder_; 266 T* builder_;
267 }; 267 };
268 268
269 269
270 template <typename T>
271 class SwitchCaseScope {
272 public:
273 explicit SwitchCaseScope(T* builder) : builder_(builder) {
274 builder_->switch_cases().EnterScope();
275 }
276 ~SwitchCaseScope() { builder_->switch_cases().LeaveScope(); }
277
278 private:
279 T* builder_;
280 };
281
282
283 // Unlike other scopes, labels from enclosing functions are not visible in 270 // Unlike other scopes, labels from enclosing functions are not visible in
284 // nested functions. The LabelScope class is used to hide outer labels. 271 // nested functions. The LabelScope class is used to hide outer labels.
285 template <typename Builder, typename Block> 272 template <typename Builder, typename Block>
286 class LabelScope { 273 class LabelScope {
287 public: 274 public:
288 explicit LabelScope(Builder* builder) : builder_(builder) { 275 explicit LabelScope(Builder* builder) : builder_(builder) {
289 outer_block_ = builder_->labels(); 276 outer_block_ = builder_->labels();
290 builder_->set_labels(&block_); 277 builder_->set_labels(&block_);
291 } 278 }
292 ~LabelScope() { builder_->set_labels(outer_block_); } 279 ~LabelScope() { builder_->set_labels(outer_block_); }
293 280
294 private: 281 private:
295 Builder* builder_; 282 Builder* builder_;
296 Block block_; 283 Block block_;
297 Block* outer_block_; 284 Block* outer_block_;
298 }; 285 };
299 286
300 287
301 class ReaderHelper { 288 class ReaderHelper {
302 public: 289 public:
303 ReaderHelper() : program_(NULL), labels_(NULL) {} 290 ReaderHelper() : program_(NULL), labels_(NULL) {}
304 291
305 Program* program() { return program_; } 292 Program* program() { return program_; }
306 void set_program(Program* program) { program_ = program; } 293 void set_program(Program* program) { program_ = program; }
307 294
308 BlockStack<VariableDeclaration>& variables() { return scope_; } 295 BlockStack<VariableDeclaration>& variables() { return scope_; }
309 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; } 296 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; }
310 BlockStack<SwitchCase>& switch_cases() { return switch_cases_; }
311 297
312 BlockStack<LabeledStatement>* labels() { return labels_; } 298 BlockStack<LabeledStatement>* labels() { return labels_; }
313 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; } 299 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; }
314 300
315 CanonicalName* GetCanonicalName(int index) { return canonical_names_[index]; } 301 CanonicalName* GetCanonicalName(int index) { return canonical_names_[index]; }
316 void SetCanonicalName(int index, CanonicalName* name) { 302 void SetCanonicalName(int index, CanonicalName* name) {
317 canonical_names_[index] = name; 303 canonical_names_[index] = name;
318 } 304 }
319 void SetCanonicalNameCount(int count) { canonical_names_.SetLength(count); } 305 void SetCanonicalNameCount(int count) { canonical_names_.SetLength(count); }
320 306
321 private: 307 private:
322 Program* program_; 308 Program* program_;
323 MallocGrowableArray<CanonicalName*> canonical_names_; 309 MallocGrowableArray<CanonicalName*> canonical_names_;
324 BlockStack<VariableDeclaration> scope_; 310 BlockStack<VariableDeclaration> scope_;
325 BlockStack<TypeParameter> type_parameters_; 311 BlockStack<TypeParameter> type_parameters_;
326 BlockStack<SwitchCase> switch_cases_;
327 BlockStack<LabeledStatement>* labels_; 312 BlockStack<LabeledStatement>* labels_;
328 }; 313 };
329 314
330 315
331 class Reader { 316 class Reader {
332 public: 317 public:
333 Reader(const uint8_t* buffer, intptr_t size) 318 Reader(const uint8_t* buffer, intptr_t size)
334 : buffer_(buffer), 319 : buffer_(buffer),
335 size_(size), 320 size_(size),
336 offset_(0), 321 offset_(0),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (record) { 405 if (record) {
421 record_token_position(result); 406 record_token_position(result);
422 } 407 }
423 return result; 408 return result;
424 } 409 }
425 410
426 intptr_t ReadListLength() { return ReadUInt(); } 411 intptr_t ReadListLength() { return ReadUInt(); }
427 412
428 uint8_t ReadByte() { return buffer_[offset_++]; } 413 uint8_t ReadByte() { return buffer_[offset_++]; }
429 414
415 uint8_t PeekByte() { return buffer_[offset_]; }
416
430 bool ReadBool() { return (ReadByte() & 1) == 1; } 417 bool ReadBool() { return (ReadByte() & 1) == 1; }
431 418
432 word ReadFlags() { return ReadByte(); } 419 word ReadFlags() { return ReadByte(); }
433 420
434 Tag ReadTag(uint8_t* payload = NULL) { 421 Tag ReadTag(uint8_t* payload = NULL) {
435 uint8_t byte = ReadByte(); 422 uint8_t byte = ReadByte();
436 bool has_payload = (byte & kSpecializedTagHighBit) != 0; 423 bool has_payload = (byte & kSpecializedTagHighBit) != 0;
437 if (has_payload) { 424 if (has_payload) {
438 if (payload != NULL) { 425 if (payload != NULL) {
439 *payload = byte & kSpecializedPayloadMask; 426 *payload = byte & kSpecializedPayloadMask;
440 } 427 }
441 return static_cast<Tag>(byte & kSpecializedTagMask); 428 return static_cast<Tag>(byte & kSpecializedTagMask);
442 } else { 429 } else {
443 return static_cast<Tag>(byte); 430 return static_cast<Tag>(byte);
444 } 431 }
445 } 432 }
446 433
434 Tag PeekTag(uint8_t* payload = NULL) {
435 uint8_t byte = PeekByte();
436 bool has_payload = (byte & kSpecializedTagHighBit) != 0;
437 if (has_payload) {
438 if (payload != NULL) {
439 *payload = byte & kSpecializedPayloadMask;
440 }
441 return static_cast<Tag>(byte & kSpecializedTagMask);
442 } else {
443 return static_cast<Tag>(byte);
444 }
445 }
446
447 const uint8_t* Consume(int count) { 447 const uint8_t* Consume(int count) {
448 ASSERT(offset_ + count <= size_); 448 ASSERT(offset_ + count <= size_);
449 const uint8_t* old = buffer_ + offset_; 449 const uint8_t* old = buffer_ + offset_;
450 offset_ += count; 450 offset_ += count;
451 return old; 451 return old;
452 } 452 }
453 453
454 void EnsureEnd() { 454 void EnsureEnd() {
455 if (offset_ != size_) { 455 if (offset_ != size_) {
456 FATAL2( 456 FATAL2(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 Reader* reader_; 582 Reader* reader_;
583 TokenPosition min_; 583 TokenPosition min_;
584 TokenPosition max_; 584 TokenPosition max_;
585 }; 585 };
586 586
587 } // namespace kernel 587 } // namespace kernel
588 } // namespace dart 588 } // namespace dart
589 589
590 #endif // !defined(DART_PRECOMPILED_RUNTIME) 590 #endif // !defined(DART_PRECOMPILED_RUNTIME)
591 #endif // RUNTIME_VM_KERNEL_BINARY_H_ 591 #endif // RUNTIME_VM_KERNEL_BINARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698