OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS 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 | 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_TO_IL_H_ | 5 #ifndef RUNTIME_VM_KERNEL_TO_IL_H_ |
6 #define RUNTIME_VM_KERNEL_TO_IL_H_ | 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
11 #include "vm/hash_map.h" | 11 #include "vm/hash_map.h" |
12 | 12 |
13 #include "vm/flow_graph.h" | 13 #include "vm/flow_graph.h" |
14 #include "vm/flow_graph_builder.h" | 14 #include "vm/flow_graph_builder.h" |
15 #include "vm/intermediate_language.h" | 15 #include "vm/intermediate_language.h" |
16 #include "vm/kernel.h" | 16 #include "vm/kernel.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 namespace kernel { | 19 namespace kernel { |
20 | 20 |
21 class StreamingFlowGraphBuilder; | 21 class StreamingFlowGraphBuilder; |
22 | 22 |
23 // TODO(27590): Instead of using [dart::kernel::TreeNode]s as keys we | |
24 // should use [TokenPosition]s. | |
25 class KernelConstMapKeyEqualsTraits { | 23 class KernelConstMapKeyEqualsTraits { |
26 public: | 24 public: |
27 static const char* Name() { return "KernelConstMapKeyEqualsTraits"; } | 25 static const char* Name() { return "KernelConstMapKeyEqualsTraits"; } |
28 static bool ReportStats() { return false; } | 26 static bool ReportStats() { return false; } |
29 | 27 |
30 static bool IsMatch(const Object& a, const Object& b) { | 28 static bool IsMatch(const Object& a, const Object& b) { |
31 const Smi& key1 = Smi::Cast(a); | 29 const Smi& key1 = Smi::Cast(a); |
32 const Smi& key2 = Smi::Cast(b); | 30 const Smi& key2 = Smi::Cast(b); |
33 return (key1.Value() == key2.Value()); | 31 return (key1.Value() == key2.Value()); |
34 } | 32 } |
35 static bool IsMatch(const TreeNode* key1, const Object& b) { | 33 static bool IsMatch(const intptr_t key1, const Object& b) { |
36 return KeyAsSmi(key1) == Smi::Cast(b).raw(); | 34 return KeyAsSmi(key1) == Smi::Cast(b).raw(); |
37 } | 35 } |
38 static uword Hash(const Object& obj) { | 36 static uword Hash(const Object& obj) { |
39 const Smi& key = Smi::Cast(obj); | 37 const Smi& key = Smi::Cast(obj); |
40 return HashValue(key.Value()); | 38 return HashValue(key.Value()); |
41 } | 39 } |
42 static uword Hash(const TreeNode* key) { | 40 static uword Hash(const intptr_t key) { |
43 return HashValue(Smi::Value(KeyAsSmi(key))); | 41 return HashValue(Smi::Value(KeyAsSmi(key))); |
44 } | 42 } |
45 static RawObject* NewKey(const TreeNode* key) { return KeyAsSmi(key); } | 43 static RawObject* NewKey(const intptr_t key) { return KeyAsSmi(key); } |
46 | 44 |
47 private: | 45 private: |
48 static uword HashValue(intptr_t pos) { return pos % (Smi::kMaxValue - 13); } | 46 static uword HashValue(intptr_t pos) { return pos % (Smi::kMaxValue - 13); } |
49 | 47 |
50 static RawSmi* KeyAsSmi(const TreeNode* key) { | 48 static RawSmi* KeyAsSmi(const intptr_t key) { |
51 // We exploit that all [TreeNode] objects will be aligned and therefore are | 49 ASSERT(key >= 0); |
52 // already [Smi]s! | 50 return Smi::New(key); |
53 return reinterpret_cast<RawSmi*>(const_cast<TreeNode*>(key)); | |
54 } | 51 } |
55 }; | 52 }; |
56 typedef UnorderedHashMap<KernelConstMapKeyEqualsTraits> KernelConstantsMap; | 53 typedef UnorderedHashMap<KernelConstMapKeyEqualsTraits> KernelConstantsMap; |
57 | 54 |
58 | 55 |
59 template <typename K, typename V> | 56 template <typename K, typename V> |
60 class Map : public DirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { | 57 class Map : public DirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { |
61 public: | 58 public: |
62 typedef typename RawPointerKeyValueTrait<K, V>::Key Key; | 59 typedef typename RawPointerKeyValueTrait<K, V>::Key Key; |
63 typedef typename RawPointerKeyValueTrait<K, V>::Value Value; | 60 typedef typename RawPointerKeyValueTrait<K, V>::Value Value; |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 translation_helper_.ReportError("Expected boolean expression."); | 525 translation_helper_.ReportError("Expected boolean expression."); |
529 } | 526 } |
530 } | 527 } |
531 | 528 |
532 bool EvaluateBooleanExpression(Expression* expression) { | 529 bool EvaluateBooleanExpression(Expression* expression) { |
533 EvaluateExpression(expression); | 530 EvaluateExpression(expression); |
534 AssertBoolInCheckedMode(); | 531 AssertBoolInCheckedMode(); |
535 return result_.raw() == Bool::True().raw(); | 532 return result_.raw() == Bool::True().raw(); |
536 } | 533 } |
537 | 534 |
538 // TODO(27590): Instead of using [dart::kernel::TreeNode]s as keys we | |
539 // should use [TokenPosition]s as well as the existing functionality in | |
540 // `Parser::CacheConstantValue`. | |
541 bool GetCachedConstant(TreeNode* node, Instance* value); | 535 bool GetCachedConstant(TreeNode* node, Instance* value); |
542 void CacheConstantValue(TreeNode* node, const Instance& value); | 536 void CacheConstantValue(TreeNode* node, const Instance& value); |
543 | 537 |
544 FlowGraphBuilder* builder_; | 538 FlowGraphBuilder* builder_; |
545 Isolate* isolate_; | 539 Isolate* isolate_; |
546 Zone* zone_; | 540 Zone* zone_; |
547 TranslationHelper& translation_helper_; | 541 TranslationHelper& translation_helper_; |
548 DartTypeTranslator& type_translator_; | 542 DartTypeTranslator& type_translator_; |
549 | 543 |
550 Script& script_; | 544 Script& script_; |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 namespace kernel { | 1105 namespace kernel { |
1112 | 1106 |
1113 RawObject* EvaluateMetadata(TreeNode* const kernel_node); | 1107 RawObject* EvaluateMetadata(TreeNode* const kernel_node); |
1114 RawObject* BuildParameterDescriptor(TreeNode* const kernel_node); | 1108 RawObject* BuildParameterDescriptor(TreeNode* const kernel_node); |
1115 | 1109 |
1116 } // namespace kernel | 1110 } // namespace kernel |
1117 } // namespace dart | 1111 } // namespace dart |
1118 | 1112 |
1119 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1113 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1120 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ | 1114 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ |
OLD | NEW |