Instruction.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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(Call) \
  36. O(EnterScope) \
  37. O(Return) \
  38. O(BitwiseAnd) \
  39. O(BitwiseOr) \
  40. O(BitwiseXor) \
  41. O(BitwiseNot) \
  42. O(Not) \
  43. O(UnaryPlus) \
  44. O(UnaryMinus) \
  45. O(Typeof) \
  46. O(LeftShift) \
  47. O(RightShift) \
  48. O(UnsignedRightShift) \
  49. O(In) \
  50. O(InstanceOf)
  51. namespace JS::Bytecode {
  52. class Instruction {
  53. public:
  54. enum class Type {
  55. #define __BYTECODE_OP(op) \
  56. op,
  57. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  58. #undef __BYTECODE_OP
  59. };
  60. Type type() const { return m_type; }
  61. size_t length() const;
  62. String to_string() const;
  63. void execute(Bytecode::Interpreter&) const;
  64. static void destroy(Instruction&);
  65. protected:
  66. explicit Instruction(Type type)
  67. : m_type(type)
  68. {
  69. }
  70. private:
  71. Type m_type {};
  72. };
  73. }