Instruction.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(EnterScope) \
  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. namespace JS::Bytecode {
  59. class Instruction {
  60. public:
  61. constexpr static bool IsTerminator = false;
  62. enum class Type {
  63. #define __BYTECODE_OP(op) \
  64. op,
  65. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  66. #undef __BYTECODE_OP
  67. };
  68. Type type() const { return m_type; }
  69. size_t length() const;
  70. String to_string(Bytecode::Executable const&) const;
  71. void execute(Bytecode::Interpreter&) const;
  72. static void destroy(Instruction&);
  73. protected:
  74. explicit Instruction(Type type)
  75. : m_type(type)
  76. {
  77. }
  78. private:
  79. Type m_type {};
  80. };
  81. }