Skip to content

Commit

Permalink
implement global.{get,set} instruction execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Aug 22, 2023
1 parent f3afbee commit 9df9454
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/wasmi/src/engine/regmach/executor/instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use core::cmp;
use wasmi_core::UntypedValue;

mod call;
mod global;
mod memory;
mod select;
mod table;
Expand Down Expand Up @@ -477,10 +478,14 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> {
Instr::MemoryInitFromToExact { dst, src, len } => {
self.execute_memory_init_from_to_exact(dst, src, len)?
}
Instr::GlobalGet { result, global } => todo!(),
Instr::GlobalSet { global, input } => todo!(),
Instr::GlobalSetI32Imm16 { global, input } => todo!(),
Instr::GlobalSetI64Imm16 { global, input } => todo!(),
Instr::GlobalGet { result, global } => self.execute_global_get(result, global),
Instr::GlobalSet { global, input } => self.execute_global_set(global, input),
Instr::GlobalSetI32Imm16 { global, input } => {
self.execute_global_set_i32imm16(global, input)
}
Instr::GlobalSetI64Imm16 { global, input } => {
self.execute_global_set_i64imm16(global, input)
}
Instr::I32Load(_) => todo!(),
Instr::I32LoadAt(_) => todo!(),
Instr::I32LoadOffset16(_) => todo!(),
Expand Down
44 changes: 44 additions & 0 deletions crates/wasmi/src/engine/regmach/executor/instrs/global.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use super::Executor;
use crate::engine::{
bytecode::GlobalIdx,
bytecode2::{Const16, Register},
};
use wasmi_core::UntypedValue;

#[cfg(doc)]
use crate::engine::bytecode2::Instruction;

impl<'ctx, 'engine> Executor<'ctx, 'engine> {
/// Executes an [`Instruction::GlobalGet`].
#[inline(always)]
pub fn execute_global_get(&mut self, result: Register, global: GlobalIdx) {
todo!()
}

/// Executes an [`Instruction::GlobalSet`].
#[inline(always)]
pub fn execute_global_set(&mut self, global: GlobalIdx, input: Register) {
let input = self.get_register(input);
self.execute_global_set_impl(global, input)
}

/// Executes an [`Instruction::GlobalSetI32Imm16`].
#[inline(always)]
pub fn execute_global_set_i32imm16(&mut self, global: GlobalIdx, input: Const16<i32>) {
let input = i32::from(input).into();
self.execute_global_set_impl(global, input)
}

/// Executes an [`Instruction::GlobalSetI64Imm16`].
#[inline(always)]
pub fn execute_global_set_i64imm16(&mut self, global: GlobalIdx, input: Const16<i64>) {
let input = i64::from(input).into();
self.execute_global_set_impl(global, input)
}

/// Executes a generic `global.set` instruction.
fn execute_global_set_impl(&mut self, global: GlobalIdx, new_value: UntypedValue) {
self.cache.set_global(self.ctx, global, new_value);
self.next_instr()
}
}

0 comments on commit 9df9454

Please sign in to comment.