Instruction.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(Jump) \
  36. O(JumpConditional) \
  37. O(JumpNullish) \
  38. O(Call) \
  39. O(NewFunction) \
  40. O(Return) \
  41. O(BitwiseAnd) \
  42. O(BitwiseOr) \
  43. O(BitwiseXor) \
  44. O(BitwiseNot) \
  45. O(Not) \
  46. O(UnaryPlus) \
  47. O(UnaryMinus) \
  48. O(Typeof) \
  49. O(LeftShift) \
  50. O(RightShift) \
  51. O(UnsignedRightShift) \
  52. O(In) \
  53. O(InstanceOf) \
  54. O(ConcatString) \
  55. O(Increment) \
  56. O(Decrement) \
  57. O(Throw) \
  58. O(PushLexicalEnvironment) \
  59. O(EnterUnwindContext) \
  60. O(LeaveUnwindContext) \
  61. O(ContinuePendingUnwind)
  62. namespace JS::Bytecode {
  63. class Instruction {
  64. public:
  65. constexpr static bool IsTerminator = false;
  66. enum class Type {
  67. #define __BYTECODE_OP(op) \
  68. op,
  69. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  70. #undef __BYTECODE_OP
  71. };
  72. Type type() const { return m_type; }
  73. size_t length() const;
  74. String to_string(Bytecode::Executable const&) const;
  75. void execute(Bytecode::Interpreter&) const;
  76. static void destroy(Instruction&);
  77. protected:
  78. explicit Instruction(Type type)
  79. : m_type(type)
  80. {
  81. }
  82. private:
  83. Type m_type {};
  84. };
  85. }