1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:38:10 +00:00

LibJS: Generate bytecode in basic blocks instead of one big block

This limits the size of each block (currently set to 1K), and gets us
closer to a canonical, more easily analysable bytecode format.
As a result of this, "Labels" are now simply entries to basic blocks.
Since there is no more 'conditional' jump (as all jumps are always
taken), JumpIf{True,False} are unified to JumpConditional, and
JumpIfNullish is renamed to JumpNullish.
Also fixes #7914 as a result of reimplementing the loop logic.
This commit is contained in:
Ali Mohammad Pur 2021-06-09 06:49:58 +04:30 committed by Andreas Kling
parent d7a25cdb82
commit 01e8f0889a
16 changed files with 392 additions and 174 deletions

View file

@ -268,31 +268,40 @@ private:
class Jump : public Instruction {
public:
explicit Jump(Type type, Optional<Label> target = {})
constexpr static bool IsTerminator = true;
explicit Jump(Type type, Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
: Instruction(type)
, m_target(move(target))
, m_true_target(move(taken_target))
, m_false_target(move(nontaken_target))
{
}
explicit Jump(Optional<Label> target = {})
explicit Jump(Optional<Label> taken_target = {}, Optional<Label> nontaken_target = {})
: Instruction(Type::Jump)
, m_target(move(target))
, m_true_target(move(taken_target))
, m_false_target(move(nontaken_target))
{
}
void set_target(Optional<Label> target) { m_target = move(target); }
void set_targets(Optional<Label> true_target, Optional<Label> false_target)
{
m_true_target = move(true_target);
m_false_target = move(false_target);
}
void execute(Bytecode::Interpreter&) const;
String to_string() const;
protected:
Optional<Label> m_target;
Optional<Label> m_true_target;
Optional<Label> m_false_target;
};
class JumpIfFalse final : public Jump {
class JumpConditional final : public Jump {
public:
explicit JumpIfFalse(Optional<Label> target = {})
: Jump(Type::JumpIfFalse, move(target))
explicit JumpConditional(Optional<Label> true_target = {}, Optional<Label> false_target = {})
: Jump(Type::JumpConditional, move(true_target), move(false_target))
{
}
@ -300,21 +309,10 @@ public:
String to_string() const;
};
class JumpIfTrue : public Jump {
class JumpNullish final : public Jump {
public:
explicit JumpIfTrue(Optional<Label> target = {})
: Jump(Type::JumpIfTrue, move(target))
{
}
void execute(Bytecode::Interpreter&) const;
String to_string() const;
};
class JumpIfNotNullish final : public Jump {
public:
explicit JumpIfNotNullish(Optional<Label> target = {})
: Jump(Type::JumpIfNotNullish, move(target))
explicit JumpNullish(Optional<Label> true_target = {}, Optional<Label> false_target = {})
: Jump(Type::JumpNullish, move(true_target), move(false_target))
{
}
@ -364,6 +362,8 @@ private:
class Return final : public Instruction {
public:
constexpr static bool IsTerminator = true;
Return()
: Instruction(Type::Return)
{