| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
| 9 #include "src/compiler/machine-operator.h" |
| 9 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| 10 #include "src/compiler/node-properties-inl.h" | 11 #include "src/compiler/node-properties-inl.h" |
| 11 #include "src/full-codegen.h" | 12 #include "src/full-codegen.h" |
| 12 #include "src/parser.h" | 13 #include "src/parser.h" |
| 13 #include "src/scopes.h" | 14 #include "src/scopes.h" |
| 14 | 15 |
| 15 namespace v8 { | 16 namespace v8 { |
| 16 namespace internal { | 17 namespace internal { |
| 17 namespace compiler { | 18 namespace compiler { |
| 18 | 19 |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 environment()->Push(value); | 731 environment()->Push(value); |
| 731 { | 732 { |
| 732 // Test if FILTER_KEY needs to be called. | 733 // Test if FILTER_KEY needs to be called. |
| 733 IfBuilder test_should_filter(this); | 734 IfBuilder test_should_filter(this); |
| 734 Node* should_filter_cond = | 735 Node* should_filter_cond = |
| 735 NewNode(javascript()->StrictEqual(), should_filter, | 736 NewNode(javascript()->StrictEqual(), should_filter, |
| 736 jsgraph()->TrueConstant()); | 737 jsgraph()->TrueConstant()); |
| 737 test_should_filter.If(should_filter_cond); | 738 test_should_filter.If(should_filter_cond); |
| 738 test_should_filter.Then(); | 739 test_should_filter.Then(); |
| 739 value = environment()->Pop(); | 740 value = environment()->Pop(); |
| 740 // TODO(dcarney): Better load from function context. | 741 Node* builtins = BuildLoadBuiltinsObject(); |
| 741 // See comment in BuildLoadBuiltinsObject. | 742 Node* function = BuildLoadObjectField( |
| 742 Handle<JSFunction> function(JSFunction::cast( | 743 builtins, |
| 743 info()->context()->builtins()->javascript_builtin( | 744 JSBuiltinsObject::OffsetOfFunctionWithId(Builtins::FILTER_KEY)); |
| 744 Builtins::FILTER_KEY))); | |
| 745 // Callee. | 745 // Callee. |
| 746 environment()->Push(jsgraph()->HeapConstant(function)); | 746 environment()->Push(function); |
| 747 // Receiver. | 747 // Receiver. |
| 748 environment()->Push(obj); | 748 environment()->Push(obj); |
| 749 // Args. | 749 // Args. |
| 750 environment()->Push(value); | 750 environment()->Push(value); |
| 751 // result is either the string key or Smi(0) indicating the property | 751 // result is either the string key or Smi(0) indicating the property |
| 752 // is gone. | 752 // is gone. |
| 753 Node* res = ProcessArguments( | 753 Node* res = ProcessArguments( |
| 754 javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 3); | 754 javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 3); |
| 755 // TODO(jarin): provide real bailout id. | 755 // TODO(jarin): provide real bailout id. |
| 756 BuildLazyBailout(res, BailoutId::None()); | 756 BuildLazyBailout(res, BailoutId::None()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 868 } |
| 869 | 869 |
| 870 | 870 |
| 871 void AstGraphBuilder::VisitLiteral(Literal* expr) { | 871 void AstGraphBuilder::VisitLiteral(Literal* expr) { |
| 872 Node* value = jsgraph()->Constant(expr->value()); | 872 Node* value = jsgraph()->Constant(expr->value()); |
| 873 ast_context()->ProduceValue(value); | 873 ast_context()->ProduceValue(value); |
| 874 } | 874 } |
| 875 | 875 |
| 876 | 876 |
| 877 void AstGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { | 877 void AstGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 878 Handle<JSFunction> closure = info()->closure(); | 878 Node* closure = GetFunctionClosure(); |
| 879 | 879 |
| 880 // Create node to materialize a regular expression literal. | 880 // Create node to materialize a regular expression literal. |
| 881 Node* literals_array = jsgraph()->Constant(handle(closure->literals())); | 881 Node* literals_array = |
| 882 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset); |
| 882 Node* literal_index = jsgraph()->Constant(expr->literal_index()); | 883 Node* literal_index = jsgraph()->Constant(expr->literal_index()); |
| 883 Node* pattern = jsgraph()->Constant(expr->pattern()); | 884 Node* pattern = jsgraph()->Constant(expr->pattern()); |
| 884 Node* flags = jsgraph()->Constant(expr->flags()); | 885 Node* flags = jsgraph()->Constant(expr->flags()); |
| 885 Operator* op = javascript()->Runtime(Runtime::kMaterializeRegExpLiteral, 4); | 886 Operator* op = javascript()->Runtime(Runtime::kMaterializeRegExpLiteral, 4); |
| 886 Node* literal = NewNode(op, literals_array, literal_index, pattern, flags); | 887 Node* literal = NewNode(op, literals_array, literal_index, pattern, flags); |
| 887 ast_context()->ProduceValue(literal); | 888 ast_context()->ProduceValue(literal); |
| 888 } | 889 } |
| 889 | 890 |
| 890 | 891 |
| 891 void AstGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { | 892 void AstGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { |
| 892 Handle<JSFunction> closure = info()->closure(); | 893 Node* closure = GetFunctionClosure(); |
| 893 | 894 |
| 894 // Create node to deep-copy the literal boilerplate. | 895 // Create node to deep-copy the literal boilerplate. |
| 895 expr->BuildConstantProperties(isolate()); | 896 expr->BuildConstantProperties(isolate()); |
| 896 Node* literals_array = jsgraph()->Constant(handle(closure->literals())); | 897 Node* literals_array = |
| 898 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset); |
| 897 Node* literal_index = jsgraph()->Constant(expr->literal_index()); | 899 Node* literal_index = jsgraph()->Constant(expr->literal_index()); |
| 898 Node* constants = jsgraph()->Constant(expr->constant_properties()); | 900 Node* constants = jsgraph()->Constant(expr->constant_properties()); |
| 899 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); | 901 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); |
| 900 Operator* op = javascript()->Runtime(Runtime::kCreateObjectLiteral, 4); | 902 Operator* op = javascript()->Runtime(Runtime::kCreateObjectLiteral, 4); |
| 901 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); | 903 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); |
| 902 | 904 |
| 903 // The object is expected on the operand stack during computation of the | 905 // The object is expected on the operand stack during computation of the |
| 904 // property values and is the value of the entire expression. | 906 // property values and is the value of the entire expression. |
| 905 environment()->Push(literal); | 907 environment()->Push(literal); |
| 906 | 908 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 if (expr->has_function()) { | 993 if (expr->has_function()) { |
| 992 Operator* op = javascript()->Runtime(Runtime::kToFastProperties, 1); | 994 Operator* op = javascript()->Runtime(Runtime::kToFastProperties, 1); |
| 993 NewNode(op, literal); | 995 NewNode(op, literal); |
| 994 } | 996 } |
| 995 | 997 |
| 996 ast_context()->ProduceValue(environment()->Pop()); | 998 ast_context()->ProduceValue(environment()->Pop()); |
| 997 } | 999 } |
| 998 | 1000 |
| 999 | 1001 |
| 1000 void AstGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { | 1002 void AstGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1001 Handle<JSFunction> closure = info()->closure(); | 1003 Node* closure = GetFunctionClosure(); |
| 1002 | 1004 |
| 1003 // Create node to deep-copy the literal boilerplate. | 1005 // Create node to deep-copy the literal boilerplate. |
| 1004 expr->BuildConstantElements(isolate()); | 1006 expr->BuildConstantElements(isolate()); |
| 1005 Node* literals_array = jsgraph()->Constant(handle(closure->literals())); | 1007 Node* literals_array = |
| 1008 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset); |
| 1006 Node* literal_index = jsgraph()->Constant(expr->literal_index()); | 1009 Node* literal_index = jsgraph()->Constant(expr->literal_index()); |
| 1007 Node* constants = jsgraph()->Constant(expr->constant_elements()); | 1010 Node* constants = jsgraph()->Constant(expr->constant_elements()); |
| 1008 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); | 1011 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); |
| 1009 Operator* op = javascript()->Runtime(Runtime::kCreateArrayLiteral, 4); | 1012 Operator* op = javascript()->Runtime(Runtime::kCreateArrayLiteral, 4); |
| 1010 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); | 1013 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); |
| 1011 | 1014 |
| 1012 // The array and the literal index are both expected on the operand stack | 1015 // The array and the literal index are both expected on the operand stack |
| 1013 // during computation of the element values. | 1016 // during computation of the element values. |
| 1014 environment()->Push(literal); | 1017 environment()->Push(literal); |
| 1015 environment()->Push(literal_index); | 1018 environment()->Push(literal_index); |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 // initializations of const declarations. | 1934 // initializations of const declarations. |
| 1932 Operator* op = javascript()->Runtime(Runtime::kStoreLookupSlot, 4); | 1935 Operator* op = javascript()->Runtime(Runtime::kStoreLookupSlot, 4); |
| 1933 return NewNode(op, value, current_context(), name, strict); | 1936 return NewNode(op, value, current_context(), name, strict); |
| 1934 } | 1937 } |
| 1935 } | 1938 } |
| 1936 UNREACHABLE(); | 1939 UNREACHABLE(); |
| 1937 return NULL; | 1940 return NULL; |
| 1938 } | 1941 } |
| 1939 | 1942 |
| 1940 | 1943 |
| 1944 Node* AstGraphBuilder::BuildLoadObjectField(Node* object, int offset) { |
| 1945 // TODO(sigurds) Use simplified load here once it is ready. |
| 1946 MachineOperatorBuilder machine(zone()); |
| 1947 Node* field_load = NewNode(machine.Load(kMachAnyTagged), object, |
| 1948 jsgraph_->Int32Constant(offset - kHeapObjectTag)); |
| 1949 return field_load; |
| 1950 } |
| 1951 |
| 1952 |
| 1941 Node* AstGraphBuilder::BuildLoadBuiltinsObject() { | 1953 Node* AstGraphBuilder::BuildLoadBuiltinsObject() { |
| 1942 // TODO(mstarzinger): Better load from function context, otherwise optimized | 1954 Node* global = BuildLoadGlobalObject(); |
| 1943 // code cannot be shared across native contexts. | 1955 Node* builtins = |
| 1944 return jsgraph()->Constant(handle(info()->context()->builtins())); | 1956 BuildLoadObjectField(global, JSGlobalObject::kBuiltinsOffset); |
| 1957 return builtins; |
| 1945 } | 1958 } |
| 1946 | 1959 |
| 1947 | 1960 |
| 1948 Node* AstGraphBuilder::BuildLoadGlobalObject() { | 1961 Node* AstGraphBuilder::BuildLoadGlobalObject() { |
| 1949 #if 0 | |
| 1950 Node* context = GetFunctionContext(); | 1962 Node* context = GetFunctionContext(); |
| 1951 // TODO(mstarzinger): Use mid-level operator on FixedArray instead of the | 1963 Operator* load_op = |
| 1952 // JS-level operator that targets JSObject. | 1964 javascript()->LoadContext(0, Context::GLOBAL_OBJECT_INDEX, true); |
| 1953 Node* index = jsgraph()->Constant(Context::GLOBAL_OBJECT_INDEX); | 1965 return NewNode(load_op, context); |
| 1954 return NewNode(javascript()->LoadProperty(), context, index); | |
| 1955 #else | |
| 1956 // TODO(mstarzinger): Better load from function context, otherwise optimized | |
| 1957 // code cannot be shared across native contexts. See unused code above. | |
| 1958 return jsgraph()->Constant(handle(info()->context()->global_object())); | |
| 1959 #endif | |
| 1960 } | 1966 } |
| 1961 | 1967 |
| 1962 | 1968 |
| 1963 Node* AstGraphBuilder::BuildToBoolean(Node* value) { | 1969 Node* AstGraphBuilder::BuildToBoolean(Node* value) { |
| 1964 // TODO(mstarzinger): Possible optimization is to NOP for boolean values. | 1970 // TODO(mstarzinger): Possible optimization is to NOP for boolean values. |
| 1965 return NewNode(javascript()->ToBoolean(), value); | 1971 return NewNode(javascript()->ToBoolean(), value); |
| 1966 } | 1972 } |
| 1967 | 1973 |
| 1968 | 1974 |
| 1969 Node* AstGraphBuilder::BuildThrowReferenceError(Variable* variable) { | 1975 Node* AstGraphBuilder::BuildThrowReferenceError(Variable* variable) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2051 | 2057 |
| 2052 void AstGraphBuilder::BuildLazyBailoutWithPushedNode(Node* node, | 2058 void AstGraphBuilder::BuildLazyBailoutWithPushedNode(Node* node, |
| 2053 BailoutId ast_id) { | 2059 BailoutId ast_id) { |
| 2054 environment()->Push(node); | 2060 environment()->Push(node); |
| 2055 BuildLazyBailout(node, ast_id); | 2061 BuildLazyBailout(node, ast_id); |
| 2056 environment()->Pop(); | 2062 environment()->Pop(); |
| 2057 } | 2063 } |
| 2058 } | 2064 } |
| 2059 } | 2065 } |
| 2060 } // namespace v8::internal::compiler | 2066 } // namespace v8::internal::compiler |
| OLD | NEW |