Instruction.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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(Add) \
  12. O(Sub) \
  13. O(Mul) \
  14. O(Div) \
  15. O(Mod) \
  16. O(Exp) \
  17. O(GreaterThan) \
  18. O(GreaterThanEquals) \
  19. O(LessThan) \
  20. O(LessThanEquals) \
  21. O(AbstractInequals) \
  22. O(AbstractEquals) \
  23. O(TypedInequals) \
  24. O(TypedEquals) \
  25. O(NewString) \
  26. O(NewObject) \
  27. O(GetVariable) \
  28. O(SetVariable) \
  29. O(PutById) \
  30. O(GetById) \
  31. O(Jump) \
  32. O(JumpIfFalse) \
  33. O(JumpIfTrue) \
  34. O(Call) \
  35. O(EnterScope) \
  36. O(Return) \
  37. O(BitwiseAnd) \
  38. O(BitwiseOr) \
  39. O(BitwiseXor) \
  40. O(BitwiseNot) \
  41. O(Not) \
  42. O(UnaryPlus) \
  43. O(UnaryMinus) \
  44. O(Typeof) \
  45. O(LeftShift) \
  46. O(RightShift) \
  47. O(UnsignedRightShift)
  48. namespace JS::Bytecode {
  49. class Instruction {
  50. public:
  51. enum class Type {
  52. #define __BYTECODE_OP(op) \
  53. op,
  54. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  55. #undef __BYTECODE_OP
  56. };
  57. Type type() const { return m_type; }
  58. size_t length() const;
  59. String to_string() const;
  60. void execute(Bytecode::Interpreter&) const;
  61. static void destroy(Instruction&);
  62. protected:
  63. explicit Instruction(Type type)
  64. : m_type(type)
  65. {
  66. }
  67. private:
  68. Type m_type {};
  69. };
  70. }