Instruction.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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(LooselyInequals) \
  24. O(LooselyEquals) \
  25. O(StrictlyInequals) \
  26. O(StrictlyEquals) \
  27. O(NewBigInt) \
  28. O(NewArray) \
  29. O(IteratorToArray) \
  30. O(NewString) \
  31. O(NewObject) \
  32. O(NewRegExp) \
  33. O(CopyObjectExcludingProperties) \
  34. O(GetVariable) \
  35. O(SetVariable) \
  36. O(PutById) \
  37. O(GetById) \
  38. O(PutByValue) \
  39. O(GetByValue) \
  40. O(Jump) \
  41. O(JumpConditional) \
  42. O(JumpNullish) \
  43. O(JumpUndefined) \
  44. O(Call) \
  45. O(NewFunction) \
  46. O(Return) \
  47. O(BitwiseAnd) \
  48. O(BitwiseOr) \
  49. O(BitwiseXor) \
  50. O(BitwiseNot) \
  51. O(Not) \
  52. O(UnaryPlus) \
  53. O(UnaryMinus) \
  54. O(Typeof) \
  55. O(LeftShift) \
  56. O(RightShift) \
  57. O(UnsignedRightShift) \
  58. O(In) \
  59. O(InstanceOf) \
  60. O(ConcatString) \
  61. O(Increment) \
  62. O(Decrement) \
  63. O(Throw) \
  64. O(PushDeclarativeEnvironment) \
  65. O(EnterUnwindContext) \
  66. O(LeaveUnwindContext) \
  67. O(ContinuePendingUnwind) \
  68. O(Yield) \
  69. O(GetIterator) \
  70. O(IteratorNext) \
  71. O(IteratorResultDone) \
  72. O(IteratorResultValue) \
  73. O(NewClass)
  74. namespace JS::Bytecode {
  75. class Instruction {
  76. public:
  77. constexpr static bool IsTerminator = false;
  78. enum class Type {
  79. #define __BYTECODE_OP(op) \
  80. op,
  81. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  82. #undef __BYTECODE_OP
  83. };
  84. bool is_terminator() const;
  85. Type type() const { return m_type; }
  86. size_t length() const;
  87. String to_string(Bytecode::Executable const&) const;
  88. void execute(Bytecode::Interpreter&) const;
  89. void replace_references(BasicBlock const&, BasicBlock const&);
  90. static void destroy(Instruction&);
  91. protected:
  92. explicit Instruction(Type type)
  93. : m_type(type)
  94. {
  95. }
  96. private:
  97. Type m_type {};
  98. };
  99. }