slige/runtime/instruction_size.cpp

53 lines
1.2 KiB
C++
Raw Normal View History

2024-12-16 18:23:51 +01:00
#include "arch.hpp"
#include "vm.hpp"
using namespace sliger;
size_t VM::instruction_size(size_t i) const
{
switch (static_cast<Op>(this->program.at(i))) {
case Op::Nop:
case Op::PushNull:
return 1;
case Op::PushInt:
case Op::PushBool:
return 2;
case Op::PushString: {
auto string_length = this->program.at(i + 1);
return 2 + string_length;
}
case Op::PushPtr:
return 2;
case Op::Pop:
return 1;
case Op::ReserveStatic:
case Op::LoadStatic:
case Op::StoreStatic:
case Op::LoadLocal:
case Op::StoreLocal:
case Op::Call:
return 2;
case Op::Return:
case Op::Jump:
case Op::JumpIfTrue:
return 1;
case Op::Builtin:
return 2;
case Op::Add:
case Op::Subtract:
case Op::Multiply:
case Op::Divide:
case Op::Remainder:
case Op::Equal:
case Op::LessThan:
case Op::And:
case Op::Or:
case Op::Xor:
case Op::Not:
return 1;
case Op::SourceMap:
return 4;
}
return 1;
}