2021-06-03 11:46:30 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
2021-06-07 16:12:43 +03:00
|
|
|
#define ENUMERATE_BYTECODE_OPS(O) \
|
|
|
|
O(Load) \
|
2021-06-08 06:58:36 +03:00
|
|
|
O(LoadImmediate) \
|
|
|
|
O(Store) \
|
2021-06-07 16:12:43 +03:00
|
|
|
O(Add) \
|
|
|
|
O(Sub) \
|
2021-06-07 20:17:20 +03:00
|
|
|
O(Mul) \
|
|
|
|
O(Div) \
|
2021-06-07 20:37:23 +03:00
|
|
|
O(Mod) \
|
|
|
|
O(Exp) \
|
2021-06-07 20:57:38 +03:00
|
|
|
O(GreaterThan) \
|
|
|
|
O(GreaterThanEquals) \
|
2021-06-07 16:12:43 +03:00
|
|
|
O(LessThan) \
|
2021-06-07 20:57:38 +03:00
|
|
|
O(LessThanEquals) \
|
2021-06-07 16:12:43 +03:00
|
|
|
O(AbstractInequals) \
|
|
|
|
O(AbstractEquals) \
|
2021-06-07 21:39:47 +03:00
|
|
|
O(TypedInequals) \
|
|
|
|
O(TypedEquals) \
|
2021-06-08 08:59:25 +03:00
|
|
|
O(NewBigInt) \
|
2021-06-09 00:06:52 +03:00
|
|
|
O(NewArray) \
|
2021-06-07 16:12:43 +03:00
|
|
|
O(NewString) \
|
|
|
|
O(NewObject) \
|
|
|
|
O(GetVariable) \
|
|
|
|
O(SetVariable) \
|
|
|
|
O(PutById) \
|
|
|
|
O(GetById) \
|
|
|
|
O(Jump) \
|
2021-06-09 05:19:58 +03:00
|
|
|
O(JumpConditional) \
|
|
|
|
O(JumpNullish) \
|
2021-06-07 16:12:43 +03:00
|
|
|
O(Call) \
|
2021-06-10 01:49:23 +03:00
|
|
|
O(NewFunction) \
|
2021-06-07 21:16:04 +03:00
|
|
|
O(Return) \
|
|
|
|
O(BitwiseAnd) \
|
|
|
|
O(BitwiseOr) \
|
2021-06-07 21:53:47 +03:00
|
|
|
O(BitwiseXor) \
|
|
|
|
O(BitwiseNot) \
|
|
|
|
O(Not) \
|
|
|
|
O(UnaryPlus) \
|
|
|
|
O(UnaryMinus) \
|
2021-06-07 22:14:12 +03:00
|
|
|
O(Typeof) \
|
|
|
|
O(LeftShift) \
|
|
|
|
O(RightShift) \
|
2021-06-07 23:13:37 +03:00
|
|
|
O(UnsignedRightShift) \
|
2021-06-07 23:18:19 +03:00
|
|
|
O(In) \
|
2021-06-08 06:58:36 +03:00
|
|
|
O(InstanceOf) \
|
2021-06-09 12:40:38 +03:00
|
|
|
O(ConcatString) \
|
|
|
|
O(Increment) \
|
2021-06-09 19:18:56 +03:00
|
|
|
O(Decrement) \
|
2021-06-10 16:04:38 +03:00
|
|
|
O(Throw) \
|
|
|
|
O(EnterUnwindContext) \
|
|
|
|
O(LeaveUnwindContext) \
|
|
|
|
O(ContinuePendingUnwind)
|
2021-06-07 16:12:43 +03:00
|
|
|
|
2021-06-03 11:46:30 +03:00
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
|
|
|
class Instruction {
|
|
|
|
public:
|
2021-06-09 05:19:58 +03:00
|
|
|
constexpr static bool IsTerminator = false;
|
|
|
|
|
2021-06-07 16:12:43 +03:00
|
|
|
enum class Type {
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
|
|
op,
|
|
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
|
|
#undef __BYTECODE_OP
|
|
|
|
};
|
|
|
|
|
|
|
|
Type type() const { return m_type; }
|
|
|
|
size_t length() const;
|
2021-06-09 11:02:01 +03:00
|
|
|
String to_string(Bytecode::Executable const&) const;
|
2021-06-07 16:12:43 +03:00
|
|
|
void execute(Bytecode::Interpreter&) const;
|
|
|
|
static void destroy(Instruction&);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit Instruction(Type type)
|
|
|
|
: m_type(type)
|
|
|
|
{
|
|
|
|
}
|
2021-06-03 11:46:30 +03:00
|
|
|
|
2021-06-07 16:12:43 +03:00
|
|
|
private:
|
|
|
|
Type m_type {};
|
2021-06-03 11:46:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|