Instruction.h 2.1 KB

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