Instruction.h 3.2 KB

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