Skip to content

Commit

Permalink
Update walrus to 0.21.0
Browse files Browse the repository at this point in the history
* `InitExpr` has been renamed to `ConstExpr`
* table64 API adjustments
  • Loading branch information
kateinoigakukun committed Jul 3, 2024
1 parent dadd131 commit 65d6ca9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
23 changes: 4 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ anyhow = "1"
clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
toml = "0.8"
walrus = "0.20.3"
walrus = "0.21.0"
wasm-compose = "0.212.0"
wasm-metadata = "0.212.0"
wasm-opt = { version = "0.116.0", optional = true }
Expand Down
21 changes: 10 additions & 11 deletions src/data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::{bail, Result};
use std::collections::HashMap;
use walrus::{
ActiveData, ActiveDataLocation, DataKind, ElementKind, FunctionBuilder, FunctionId,
FunctionKind, InitExpr, Module, ValType,
ActiveData, ActiveDataLocation, DataKind, ElementItems, ElementKind, FunctionBuilder, FunctionId, FunctionKind, ConstExpr, Module, RefType, ValType
};

use crate::walrus_ops::bump_stack_global;
Expand Down Expand Up @@ -137,7 +136,7 @@ impl Data {
let len_local = module.locals.add(ValType::I32);
let ptr_local = module.locals.add(ValType::I32);

let mut passive_fids: Vec<Option<FunctionId>> = Vec::new();
let mut passive_fids: Vec<FunctionId> = Vec::new();
for passive_segment in self.passive_segments {
let passive_id = module.data.add(DataKind::Passive, passive_segment);

Expand Down Expand Up @@ -166,25 +165,25 @@ impl Data {
// return the allocated pointer
.local_get(ptr_local);

passive_fids.push(Some(
passive_fids.push(
module
.funcs
.add_local(builder.local_func(vec![offset_local, len_local])),
));
);
}

let passive_tid = module.tables.add_local(
passive_fids.len() as u32,
Some(passive_fids.len() as u32),
ValType::Funcref,
false,
passive_fids.len() as u64,
Some(passive_fids.len() as u64),
RefType::Funcref,
);
module.elements.add(
ElementKind::Active {
table: passive_tid,
offset: InitExpr::Value(walrus::ir::Value::I32(0)),
offset: ConstExpr::Value(walrus::ir::Value::I32(0)),
},
ValType::Funcref,
passive_fids,
ElementItems::Functions(passive_fids),
);

// main passive call function
Expand Down
4 changes: 2 additions & 2 deletions src/virt_env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{bail, Context, Result};
use serde::Deserialize;
use walrus::{
ir::Value, ActiveData, ActiveDataLocation, DataKind, ExportItem, GlobalKind, InitExpr, Module,
ir::Value, ActiveData, ActiveDataLocation, DataKind, ExportItem, GlobalKind, ConstExpr, Module,
};

use crate::walrus_ops::{bump_stack_global, get_active_data_segment};
Expand Down Expand Up @@ -78,7 +78,7 @@ pub(crate) fn create_env_virt<'a>(module: &'a mut Module, env: &VirtEnv) -> Resu
let ExportItem::Global(env_ptr_global) = env_ptr_export.item else {
bail!("Adapter 'env' not a global");
};
let GlobalKind::Local(InitExpr::Value(Value::I32(env_ptr_addr))) =
let GlobalKind::Local(ConstExpr::Value(Value::I32(env_ptr_addr))) =
&module.globals.get(env_ptr_global).kind
else {
bail!("Adapter 'env' not a local I32 global value");
Expand Down
4 changes: 2 additions & 2 deletions src/virt_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, fmt, fs};
use anyhow::{bail, Context, Result};
use clap::ValueEnum;
use serde::Deserialize;
use walrus::{ir::Value, ExportItem, GlobalKind, InitExpr, Module};
use walrus::{ir::Value, ExportItem, GlobalKind, ConstExpr, Module};

use crate::{
data::{Data, WasmEncode},
Expand Down Expand Up @@ -505,7 +505,7 @@ pub(crate) fn create_io_virt<'a>(
let ExportItem::Global(io_ptr_global) = io_ptr_export.item else {
bail!("Virt adapter 'io' not a global");
};
let GlobalKind::Local(InitExpr::Value(Value::I32(io_ptr_addr))) =
let GlobalKind::Local(ConstExpr::Value(Value::I32(io_ptr_addr))) =
&module.globals.get(io_ptr_global).kind
else {
bail!("Virt adapter 'io' not a local I32 global value");
Expand Down
7 changes: 3 additions & 4 deletions src/walrus_ops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{bail, Context, Result};
use walrus::{
ir::Value, ActiveData, ActiveDataLocation, Data, DataKind, GlobalKind, InitExpr, MemoryId,
Module,
ir::Value, ActiveData, ActiveDataLocation, ConstExpr, Data, DataKind, GlobalKind, MemoryId, Module
};

pub(crate) fn get_active_data_start(data: &Data, mem: MemoryId) -> Result<u32> {
Expand Down Expand Up @@ -56,7 +55,7 @@ pub(crate) fn get_stack_global(module: &Module) -> Result<u32> {
.context("Unable to find __stack_pointer global name")?
.id();
let stack_global = module.globals.get(stack_global_id);
let GlobalKind::Local(InitExpr::Value(Value::I32(stack_value))) = &stack_global.kind else {
let GlobalKind::Local(ConstExpr::Value(Value::I32(stack_value))) = &stack_global.kind else {
bail!("Stack global is not a constant I32");
};
Ok(*stack_value as u32)
Expand All @@ -73,7 +72,7 @@ pub(crate) fn bump_stack_global(module: &mut Module, offset: i32) -> Result<u32>
.context("Unable to find __stack_pointer global name")?
.id();
let stack_global = module.globals.get_mut(stack_global_id);
let GlobalKind::Local(InitExpr::Value(Value::I32(stack_value))) = &mut stack_global.kind else {
let GlobalKind::Local(ConstExpr::Value(Value::I32(stack_value))) = &mut stack_global.kind else {
bail!("Stack global is not a constant I32");
};
if offset > *stack_value {
Expand Down

0 comments on commit 65d6ca9

Please sign in to comment.