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