Instruction.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibJS/Forward.h>
  9. #define ENUMERATE_BYTECODE_OPS(O) \
  10. O(Load) \
  11. O(LoadImmediate) \
  12. O(Store) \
  13. O(Add) \
  14. O(Sub) \
  15. O(Mul) \
  16. O(Div) \
  17. O(Mod) \
  18. O(Exp) \
  19. O(GreaterThan) \
  20. O(GreaterThanEquals) \
  21. O(LessThan) \
  22. O(LessThanEquals) \
  23. O(AbstractInequals) \
  24. O(AbstractEquals) \
  25. O(TypedInequals) \
  26. O(TypedEquals) \
  27. O(NewBigInt) \
  28. O(NewArray) \
  29. O(NewString) \
  30. O(NewObject) \
  31. O(GetVariable) \
  32. O(SetVariable) \
  33. O(PutById) \
  34. O(GetById) \
  35. O(PutByValue) \
  36. O(GetByValue) \
  37. O(Jump) \
  38. O(JumpConditional) \
  39. O(JumpNullish) \
  40. O(Call) \
  41. O(NewFunction) \
  42. O(Return) \
  43. O(BitwiseAnd) \
  44. O(BitwiseOr) \
  45. O(BitwiseXor) \
  46. O(BitwiseNot) \
  47. O(Not) \
  48. O(UnaryPlus) \
  49. O(UnaryMinus) \
  50. O(Typeof) \
  51. O(LeftShift) \
  52. O(RightShift) \
  53. O(UnsignedRightShift) \
  54. O(In) \
  55. O(InstanceOf) \
  56. O(ConcatString) \
  57. O(Increment) \
  58. O(Decrement) \
  59. O(Throw) \
  60. O(PushLexicalEnvironment) \
  61. O(EnterUnwindContext) \
  62. O(LeaveUnwindContext) \
  63. O(ContinuePendingUnwind) \
  64. O(Yield)
  65. namespace JS::Bytecode {
  66. class Instruction {
  67. public:
  68. constexpr static bool IsTerminator = false;
  69. enum class Type {
  70. #define __BYTECODE_OP(op) \
  71. op,
  72. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  73. #undef __BYTECODE_OP
  74. };
  75. Type type() const { return m_type; }
  76. size_t length() const;
  77. String to_string(Bytecode::Executable const&) const;
  78. void execute(Bytecode::Interpreter&) const;
  79. static void destroy(Instruction&);
  80. protected:
  81. explicit Instruction(Type type)
  82. : m_type(type)
  83. {
  84. }
  85. private:
  86. Type m_type {};
  87. };
  88. }