OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "vm/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/flow_graph_allocator.h" | 10 #include "vm/flow_graph_allocator.h" |
(...skipping 2899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2910 // deoptimization occurs. | 2910 // deoptimization occurs. |
2911 Definition* StringInterpolateInstr::Canonicalize(FlowGraph* flow_graph) { | 2911 Definition* StringInterpolateInstr::Canonicalize(FlowGraph* flow_graph) { |
2912 // The following graph structure is generated by the graph builder: | 2912 // The following graph structure is generated by the graph builder: |
2913 // v2 <- CreateArray(v0) | 2913 // v2 <- CreateArray(v0) |
2914 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value. | 2914 // StoreIndexed(v2, v3, v4) -- v3:constant index, v4: value. |
2915 // .. | 2915 // .. |
2916 // v8 <- StringInterpolate(v2) | 2916 // v8 <- StringInterpolate(v2) |
2917 CreateArrayInstr* create_array = value()->definition()->AsCreateArray(); | 2917 CreateArrayInstr* create_array = value()->definition()->AsCreateArray(); |
2918 ASSERT(create_array != NULL); | 2918 ASSERT(create_array != NULL); |
2919 // Check if the string interpolation has only constant inputs. | 2919 // Check if the string interpolation has only constant inputs. |
2920 GrowableArray<ConstantInstr*> constants(create_array->num_elements()); | 2920 Value* num_elements = create_array->num_elements(); |
2921 for (intptr_t i = 0; i < create_array->num_elements(); i++) { | 2921 if (!num_elements->BindsToConstant() || |
2922 !num_elements->BoundConstant().IsSmi()) { | |
srdjan
2014/01/30 17:55:23
I think num_elements->BoundConstant must be a Smi,
Florian Schneider
2014/01/31 12:43:34
For now, I'll keep this (more general) version sin
| |
2923 return this; | |
2924 } | |
2925 intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); | |
2926 GrowableArray<ConstantInstr*> constants(length); | |
2927 for (intptr_t i = 0; i < length; i++) { | |
2922 constants.Add(NULL); | 2928 constants.Add(NULL); |
2923 } | 2929 } |
2924 for (Value::Iterator it(create_array->input_use_list()); | 2930 for (Value::Iterator it(create_array->input_use_list()); |
2925 !it.Done(); | 2931 !it.Done(); |
2926 it.Advance()) { | 2932 it.Advance()) { |
2927 Instruction* curr = it.Current()->instruction(); | 2933 Instruction* curr = it.Current()->instruction(); |
2928 if (curr != this) { | 2934 if (curr != this) { |
2929 StoreIndexedInstr* store = curr->AsStoreIndexed(); | 2935 StoreIndexedInstr* store = curr->AsStoreIndexed(); |
2930 ASSERT(store != NULL); | 2936 ASSERT(store != NULL); |
2931 if (store->value()->definition()->IsConstant()) { | 2937 if (store->value()->definition()->IsConstant()) { |
2932 ASSERT(store->index()->BindsToConstant()); | 2938 ASSERT(store->index()->BindsToConstant()); |
2933 const Object& obj = store->value()->definition()->AsConstant()->value(); | 2939 const Object& obj = store->value()->definition()->AsConstant()->value(); |
2934 if (obj.IsNumber() || obj.IsString() || obj.IsBool() || obj.IsNull()) { | 2940 if (obj.IsNumber() || obj.IsString() || obj.IsBool() || obj.IsNull()) { |
2935 constants[Smi::Cast(store->index()->BoundConstant()).Value()] = | 2941 constants[Smi::Cast(store->index()->BoundConstant()).Value()] = |
2936 store->value()->definition()->AsConstant(); | 2942 store->value()->definition()->AsConstant(); |
2937 } else { | 2943 } else { |
2938 return this; | 2944 return this; |
2939 } | 2945 } |
2940 } else { | 2946 } else { |
2941 return this; | 2947 return this; |
2942 } | 2948 } |
2943 } | 2949 } |
2944 } | 2950 } |
2945 // Interpolate string at compile time. | 2951 // Interpolate string at compile time. |
2946 const Array& array_argument = | 2952 const Array& array_argument = |
2947 Array::Handle(Array::New(create_array->num_elements())); | 2953 Array::Handle(Array::New(length)); |
2948 for (intptr_t i = 0; i < constants.length(); i++) { | 2954 for (intptr_t i = 0; i < constants.length(); i++) { |
2949 array_argument.SetAt(i, constants[i]->value()); | 2955 array_argument.SetAt(i, constants[i]->value()); |
2950 } | 2956 } |
2951 // Build argument array to pass to the interpolation function. | 2957 // Build argument array to pass to the interpolation function. |
2952 const Array& interpolate_arg = Array::Handle(Array::New(1)); | 2958 const Array& interpolate_arg = Array::Handle(Array::New(1)); |
2953 interpolate_arg.SetAt(0, array_argument); | 2959 interpolate_arg.SetAt(0, array_argument); |
2954 // Call interpolation function. | 2960 // Call interpolation function. |
2955 String& concatenated = String::ZoneHandle(); | 2961 String& concatenated = String::ZoneHandle(); |
2956 concatenated ^= | 2962 concatenated ^= |
2957 DartEntry::InvokeFunction(CallFunction(), interpolate_arg); | 2963 DartEntry::InvokeFunction(CallFunction(), interpolate_arg); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3100 case Token::kTRUNCDIV: return 0; | 3106 case Token::kTRUNCDIV: return 0; |
3101 case Token::kMOD: return 1; | 3107 case Token::kMOD: return 1; |
3102 default: UNIMPLEMENTED(); return -1; | 3108 default: UNIMPLEMENTED(); return -1; |
3103 } | 3109 } |
3104 } | 3110 } |
3105 | 3111 |
3106 | 3112 |
3107 #undef __ | 3113 #undef __ |
3108 | 3114 |
3109 } // namespace dart | 3115 } // namespace dart |
OLD | NEW |