Skip to content

Commit

Permalink
Import just the skeleton of the VM interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmr1993 committed Nov 28, 2023
1 parent 253ddb1 commit 9c63692
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
92 changes: 92 additions & 0 deletions optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,95 @@ pub enum ITypeInstruction {
StoreWordLeft, // swl
StoreWordRight, // swr
}

pub trait InterpreterEnv {}

pub fn interpret_instruction<Env: InterpreterEnv>(env: &mut Env, instr: Instruction) {
match instr {
Instruction::RType(instr) => interpret_rtype(env, instr),
Instruction::JType(instr) => interpret_jtype(env, instr),
Instruction::IType(instr) => interpret_itype(env, instr),
}
}

pub fn interpret_rtype<Env: InterpreterEnv>(_env: &mut Env, instr: RTypeInstruction) {
match instr {
RTypeInstruction::ShiftLeftLogical => (),
RTypeInstruction::ShiftRightLogical => (),
RTypeInstruction::ShiftRightArithmetic => (),
RTypeInstruction::ShiftLeftLogicalVariable => (),
RTypeInstruction::ShiftRightLogicalVariable => (),
RTypeInstruction::ShiftRightArithmeticVariable => (),
RTypeInstruction::JumpRegister => (),
RTypeInstruction::JumpAndLinkRegister => (),
RTypeInstruction::SyscallMmap => (),
RTypeInstruction::SyscallExitGroup => (),
RTypeInstruction::SyscallReadPreimage => (),
RTypeInstruction::SyscallReadOther => (),
RTypeInstruction::SyscallWriteHint => (),
RTypeInstruction::SyscallWritePreimage => (),
RTypeInstruction::SyscallWriteOther => (),
RTypeInstruction::SyscallFcntl => (),
RTypeInstruction::SyscallOther => (),
RTypeInstruction::MoveZero => (),
RTypeInstruction::MoveNonZero => (),
RTypeInstruction::Sync => (),
RTypeInstruction::MoveFromHi => (),
RTypeInstruction::MoveToHi => (),
RTypeInstruction::MoveFromLo => (),
RTypeInstruction::MoveToLo => (),
RTypeInstruction::Multiply => (),
RTypeInstruction::MultiplyUnsigned => (),
RTypeInstruction::Div => (),
RTypeInstruction::DivUnsigned => (),
RTypeInstruction::Add => (),
RTypeInstruction::AddUnsigned => (),
RTypeInstruction::Sub => (),
RTypeInstruction::SubUnsigned => (),
RTypeInstruction::And => (),
RTypeInstruction::Or => (),
RTypeInstruction::Xor => (),
RTypeInstruction::Nor => (),
RTypeInstruction::SetLessThan => (),
RTypeInstruction::SetLessThanUnsigned => (),
RTypeInstruction::MultiplyToRegister => (),
RTypeInstruction::CountLeadingOnes => (),
RTypeInstruction::CountLeadingZeros => (),
}
}

pub fn interpret_jtype<Env: InterpreterEnv>(_env: &mut Env, instr: JTypeInstruction) {
match instr {
JTypeInstruction::Jump => (),
JTypeInstruction::JumpAndLink => (),
}
}

pub fn interpret_itype<Env: InterpreterEnv>(_env: &mut Env, instr: ITypeInstruction) {
match instr {
ITypeInstruction::BranchEq => (),
ITypeInstruction::BranchNeq => (),
ITypeInstruction::BranchLeqZero => (),
ITypeInstruction::BranchGtZero => (),
ITypeInstruction::AddImmediate => (),
ITypeInstruction::AddImmediateUnsigned => (),
ITypeInstruction::SetLessThanImmediate => (),
ITypeInstruction::SetLessThanImmediateUnsigned => (),
ITypeInstruction::AndImmediate => (),
ITypeInstruction::OrImmediate => (),
ITypeInstruction::XorImmediate => (),
ITypeInstruction::LoadUpperImmediate => (),
ITypeInstruction::Load8 => (),
ITypeInstruction::Load16 => (),
ITypeInstruction::Load32 => (),
ITypeInstruction::Load8Unsigned => (),
ITypeInstruction::Load16Unsigned => (),
ITypeInstruction::LoadWordLeft => (),
ITypeInstruction::LoadWordRight => (),
ITypeInstruction::Store8 => (),
ITypeInstruction::Store16 => (),
ITypeInstruction::Store32 => (),
ITypeInstruction::StoreWordLeft => (),
ITypeInstruction::StoreWordRight => (),
}
}
10 changes: 8 additions & 2 deletions optimism/src/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::{
PAGE_SIZE,
},
mips::{
interpreter::{self, ITypeInstruction, Instruction, JTypeInstruction, RTypeInstruction},
interpreter::{
self, ITypeInstruction, Instruction, InterpreterEnv, JTypeInstruction, RTypeInstruction,
},
registers::Registers,
},
preimage_oracle::PreImageOracle,
Expand Down Expand Up @@ -93,6 +95,8 @@ fn memory_size(total: usize) -> String {
}
}

impl<Fp: Field> InterpreterEnv for Env<Fp> {}

impl<Fp: Field> Env<Fp> {
pub fn create(page_size: usize, state: State, preimage_oracle: PreImageOracle) -> Self {
let initial_instruction_pointer = state.pc;
Expand Down Expand Up @@ -270,7 +274,9 @@ impl<Fp: Field> Env<Fp> {
}

pub fn step(&mut self, config: VmConfiguration, metadata: &Meta, start: &Start) {
println!("instruction: {:?}", self.decode_instruction());
let instruction = self.decode_instruction();
println!("instruction: {:?}", instruction);
interpreter::interpret_instruction(self, instruction);

self.pp_info(config.info_at, metadata, start);

Expand Down

0 comments on commit 9c63692

Please sign in to comment.