1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ 6 #define V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ 7 8 #include "src/allocation.h" 9 #include "src/builtins/builtins.h" 10 #include "src/frames.h" 11 #include "src/interpreter/bytecodes.h" 12 #include "src/interpreter/interpreter-assembler.h" 13 #include "src/runtime/runtime.h" 14 15 namespace v8 { 16 namespace internal { 17 18 namespace compiler { 19 class Node; 20 } // namespace compiler 21 22 namespace interpreter { 23 24 // List of supported intrisics, with upper case name, lower case name and 25 // expected number of arguments (-1 denoting argument count is variable). 26 #define INTRINSICS_LIST(V) \ 27 V(Call, call, -1) \ 28 V(ClassOf, class_of, 1) \ 29 V(HasProperty, has_property, 2) \ 30 V(IsArray, is_array, 1) \ 31 V(IsJSProxy, is_js_proxy, 1) \ 32 V(IsJSReceiver, is_js_receiver, 1) \ 33 V(IsRegExp, is_regexp, 1) \ 34 V(IsSmi, is_smi, 1) \ 35 V(IsTypedArray, is_typed_array, 1) \ 36 V(NewObject, new_object, 2) \ 37 V(NumberToString, number_to_string, 1) \ 38 V(RegExpExec, reg_exp_exec, 4) \ 39 V(SubString, sub_string, 3) \ 40 V(ToString, to_string, 1) \ 41 V(ToLength, to_length, 1) \ 42 V(ToInteger, to_integer, 1) \ 43 V(ToNumber, to_number, 1) \ 44 V(ToObject, to_object, 1) \ 45 V(ValueOf, value_of, 1) 46 47 class IntrinsicsHelper { 48 public: 49 enum class IntrinsicId { 50 #define DECLARE_INTRINSIC_ID(name, lower_case, count) k##name, 51 INTRINSICS_LIST(DECLARE_INTRINSIC_ID) 52 #undef DECLARE_INTRINSIC_ID 53 kIdCount 54 }; 55 STATIC_ASSERT(static_cast<uint32_t>(IntrinsicId::kIdCount) <= kMaxUInt8); 56 57 explicit IntrinsicsHelper(InterpreterAssembler* assembler); 58 59 compiler::Node* InvokeIntrinsic(compiler::Node* function_id, 60 compiler::Node* context, 61 compiler::Node* first_arg_reg, 62 compiler::Node* arg_count); 63 64 static bool IsSupported(Runtime::FunctionId function_id); 65 static IntrinsicId FromRuntimeId(Runtime::FunctionId function_id); 66 static Runtime::FunctionId ToRuntimeId(IntrinsicId intrinsic_id); 67 68 private: 69 enum InstanceTypeCompareMode { 70 kInstanceTypeEqual, 71 kInstanceTypeGreaterThanOrEqual 72 }; 73 74 compiler::Node* IsInstanceType(compiler::Node* input, int type); 75 compiler::Node* CompareInstanceType(compiler::Node* map, int type, 76 InstanceTypeCompareMode mode); 77 compiler::Node* IntrinsicAsStubCall(compiler::Node* input, 78 compiler::Node* context, 79 Callable const& callable); 80 void AbortIfArgCountMismatch(int expected, compiler::Node* actual); 81 82 #define DECLARE_INTRINSIC_HELPER(name, lower_case, count) \ 83 compiler::Node* name(compiler::Node* input, compiler::Node* arg_count, \ 84 compiler::Node* context); 85 INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER) 86 #undef DECLARE_INTRINSIC_HELPER 87 88 Isolate* isolate() { return isolate_; } 89 Zone* zone() { return zone_; } 90 91 Isolate* isolate_; 92 Zone* zone_; 93 InterpreterAssembler* assembler_; 94 95 DISALLOW_COPY_AND_ASSIGN(IntrinsicsHelper); 96 }; 97 98 } // namespace interpreter 99 } // namespace internal 100 } // namespace v8 101 102 #endif 103