Instruction.h 2.8 KB

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