mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:07:44 +00:00
LibJS: Add bytecode instructions for multiplication and division
This commit is contained in:
parent
5183952d1d
commit
3c5ce9b5b7
4 changed files with 66 additions and 0 deletions
|
@ -49,6 +49,12 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
|
||||||
case BinaryOp::Subtraction:
|
case BinaryOp::Subtraction:
|
||||||
generator.emit<Bytecode::Op::Sub>(dst_reg, *lhs_reg, *rhs_reg);
|
generator.emit<Bytecode::Op::Sub>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
return dst_reg;
|
return dst_reg;
|
||||||
|
case BinaryOp::Multiplication:
|
||||||
|
generator.emit<Bytecode::Op::Mul>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
|
case BinaryOp::Division:
|
||||||
|
generator.emit<Bytecode::Op::Div>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
case BinaryOp::LessThan:
|
case BinaryOp::LessThan:
|
||||||
generator.emit<Bytecode::Op::LessThan>(dst_reg, *lhs_reg, *rhs_reg);
|
generator.emit<Bytecode::Op::LessThan>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
return dst_reg;
|
return dst_reg;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
O(Load) \
|
O(Load) \
|
||||||
O(Add) \
|
O(Add) \
|
||||||
O(Sub) \
|
O(Sub) \
|
||||||
|
O(Mul) \
|
||||||
|
O(Div) \
|
||||||
O(LessThan) \
|
O(LessThan) \
|
||||||
O(AbstractInequals) \
|
O(AbstractInequals) \
|
||||||
O(AbstractEquals) \
|
O(AbstractEquals) \
|
||||||
|
|
|
@ -62,6 +62,16 @@ void Sub::execute(Bytecode::Interpreter& interpreter) const
|
||||||
interpreter.reg(m_dst) = sub(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
interpreter.reg(m_dst) = sub(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mul::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = mul(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Div::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = div(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
void LessThan::execute(Bytecode::Interpreter& interpreter) const
|
void LessThan::execute(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
interpreter.reg(m_dst) = less_than(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
interpreter.reg(m_dst) = less_than(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
@ -193,6 +203,16 @@ String Sub::to_string() const
|
||||||
return String::formatted("Sub dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
return String::formatted("Sub dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Mul::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("Mul dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String Div::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("Div dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
}
|
||||||
|
|
||||||
String LessThan::to_string() const
|
String LessThan::to_string() const
|
||||||
{
|
{
|
||||||
return String::formatted("LessThan dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
return String::formatted("LessThan dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
|
|
@ -70,6 +70,44 @@ private:
|
||||||
Register m_src2;
|
Register m_src2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Mul final : public Instruction {
|
||||||
|
public:
|
||||||
|
Mul(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::Mul)
|
||||||
|
, m_dst(dst)
|
||||||
|
, m_src1(src1)
|
||||||
|
, m_src2(src2)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute(Bytecode::Interpreter&) const;
|
||||||
|
String to_string() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Register m_dst;
|
||||||
|
Register m_src1;
|
||||||
|
Register m_src2;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Div final : public Instruction {
|
||||||
|
public:
|
||||||
|
Div(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::Div)
|
||||||
|
, m_dst(dst)
|
||||||
|
, m_src1(src1)
|
||||||
|
, m_src2(src2)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute(Bytecode::Interpreter&) const;
|
||||||
|
String to_string() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Register m_dst;
|
||||||
|
Register m_src1;
|
||||||
|
Register m_src2;
|
||||||
|
};
|
||||||
|
|
||||||
class LessThan final : public Instruction {
|
class LessThan final : public Instruction {
|
||||||
public:
|
public:
|
||||||
LessThan(Register dst, Register src1, Register src2)
|
LessThan(Register dst, Register src1, Register src2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue