• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h"
7 #include "src/isolate.h"
8 #include "src/macro-assembler.h"
9 #include "src/objects-inl.h"
10 
11 namespace v8 {
12 namespace internal {
13 
CallFunction(ConvertReceiverMode mode,TailCallMode tail_call_mode)14 Handle<Code> Builtins::CallFunction(ConvertReceiverMode mode,
15                                     TailCallMode tail_call_mode) {
16   switch (tail_call_mode) {
17     case TailCallMode::kDisallow:
18       switch (mode) {
19         case ConvertReceiverMode::kNullOrUndefined:
20           return CallFunction_ReceiverIsNullOrUndefined();
21         case ConvertReceiverMode::kNotNullOrUndefined:
22           return CallFunction_ReceiverIsNotNullOrUndefined();
23         case ConvertReceiverMode::kAny:
24           return CallFunction_ReceiverIsAny();
25       }
26       break;
27     case TailCallMode::kAllow:
28       switch (mode) {
29         case ConvertReceiverMode::kNullOrUndefined:
30           return TailCallFunction_ReceiverIsNullOrUndefined();
31         case ConvertReceiverMode::kNotNullOrUndefined:
32           return TailCallFunction_ReceiverIsNotNullOrUndefined();
33         case ConvertReceiverMode::kAny:
34           return TailCallFunction_ReceiverIsAny();
35       }
36       break;
37   }
38   UNREACHABLE();
39   return Handle<Code>::null();
40 }
41 
Call(ConvertReceiverMode mode,TailCallMode tail_call_mode)42 Handle<Code> Builtins::Call(ConvertReceiverMode mode,
43                             TailCallMode tail_call_mode) {
44   switch (tail_call_mode) {
45     case TailCallMode::kDisallow:
46       switch (mode) {
47         case ConvertReceiverMode::kNullOrUndefined:
48           return Call_ReceiverIsNullOrUndefined();
49         case ConvertReceiverMode::kNotNullOrUndefined:
50           return Call_ReceiverIsNotNullOrUndefined();
51         case ConvertReceiverMode::kAny:
52           return Call_ReceiverIsAny();
53       }
54       break;
55     case TailCallMode::kAllow:
56       switch (mode) {
57         case ConvertReceiverMode::kNullOrUndefined:
58           return TailCall_ReceiverIsNullOrUndefined();
59         case ConvertReceiverMode::kNotNullOrUndefined:
60           return TailCall_ReceiverIsNotNullOrUndefined();
61         case ConvertReceiverMode::kAny:
62           return TailCall_ReceiverIsAny();
63       }
64       break;
65   }
66   UNREACHABLE();
67   return Handle<Code>::null();
68 }
69 
CallBoundFunction(TailCallMode tail_call_mode)70 Handle<Code> Builtins::CallBoundFunction(TailCallMode tail_call_mode) {
71   switch (tail_call_mode) {
72     case TailCallMode::kDisallow:
73       return CallBoundFunction();
74     case TailCallMode::kAllow:
75       return TailCallBoundFunction();
76   }
77   UNREACHABLE();
78   return Handle<Code>::null();
79 }
80 
Generate_CallFunction_ReceiverIsNullOrUndefined(MacroAssembler * masm)81 void Builtins::Generate_CallFunction_ReceiverIsNullOrUndefined(
82     MacroAssembler* masm) {
83   Generate_CallFunction(masm, ConvertReceiverMode::kNullOrUndefined,
84                         TailCallMode::kDisallow);
85 }
86 
Generate_CallFunction_ReceiverIsNotNullOrUndefined(MacroAssembler * masm)87 void Builtins::Generate_CallFunction_ReceiverIsNotNullOrUndefined(
88     MacroAssembler* masm) {
89   Generate_CallFunction(masm, ConvertReceiverMode::kNotNullOrUndefined,
90                         TailCallMode::kDisallow);
91 }
92 
Generate_CallFunction_ReceiverIsAny(MacroAssembler * masm)93 void Builtins::Generate_CallFunction_ReceiverIsAny(MacroAssembler* masm) {
94   Generate_CallFunction(masm, ConvertReceiverMode::kAny,
95                         TailCallMode::kDisallow);
96 }
97 
Generate_TailCallFunction_ReceiverIsNullOrUndefined(MacroAssembler * masm)98 void Builtins::Generate_TailCallFunction_ReceiverIsNullOrUndefined(
99     MacroAssembler* masm) {
100   Generate_CallFunction(masm, ConvertReceiverMode::kNullOrUndefined,
101                         TailCallMode::kAllow);
102 }
103 
Generate_TailCallFunction_ReceiverIsNotNullOrUndefined(MacroAssembler * masm)104 void Builtins::Generate_TailCallFunction_ReceiverIsNotNullOrUndefined(
105     MacroAssembler* masm) {
106   Generate_CallFunction(masm, ConvertReceiverMode::kNotNullOrUndefined,
107                         TailCallMode::kAllow);
108 }
109 
Generate_TailCallFunction_ReceiverIsAny(MacroAssembler * masm)110 void Builtins::Generate_TailCallFunction_ReceiverIsAny(MacroAssembler* masm) {
111   Generate_CallFunction(masm, ConvertReceiverMode::kAny, TailCallMode::kAllow);
112 }
113 
Generate_CallBoundFunction(MacroAssembler * masm)114 void Builtins::Generate_CallBoundFunction(MacroAssembler* masm) {
115   Generate_CallBoundFunctionImpl(masm, TailCallMode::kDisallow);
116 }
117 
Generate_TailCallBoundFunction(MacroAssembler * masm)118 void Builtins::Generate_TailCallBoundFunction(MacroAssembler* masm) {
119   Generate_CallBoundFunctionImpl(masm, TailCallMode::kAllow);
120 }
121 
Generate_Call_ReceiverIsNullOrUndefined(MacroAssembler * masm)122 void Builtins::Generate_Call_ReceiverIsNullOrUndefined(MacroAssembler* masm) {
123   Generate_Call(masm, ConvertReceiverMode::kNullOrUndefined,
124                 TailCallMode::kDisallow);
125 }
126 
Generate_Call_ReceiverIsNotNullOrUndefined(MacroAssembler * masm)127 void Builtins::Generate_Call_ReceiverIsNotNullOrUndefined(
128     MacroAssembler* masm) {
129   Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
130                 TailCallMode::kDisallow);
131 }
132 
Generate_Call_ReceiverIsAny(MacroAssembler * masm)133 void Builtins::Generate_Call_ReceiverIsAny(MacroAssembler* masm) {
134   Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kDisallow);
135 }
136 
Generate_TailCall_ReceiverIsNullOrUndefined(MacroAssembler * masm)137 void Builtins::Generate_TailCall_ReceiverIsNullOrUndefined(
138     MacroAssembler* masm) {
139   Generate_Call(masm, ConvertReceiverMode::kNullOrUndefined,
140                 TailCallMode::kAllow);
141 }
142 
Generate_TailCall_ReceiverIsNotNullOrUndefined(MacroAssembler * masm)143 void Builtins::Generate_TailCall_ReceiverIsNotNullOrUndefined(
144     MacroAssembler* masm) {
145   Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
146                 TailCallMode::kAllow);
147 }
148 
Generate_TailCall_ReceiverIsAny(MacroAssembler * masm)149 void Builtins::Generate_TailCall_ReceiverIsAny(MacroAssembler* masm) {
150   Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kAllow);
151 }
152 
Generate_CallForwardVarargs(MacroAssembler * masm)153 void Builtins::Generate_CallForwardVarargs(MacroAssembler* masm) {
154   Generate_CallForwardVarargs(masm, masm->isolate()->builtins()->Call());
155 }
156 
Generate_CallFunctionForwardVarargs(MacroAssembler * masm)157 void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) {
158   Generate_CallForwardVarargs(masm,
159                               masm->isolate()->builtins()->CallFunction());
160 }
161 
162 }  // namespace internal
163 }  // namespace v8
164