Skip to content

Commit

Permalink
Merge with upstream (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhil authored Mar 13, 2024
2 parents 38bb42a + fb419bd commit 08700fe
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
11 changes: 0 additions & 11 deletions crates/wasm-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ from other WebAssembly components.

It is made available as the `compose` subcommand of `wasm-tools`.

## Implementation status

A quick note on the implementation status of the component model
proposal:

At this time of this writing, no WebAssembly runtimes have fully
implemented the component model proposal.

__[Wasmtime](https://github.com/bytecodealliance/wasmtime)
has implementation efforts underway to support it.__

## Usage

To compose a component, run the `compose` command:
Expand Down
2 changes: 1 addition & 1 deletion crates/wast/src/core/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ impl<'a> Parse<'a> for BrOnCastFail<'a> {
}

/// Different ways to specify a `v128.const` instruction
#[derive(Debug)]
#[derive(Clone, Debug)]
#[allow(missing_docs)]
pub enum V128Const {
I8x16([i8; 16]),
Expand Down
4 changes: 2 additions & 2 deletions crates/wast/src/core/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Peek for WastRetCore<'_> {
}

/// Either a NaN pattern (`nan:canonical`, `nan:arithmetic`) or a value of type `T`.
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
#[allow(missing_docs)]
pub enum NanPattern<T> {
CanonicalNan,
Expand Down Expand Up @@ -181,7 +181,7 @@ where
///
/// This implementation is necessary because only float types can include NaN patterns; otherwise
/// it is largely similar to the implementation of `V128Const`.
#[derive(Debug)]
#[derive(Clone, Debug)]
#[allow(missing_docs)]
pub enum V128Pattern {
I8x16([i8; 16]),
Expand Down
41 changes: 38 additions & 3 deletions crates/wit-parser/src/sizealign.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
use crate::{FlagsRepr, Int, Resolve, Type, TypeDef, TypeDefKind};

#[derive(Default)]
pub enum AddressSize {
#[default]
Wasm32,
Wasm64,
}

#[derive(Default)]
pub struct SizeAlign {
map: Vec<(usize, usize)>,
wasm_type: AddressSize,
}

impl SizeAlign {
pub fn new(wasm_type: AddressSize) -> Self {
Self {
map: Vec::new(),
wasm_type,
}
}

pub fn fill(&mut self, resolve: &Resolve) {
self.map = Vec::new();
for (_, ty) in resolve.types.iter() {
Expand All @@ -17,7 +32,13 @@ impl SizeAlign {
fn calculate(&self, ty: &TypeDef) -> (usize, usize) {
match &ty.kind {
TypeDefKind::Type(t) => (self.size(t), self.align(t)),
TypeDefKind::List(_) => (8, 4),
TypeDefKind::List(_) => {
if matches!(self.wasm_type, AddressSize::Wasm64) {
(16, 8)
} else {
(8, 4)
}
}
TypeDefKind::Record(r) => self.record(r.fields.iter().map(|f| &f.ty)),
TypeDefKind::Tuple(t) => self.record(t.types.iter()),
TypeDefKind::Flags(f) => match f.repr() {
Expand Down Expand Up @@ -47,7 +68,14 @@ impl SizeAlign {
Type::Bool | Type::U8 | Type::S8 => 1,
Type::U16 | Type::S16 => 2,
Type::U32 | Type::S32 | Type::Float32 | Type::Char => 4,
Type::U64 | Type::S64 | Type::Float64 | Type::String => 8,
Type::U64 | Type::S64 | Type::Float64 => 8,
Type::String => {
if matches!(self.wasm_type, AddressSize::Wasm64) {
16
} else {
8
}
}
Type::Id(id) => self.map[id.index()].0,
}
}
Expand All @@ -56,8 +84,15 @@ impl SizeAlign {
match ty {
Type::Bool | Type::U8 | Type::S8 => 1,
Type::U16 | Type::S16 => 2,
Type::U32 | Type::S32 | Type::Float32 | Type::Char | Type::String => 4,
Type::U32 | Type::S32 | Type::Float32 | Type::Char => 4,
Type::U64 | Type::S64 | Type::Float64 => 8,
Type::String => {
if matches!(self.wasm_type, AddressSize::Wasm64) {
8
} else {
4
}
}
Type::Id(id) => self.map[id.index()].1,
}
}
Expand Down

0 comments on commit 08700fe

Please sign in to comment.