Instruction.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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(LoadArgument) \
  62. O(EnterUnwindContext) \
  63. O(LeaveUnwindContext) \
  64. O(ContinuePendingUnwind) \
  65. O(Yield)
  66. namespace JS::Bytecode {
  67. class Instruction {
  68. public:
  69. constexpr static bool IsTerminator = false;
  70. enum class Type {
  71. #define __BYTECODE_OP(op) \
  72. op,
  73. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  74. #undef __BYTECODE_OP
  75. };
  76. Type type() const { return m_type; }
  77. size_t length() const;
  78. String to_string(Bytecode::Executable const&) const;
  79. void execute(Bytecode::Interpreter&) const;
  80. static void destroy(Instruction&);
  81. protected:
  82. explicit Instruction(Type type)
  83. : m_type(type)
  84. {
  85. }
  86. private:
  87. Type m_type {};
  88. };
  89. }