Lines Matching full:bytecode
13 #include "src/interpreter/bytecode-operands.h"
24 // Format is V(<bytecode>, <accumulator_use>, <operands>).
257 /* and one for each operand widening prefix bytecode */ \
272 /* Illegal bytecode (terminates execution) */ \
298 enum class Bytecode : uint8_t {
304 // evaluate to the same value as the last real bytecode.
319 // The maximum number of operands a bytecode may have.
322 // Returns string representation of |bytecode|.
323 static const char* ToString(Bytecode bytecode);
325 // Returns string representation of |bytecode|.
326 static std::string ToString(Bytecode bytecode, OperandScale operand_scale);
328 // Returns byte value of bytecode.
329 static uint8_t ToByte(Bytecode bytecode) {
330 DCHECK_LE(bytecode, Bytecode::kLast);
331 return static_cast<uint8_t>(bytecode);
334 // Returns bytecode for |value|.
335 static Bytecode FromByte(uint8_t value) {
336 Bytecode bytecode = static_cast<Bytecode>(value);
337 DCHECK(bytecode <= Bytecode::kLast);
338 return bytecode;
341 // Returns the prefix bytecode representing an operand scale to be
342 // applied to a a bytecode.
343 static Bytecode OperandScaleToPrefixBytecode(OperandScale operand_scale) {
346 return Bytecode::kExtraWide;
348 return Bytecode::kWide;
351 return Bytecode::kIllegal;
355 // Returns true if the operand scale requires a prefix bytecode.
360 // Returns the scaling applied to scalable operands if bytecode is
362 static OperandScale PrefixBytecodeToOperandScale(Bytecode bytecode) {
363 switch (bytecode) {
364 case Bytecode::kExtraWide:
365 case Bytecode::kDebugBreakExtraWide:
367 case Bytecode::kWide:
368 case Bytecode::kDebugBreakWide:
376 // Returns how accumulator is used by |bytecode|.
377 static AccumulatorUse GetAccumulatorUse(Bytecode bytecode) {
378 DCHECK(bytecode <= Bytecode::kLast);
379 return kAccumulatorUse[static_cast<size_t>(bytecode)];
382 // Returns true if |bytecode| reads the accumulator.
383 static bool ReadsAccumulator(Bytecode bytecode) {
384 return (GetAccumulatorUse(bytecode) & AccumulatorUse::kRead) ==
388 // Returns true if |bytecode| writes the accumulator.
389 static bool WritesAccumulator(Bytecode bytecode) {
390 return (GetAccumulatorUse(bytecode) & AccumulatorUse::kWrite) ==
394 // Return true if |bytecode| writes the accumulator with a boolean value.
395 static bool WritesBooleanToAccumulator(Bytecode bytecode) {
396 switch (bytecode) {
397 case Bytecode::kLdaTrue:
398 case Bytecode::kLdaFalse:
399 case Bytecode::kToBooleanLogicalNot:
400 case Bytecode::kLogicalNot:
401 case Bytecode::kTestEqual:
402 case Bytecode::kTestNotEqual:
403 case Bytecode::kTestEqualStrict:
404 case Bytecode::kTestLessThan:
405 case Bytecode::kTestLessThanOrEqual:
406 case Bytecode::kTestGreaterThan:
407 case Bytecode::kTestGreaterThanOrEqual:
408 case Bytecode::kTestInstanceOf:
409 case Bytecode::kTestIn:
410 case Bytecode::kForInContinue:
417 // Return true if |bytecode| is an accumulator load without effects,
419 static CONSTEXPR bool IsAccumulatorLoadWithoutEffects(Bytecode bytecode) {
420 return bytecode == Bytecode::kLdar || bytecode == Bytecode::kLdaZero ||
421 bytecode == Bytecode::kLdaSmi || bytecode == Bytecode::kLdaNull ||
422 bytecode == Bytecode::kLdaTrue || bytecode == Bytecode::kLdaFalse ||
423 bytecode == Bytecode::kLdaUndefined ||
424 bytecode == Bytecode::kLdaTheHole ||
425 bytecode == Bytecode::kLdaConstant ||
426 bytecode == Bytecode::kLdaContextSlot ||
427 bytecode == Bytecode::kLdaCurrentContextSlot;
430 // Return true if |bytecode| is a register load without effects,
432 static CONSTEXPR bool IsRegisterLoadWithoutEffects(Bytecode bytecode) {
433 return bytecode == Bytecode::kMov || bytecode == Bytecode::kPopContext ||
434 bytecode == Bytecode::kPushContext || bytecode == Bytecode::kStar;
437 // Returns true if the bytecode is a conditional jump taking
439 static CONSTEXPR bool IsConditionalJumpImmediate(Bytecode bytecode) {
440 return bytecode == Bytecode::kJumpIfTrue ||
441 bytecode == Bytecode::kJumpIfFalse ||
442 bytecode == Bytecode::kJumpIfToBooleanTrue ||
443 bytecode == Bytecode::kJumpIfToBooleanFalse ||
444 bytecode == Bytecode::kJumpIfNotHole ||
445 bytecode == Bytecode::kJumpIfNull ||
446 bytecode == Bytecode::kJumpIfUndefined;
449 // Returns true if the bytecode is a conditional jump taking
451 static CONSTEXPR bool IsConditionalJumpConstant(Bytecode bytecode) {
452 return bytecode == Bytecode::kJumpIfTrueConstant ||
453 bytecode == Bytecode::kJumpIfFalseConstant ||
454 bytecode == Bytecode::kJumpIfToBooleanTrueConstant ||
455 bytecode == Bytecode::kJumpIfToBooleanFalseConstant ||
456 bytecode == Bytecode::kJumpIfNotHoleConstant ||
457 bytecode == Bytecode::kJumpIfNullConstant ||
458 bytecode == Bytecode::kJumpIfUndefinedConstant;
461 // Returns true if the bytecode is a conditional jump taking
463 static CONSTEXPR bool IsConditionalJump(Bytecode bytecode) {
464 return IsConditionalJumpImmediate(bytecode) ||
465 IsConditionalJumpConstant(bytecode);
468 // Returns true if the bytecode is a jump or a conditional jump taking
470 static CONSTEXPR bool IsJumpImmediate(Bytecode bytecode) {
471 return bytecode == Bytecode::kJump || bytecode == Bytecode::kJumpLoop ||
472 IsConditionalJumpImmediate(bytecode);
475 // Returns true if the bytecode is a jump or conditional jump taking a
477 static CONSTEXPR bool IsJumpConstant(Bytecode bytecode) {
478 return bytecode == Bytecode::kJumpConstant ||
479 IsConditionalJumpConstant(bytecode);
482 // Returns true if the bytecode is a jump that internally coerces the
484 static CONSTEXPR bool IsJumpIfToBoolean(Bytecode bytecode) {
485 return bytecode == Bytecode::kJumpIfToBooleanTrue ||
486 bytecode == Bytecode::kJumpIfToBooleanFalse ||
487 bytecode == Bytecode::kJumpIfToBooleanTrueConstant ||
488 bytecode == Bytecode::kJumpIfToBooleanFalseConstant;
491 // Returns true if the bytecode is a jump or conditional jump taking
493 static CONSTEXPR bool IsJump(Bytecode bytecode) {
494 return IsJumpImmediate(bytecode) || IsJumpConstant(bytecode);
497 // Returns true if the bytecode is a conditional jump, a jump, or a return.
498 static CONSTEXPR bool IsJumpOrReturn(Bytecode bytecode) {
499 return bytecode == Bytecode::kReturn || IsJump(bytecode);
502 // Return true if |bytecode| is a jump without effects,
505 static CONSTEXPR bool IsJumpWithoutEffects(Bytecode bytecode) {
506 return IsJump(bytecode) && !IsJumpIfToBoolean(bytecode);
509 // Returns true if |bytecode| has no effects. These bytecodes only manipulate
511 static CONSTEXPR bool IsWithoutExternalSideEffects(Bytecode bytecode) {
512 return (IsAccumulatorLoadWithoutEffects(bytecode) ||
513 IsRegisterLoadWithoutEffects(bytecode) ||
514 bytecode == Bytecode::kNop || IsJumpWithoutEffects(bytecode));
517 // Returns true if the bytecode is Ldar or Star.
518 static CONSTEXPR bool IsLdarOrStar(Bytecode bytecode) {
519 return bytecode == Bytecode::kLdar || bytecode == Bytecode::kStar;
522 // Returns true if |bytecode| puts a name in the accumulator.
523 static CONSTEXPR bool PutsNameInAccumulator(Bytecode bytecode) {
524 return bytecode == Bytecode::kTypeOf;
527 // Returns true if the bytecode is a call or a constructor call.
528 static CONSTEXPR bool IsCallOrNew(Bytecode bytecode) {
529 return bytecode == Bytecode::kCall || bytecode == Bytecode::kCallProperty ||
530 bytecode == Bytecode::kTailCall || bytecode == Bytecode::kNew;
533 // Returns true if the bytecode is a call to the runtime.
534 static CONSTEXPR bool IsCallRuntime(Bytecode bytecode) {
535 return bytecode == Bytecode::kCallRuntime ||
536 bytecode == Bytecode::kCallRuntimeForPair ||
537 bytecode == Bytecode::kInvokeIntrinsic;
540 // Returns true if the bytecode is a scaling prefix bytecode.
541 static CONSTEXPR bool IsPrefixScalingBytecode(Bytecode bytecode) {
542 return bytecode == Bytecode::kExtraWide || bytecode == Bytecode::kWide ||
543 bytecode == Bytecode::kDebugBreakExtraWide ||
544 bytecode == Bytecode::kDebugBreakWide;
547 // Returns the number of values which |bytecode| returns.
548 static CONSTEXPR size_t ReturnCount(Bytecode bytecode) {
549 return bytecode == Bytecode::kReturn ? 1 : 0;
552 // Returns the number of operands expected by |bytecode|.
553 static int NumberOfOperands(Bytecode bytecode) {
554 DCHECK(bytecode <= Bytecode::kLast);
555 return kOperandCount[static_cast<size_t>(bytecode)];
558 // Returns the i-th operand of |bytecode|.
559 static OperandType GetOperandType(Bytecode bytecode, int i) {
560 DCHECK_LE(bytecode, Bytecode::kLast);
561 DCHECK_LT(i, NumberOfOperands(bytecode));
563 return GetOperandTypes(bytecode)[i];
568 static const OperandType* GetOperandTypes(Bytecode bytecode) {
569 DCHECK(bytecode <= Bytecode::kLast);
570 return kOperandTypes[static_cast<size_t>(bytecode)];
573 static bool OperandIsScalableSignedByte(Bytecode bytecode,
575 DCHECK(bytecode <= Bytecode::kLast);
576 return kOperandTypeInfos[static_cast<size_t>(bytecode)][operand_index] ==
580 static bool OperandIsScalableUnsignedByte(Bytecode bytecode,
582 DCHECK(bytecode <= Bytecode::kLast);
583 return kOperandTypeInfos[static_cast<size_t>(bytecode)][operand_index] ==
587 static bool OperandIsScalable(Bytecode bytecode, int operand_index) {
588 return OperandIsScalableSignedByte(bytecode, operand_index) ||
589 OperandIsScalableUnsignedByte(bytecode, operand_index);
592 // Returns true if the bytecode has wider operand forms.
593 static bool IsBytecodeWithScalableOperands(Bytecode bytecode);
595 // Returns the size of the i-th operand of |bytecode|.
596 static OperandSize GetOperandSize(Bytecode bytecode, int i,
598 CHECK_LT(i, NumberOfOperands(bytecode));
599 return GetOperandSizes(bytecode, operand_scale)[i];
602 // Returns the operand sizes of |bytecode| with scale |operand_scale|.
603 static const OperandSize* GetOperandSizes(Bytecode bytecode,
605 DCHECK(bytecode <= Bytecode::kLast);
611 return kOperandSizes[static_cast<size_t>(bytecode)][scale_index];
614 // Returns the offset of the i-th operand of |bytecode| relative to the start
615 // of the bytecode.
616 static int GetOperandOffset(Bytecode bytecode, int i,
619 // Returns the size of the bytecode including its operands for the
621 static int Size(Bytecode bytecode, OperandScale operand_scale) {
622 DCHECK(bytecode <= Bytecode::kLast);
626 return kBytecodeSizes[static_cast<size_t>(bytecode)][scale_index];
629 // Returns a debug break bytecode to replace |bytecode|.
630 static Bytecode GetDebugBreak(Bytecode bytecode);
632 // Returns the equivalent jump bytecode without the accumulator coercion.
633 static Bytecode GetJumpWithoutToBoolean(Bytecode bytecode);
635 // Returns true if the bytecode is a debug break.
636 static bool IsDebugBreak(Bytecode bytecode);
647 // Returns true if the handler for |bytecode| should look ahead and inline a
648 // dispatch to a Star bytecode.
649 static bool IsStarLookahead(Bytecode bytecode, OperandScale operand_scale);
683 // Returns true if a handler is generated for a bytecode at a given
687 static bool BytecodeHasHandler(Bytecode bytecode, OperandScale operand_scale);
738 const Bytecode& bytecode);