mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +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:
parent
0acf89234c
commit
c372a084a2
Notes:
sideshowbarker
2024-07-17 23:02:37 +09:00
Author: https://github.com/awesomekling
Commit: c372a084a2
Pull-request: https://github.com/SerenityOS/serenity/pull/24524
3 changed files with 18 additions and 34 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue