mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 22:55:23 +00:00
LibJS/Bytecode: Add and use copy_if_needed_to_preserve_evaluation_order
This is a new Bytecode::Generator helper that takes an operand and returns the same operand, or a copy of it, in case a copy is required to preserve correct evaluation order. This can be used in a bunch of places where we're worried about clobbering some value after obtaining it. Practically, locals are always copied, and temporary registers as well as constants are returned as-is.
This commit is contained in:
@@ -1156,4 +1156,13 @@ void Generator::emit_jump_if(ScopedOperand const& condition, Label true_target,
|
||||
emit<Op::JumpIf>(condition, true_target, false_target);
|
||||
}
|
||||
|
||||
ScopedOperand Generator::copy_if_needed_to_preserve_evaluation_order(ScopedOperand const& operand)
|
||||
{
|
||||
if (!operand.operand().is_local())
|
||||
return operand;
|
||||
auto new_register = allocate_register();
|
||||
emit<Bytecode::Op::Mov>(new_register, operand);
|
||||
return new_register;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user