Instruction.h 2.2 KB

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