Instruction.h 2.3 KB

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