5 #include "src/interpreter/bytecodes.h" 9 #include "src/base/bits.h" 10 #include "src/interpreter/bytecode-traits.h" 14 namespace interpreter {
17 const OperandType*
const Bytecodes::kOperandTypes[] = {
18 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kOperandTypes, 23 const OperandTypeInfo*
const Bytecodes::kOperandTypeInfos[] = {
24 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kOperandTypeInfos, 29 const int Bytecodes::kOperandCount[] = {
30 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kOperandCount, 35 const AccumulatorUse Bytecodes::kAccumulatorUse[] = {
36 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kAccumulatorUse, 41 const int Bytecodes::kBytecodeSizes[3][kBytecodeCount] = {
43 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kSingleScaleSize, 47 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kDoubleScaleSize, 51 #define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kQuadrupleScaleSize, 57 const OperandSize*
const Bytecodes::kOperandSizes[3][kBytecodeCount] = {
59 #define ENTRY(Name, ...) \ 60 BytecodeTraits<__VA_ARGS__>::kSingleScaleOperandSizes, 64 #define ENTRY(Name, ...) \ 65 BytecodeTraits<__VA_ARGS__>::kDoubleScaleOperandSizes, 69 #define ENTRY(Name, ...) \ 70 BytecodeTraits<__VA_ARGS__>::kQuadrupleScaleOperandSizes, 77 Bytecodes::kOperandKindSizes[3][BytecodeOperands::kOperandTypeCount] = {
79 #define ENTRY(Name, ...) \ 80 OperandScaler<OperandType::k##Name, OperandScale::kSingle>::kOperandSize, 81 OPERAND_TYPE_LIST(ENTRY)
84 #define ENTRY(Name, ...) \ 85 OperandScaler<OperandType::k##Name, OperandScale::kDouble>::kOperandSize, 86 OPERAND_TYPE_LIST(ENTRY)
89 #define ENTRY(Name, ...) \ 90 OperandScaler<OperandType::k##Name, OperandScale::kQuadruple>::kOperandSize, 91 OPERAND_TYPE_LIST(ENTRY)
98 const char* Bytecodes::ToString(Bytecode bytecode) {
100 #define CASE(Name, ...) \ 101 case Bytecode::k##Name: \ 110 std::string Bytecodes::ToString(Bytecode bytecode, OperandScale operand_scale,
111 const char* separator) {
112 std::string value(ToString(bytecode));
113 if (operand_scale > OperandScale::kSingle) {
114 Bytecode prefix_bytecode = OperandScaleToPrefixBytecode(operand_scale);
115 std::string suffix = ToString(prefix_bytecode);
116 return value.append(separator).append(suffix);
123 Bytecode Bytecodes::GetDebugBreak(Bytecode bytecode) {
124 DCHECK(!IsDebugBreak(bytecode));
125 if (bytecode == Bytecode::kWide) {
126 return Bytecode::kDebugBreakWide;
128 if (bytecode == Bytecode::kExtraWide) {
129 return Bytecode::kDebugBreakExtraWide;
131 int bytecode_size = Size(bytecode, OperandScale::kSingle);
132 #define RETURN_IF_DEBUG_BREAK_SIZE_MATCHES(Name) \ 133 if (bytecode_size == Size(Bytecode::k##Name, OperandScale::kSingle)) { \ 134 return Bytecode::k##Name; \ 136 DEBUG_BREAK_PLAIN_BYTECODE_LIST(RETURN_IF_DEBUG_BREAK_SIZE_MATCHES)
137 #undef RETURN_IF_DEBUG_BREAK_SIZE_MATCHES 142 int Bytecodes::GetOperandOffset(Bytecode bytecode,
int i,
143 OperandScale operand_scale) {
144 DCHECK_LT(
i, Bytecodes::NumberOfOperands(bytecode));
147 for (
int operand_index = 0; operand_index <
i; ++operand_index) {
148 OperandSize operand_size =
149 GetOperandSize(bytecode, operand_index, operand_scale);
150 offset +=
static_cast<int>(operand_size);
156 Bytecode Bytecodes::GetJumpWithoutToBoolean(Bytecode bytecode) {
158 case Bytecode::kJumpIfToBooleanTrue:
159 return Bytecode::kJumpIfTrue;
160 case Bytecode::kJumpIfToBooleanFalse:
161 return Bytecode::kJumpIfFalse;
162 case Bytecode::kJumpIfToBooleanTrueConstant:
163 return Bytecode::kJumpIfTrueConstant;
164 case Bytecode::kJumpIfToBooleanFalseConstant:
165 return Bytecode::kJumpIfFalseConstant;
173 bool Bytecodes::IsDebugBreak(Bytecode bytecode) {
175 #define CASE(Name, ...) case Bytecode::k##Name: 176 DEBUG_BREAK_BYTECODE_LIST(CASE);
186 bool Bytecodes::IsRegisterOperandType(OperandType operand_type) {
187 switch (operand_type) {
188 #define CASE(Name, _) \ 189 case OperandType::k##Name: \ 191 REGISTER_OPERAND_TYPE_LIST(CASE)
193 #define CASE(Name, _) \ 194 case OperandType::k##Name: \ 196 NON_REGISTER_OPERAND_TYPE_LIST(CASE)
203 bool Bytecodes::IsRegisterListOperandType(OperandType operand_type) {
204 switch (operand_type) {
205 case OperandType::kRegList:
206 case OperandType::kRegOutList:
213 bool Bytecodes::MakesCallAlongCriticalPath(Bytecode bytecode) {
214 if (IsCallOrConstruct(bytecode) || IsCallRuntime(bytecode))
return true;
216 case Bytecode::kCreateWithContext:
217 case Bytecode::kCreateBlockContext:
218 case Bytecode::kCreateCatchContext:
219 case Bytecode::kCreateRegExpLiteral:
227 bool Bytecodes::IsRegisterInputOperandType(OperandType operand_type) {
228 switch (operand_type) {
229 #define CASE(Name, _) \ 230 case OperandType::k##Name: \ 232 REGISTER_INPUT_OPERAND_TYPE_LIST(CASE)
234 #define CASE(Name, _) \ 235 case OperandType::k##Name: \ 237 NON_REGISTER_OPERAND_TYPE_LIST(CASE)
238 REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE)
245 bool Bytecodes::IsRegisterOutputOperandType(OperandType operand_type) {
246 switch (operand_type) {
247 #define CASE(Name, _) \ 248 case OperandType::k##Name: \ 250 REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE)
252 #define CASE(Name, _) \ 253 case OperandType::k##Name: \ 255 NON_REGISTER_OPERAND_TYPE_LIST(CASE)
256 REGISTER_INPUT_OPERAND_TYPE_LIST(CASE)
263 bool Bytecodes::IsStarLookahead(Bytecode bytecode, OperandScale operand_scale) {
264 if (operand_scale == OperandScale::kSingle) {
266 case Bytecode::kLdaZero:
267 case Bytecode::kLdaSmi:
268 case Bytecode::kLdaNull:
269 case Bytecode::kLdaTheHole:
270 case Bytecode::kLdaConstant:
271 case Bytecode::kLdaUndefined:
272 case Bytecode::kLdaGlobal:
273 case Bytecode::kLdaNamedProperty:
274 case Bytecode::kLdaKeyedProperty:
275 case Bytecode::kLdaContextSlot:
276 case Bytecode::kLdaCurrentContextSlot:
280 case Bytecode::kAddSmi:
281 case Bytecode::kSubSmi:
284 case Bytecode::kTypeOf:
285 case Bytecode::kCallAnyReceiver:
286 case Bytecode::kCallNoFeedback:
287 case Bytecode::kCallProperty:
288 case Bytecode::kCallProperty0:
289 case Bytecode::kCallProperty1:
290 case Bytecode::kCallProperty2:
291 case Bytecode::kCallUndefinedReceiver:
292 case Bytecode::kCallUndefinedReceiver0:
293 case Bytecode::kCallUndefinedReceiver1:
294 case Bytecode::kCallUndefinedReceiver2:
295 case Bytecode::kConstruct:
296 case Bytecode::kConstructWithSpread:
306 bool Bytecodes::IsBytecodeWithScalableOperands(Bytecode bytecode) {
307 for (
int i = 0;
i < NumberOfOperands(bytecode);
i++) {
308 if (OperandIsScalable(bytecode,
i))
return true;
314 bool Bytecodes::IsUnsignedOperandType(OperandType operand_type) {
315 switch (operand_type) {
316 #define CASE(Name, _) \ 317 case OperandType::k##Name: \ 318 return OperandTraits<OperandType::k##Name>::TypeInfoTraits::kIsUnsigned; 319 OPERAND_TYPE_LIST(CASE)
326 bool Bytecodes::BytecodeHasHandler(Bytecode bytecode,
327 OperandScale operand_scale) {
328 return operand_scale == OperandScale::kSingle ||
329 Bytecodes::IsBytecodeWithScalableOperands(bytecode);
332 std::ostream& operator<<(std::ostream& os,
const Bytecode& bytecode) {
333 return os << Bytecodes::ToString(bytecode);