Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions crates/gen-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,8 @@ impl C {
Type::S32 => self.src.h("int32_t"),
Type::U64 => self.src.h("uint64_t"),
Type::S64 => self.src.h("int64_t"),
Type::CChar => self.src.h("char"),
Type::F32 => self.src.h("float"),
Type::F64 => self.src.h("double"),
Type::Usize => self.src.h("size_t"),
Type::Handle(id) => {
self.print_namespace(iface);
self.src.h(&iface.resources[*id].name.to_snake_case());
Expand Down Expand Up @@ -280,10 +278,8 @@ impl C {
Type::S32 => self.src.h("s32"),
Type::U64 => self.src.h("u64"),
Type::S64 => self.src.h("s64"),
Type::CChar => self.src.h("char"),
Type::F32 => self.src.h("f32"),
Type::F64 => self.src.h("f64"),
Type::Usize => self.src.h("usize"),
Type::Handle(id) => self.src.h(&iface.resources[*id].name.to_snake_case()),
Type::Id(id) => {
let ty = &iface.types[*id];
Expand Down Expand Up @@ -1297,10 +1293,8 @@ impl Bindgen for FunctionBindgen<'_> {
Instruction::U32FromI32 => results.push(format!("(uint32_t) ({})", operands[0])),
Instruction::S32FromI32 | Instruction::S64FromI64 => results.push(operands[0].clone()),
Instruction::U64FromI64 => results.push(format!("(uint64_t) ({})", operands[0])),
Instruction::UsizeFromI32 => results.push(format!("(size_t) ({})", operands[0])),

Instruction::I32FromUsize
| Instruction::I32FromU8
Instruction::I32FromU8
| Instruction::I32FromS8
| Instruction::I32FromU16
| Instruction::I32FromS16
Expand Down
10 changes: 4 additions & 6 deletions crates/gen-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ impl Js {

fn array_ty(&self, iface: &Interface, ty: &Type) -> Option<&'static str> {
match ty {
Type::U8 | Type::CChar => Some("Uint8Array"),
Type::U8 => Some("Uint8Array"),
Type::S8 => Some("Int8Array"),
Type::U16 => Some("Uint16Array"),
Type::S16 => Some("Int16Array"),
Type::U32 | Type::Usize => Some("Uint32Array"),
Type::U32 => Some("Uint32Array"),
Type::S32 => Some("Int32Array"),
Type::U64 => Some("BigUint64Array"),
Type::S64 => Some("BigInt64Array"),
Expand All @@ -145,12 +145,10 @@ impl Js {
fn print_ty(&mut self, iface: &Interface, ty: &Type) {
match ty {
Type::U8
| Type::CChar
| Type::S8
| Type::U16
| Type::S16
| Type::U32
| Type::Usize
| Type::S32
| Type::F32
| Type::F64 => self.src.ts("number"),
Expand Down Expand Up @@ -1228,7 +1226,7 @@ impl Bindgen for FunctionBindgen<'_> {
Instruction::S16FromI32 => self.clamp_guest(results, operands, i16::MIN, i16::MAX),
// Use `>>>0` to ensure the bits of the number are treated as
// unsigned.
Instruction::U32FromI32 | Instruction::UsizeFromI32 => {
Instruction::U32FromI32 => {
results.push(format!("{} >>> 0", operands[0]));
}
// All bigints coming from wasm are treated as signed, so convert
Expand All @@ -1246,7 +1244,7 @@ impl Bindgen for FunctionBindgen<'_> {
Instruction::I32FromS8 => self.clamp_host(results, operands, i8::MIN, i8::MAX),
Instruction::I32FromU16 => self.clamp_host(results, operands, u16::MIN, u16::MAX),
Instruction::I32FromS16 => self.clamp_host(results, operands, i16::MIN, i16::MAX),
Instruction::I32FromU32 | Instruction::I32FromUsize => {
Instruction::I32FromU32 => {
self.clamp_host(results, operands, u32::MIN, u32::MAX);
}
Instruction::I32FromS32 => self.clamp_host(results, operands, i32::MIN, i32::MAX),
Expand Down
2 changes: 0 additions & 2 deletions crates/gen-markdown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ impl Markdown {
Type::F32 => self.src.push_str("`f32`"),
Type::F64 => self.src.push_str("`f64`"),
Type::Char => self.src.push_str("`char`"),
Type::CChar => self.src.push_str("`c_char`"),
Type::Usize => self.src.push_str("`usize`"),
Type::Handle(id) => {
self.src.push_str("handle<");
self.src.push_str(&iface.resources[*id].name);
Expand Down
11 changes: 2 additions & 9 deletions crates/gen-rust-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ impl RustGenerator for RustWasm {
&mut self.types
}

fn print_usize(&mut self) {
self.src.push_str("usize");
}

fn print_pointer(&mut self, iface: &Interface, const_: bool, ty: &Type) {
self.push_str("*");
if const_ {
Expand Down Expand Up @@ -858,11 +854,9 @@ impl Bindgen for FunctionBindgen<'_> {
let s = operands.pop().unwrap();
results.push(format!("wit_bindgen_rust::rt::as_i64({})", s));
}
Instruction::I32FromUsize
| Instruction::I32FromChar
Instruction::I32FromChar
| Instruction::I32FromU8
| Instruction::I32FromS8
| Instruction::I32FromChar8
| Instruction::I32FromU16
| Instruction::I32FromS16
| Instruction::I32FromU32
Expand All @@ -886,12 +880,11 @@ impl Bindgen for FunctionBindgen<'_> {
results.push(operands.pop().unwrap());
}
Instruction::S8FromI32 => top_as("i8"),
Instruction::Char8FromI32 | Instruction::U8FromI32 => top_as("u8"),
Instruction::U8FromI32 => top_as("u8"),
Instruction::S16FromI32 => top_as("i16"),
Instruction::U16FromI32 => top_as("u16"),
Instruction::U32FromI32 => top_as("u32"),
Instruction::U64FromI64 => top_as("u64"),
Instruction::UsizeFromI32 => top_as("usize"),
Instruction::CharFromI32 => {
if unchecked {
results.push(format!(
Expand Down
3 changes: 0 additions & 3 deletions crates/gen-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub trait RustGenerator {
fn push_str(&mut self, s: &str);
fn info(&self, ty: TypeId) -> TypeInfo;
fn types_mut(&mut self) -> &mut Types;
fn print_usize(&mut self);
fn print_pointer(&mut self, iface: &Interface, const_: bool, ty: &Type);
fn print_borrowed_slice(
&mut self,
Expand Down Expand Up @@ -200,10 +199,8 @@ pub trait RustGenerator {
}

Type::U8 => self.push_str("u8"),
Type::CChar => self.push_str("u8"),
Type::U16 => self.push_str("u16"),
Type::U32 => self.push_str("u32"),
Type::Usize => self.print_usize(),
Type::U64 => self.push_str("u64"),
Type::S8 => self.push_str("i8"),
Type::S16 => self.push_str("i16"),
Expand Down
4 changes: 0 additions & 4 deletions crates/gen-spidermonkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
abi::Instruction::I32FromS16 => todo!(),
abi::Instruction::I32FromU8 => todo!(),
abi::Instruction::I32FromS8 => todo!(),
abi::Instruction::I32FromUsize => todo!(),
abi::Instruction::I32FromChar8 => todo!(),
abi::Instruction::F32FromIf32 => todo!(),
abi::Instruction::F64FromIf64 => todo!(),
abi::Instruction::S8FromI32 => todo!(),
Expand Down Expand Up @@ -1505,8 +1503,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
abi::Instruction::CharFromI32 => todo!(),
abi::Instruction::If32FromF32 => todo!(),
abi::Instruction::If64FromF64 => todo!(),
abi::Instruction::Char8FromI32 => todo!(),
abi::Instruction::UsizeFromI32 => todo!(),
abi::Instruction::I32FromBorrowedHandle { ty: _ } => todo!(),
abi::Instruction::I32FromOwnedHandle { ty: _ } => todo!(),
abi::Instruction::HandleOwnedFromI32 { ty: _ } => todo!(),
Expand Down
12 changes: 5 additions & 7 deletions crates/gen-wasmtime-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ impl WasmtimePy {
| Type::U32
| Type::S32
| Type::U64
| Type::S64
| Type::Usize
| Type::CChar => self.src.push_str("int"),
| Type::S64 => self.src.push_str("int"),
Type::F32 | Type::F64 => self.src.push_str("float"),
Type::Char => self.src.push_str("str"),
Type::Handle(id) => {
Expand Down Expand Up @@ -493,11 +491,11 @@ impl WasmtimePy {

fn array_ty(&self, iface: &Interface, ty: &Type) -> Option<&'static str> {
match ty {
Type::U8 | Type::CChar => Some("c_uint8"),
Type::U8 => Some("c_uint8"),
Type::S8 => Some("c_int8"),
Type::U16 => Some("c_uint16"),
Type::S16 => Some("c_int16"),
Type::U32 | Type::Usize => Some("c_uint32"),
Type::U32 => Some("c_uint32"),
Type::S32 => Some("c_int32"),
Type::U64 => Some("c_uint64"),
Type::S64 => Some("c_int64"),
Expand Down Expand Up @@ -1346,7 +1344,7 @@ impl Bindgen for FunctionBindgen<'_> {
Instruction::U16FromI32 => self.clamp(results, operands, u16::MIN, u16::MAX),
Instruction::S16FromI32 => self.clamp(results, operands, i16::MIN, i16::MAX),
// Ensure the bits of the number are treated as unsigned.
Instruction::U32FromI32 | Instruction::UsizeFromI32 => {
Instruction::U32FromI32 => {
results.push(format!("{} & 0xffffffff", operands[0]));
}
// All bigints coming from wasm are treated as signed, so convert
Expand All @@ -1367,7 +1365,7 @@ impl Bindgen for FunctionBindgen<'_> {
Instruction::I32FromU16 => self.clamp(results, operands, u16::MIN, u16::MAX),
Instruction::I32FromS16 => self.clamp(results, operands, i16::MIN, i16::MAX),
// TODO: need to do something to get this to be represented as signed?
Instruction::I32FromU32 | Instruction::I32FromUsize => {
Instruction::I32FromU32 => {
self.clamp(results, operands, u32::MIN, u32::MAX);
}
Instruction::I32FromS32 => self.clamp(results, operands, i32::MIN, i32::MAX),
Expand Down
12 changes: 3 additions & 9 deletions crates/gen-wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ impl RustGenerator for Wasmtime {
&mut self.types
}

fn print_usize(&mut self) {
self.src.push_str("u32");
}

fn print_pointer(&mut self, _iface: &Interface, _const_: bool, _ty: &Type) {
self.push_str("u32");
}
Expand Down Expand Up @@ -1434,11 +1430,9 @@ impl Bindgen for FunctionBindgen<'_> {
let s = operands.pop().unwrap();
results.push(format!("wit_bindgen_wasmtime::rt::as_i64({})", s));
}
Instruction::I32FromUsize
| Instruction::I32FromChar
Instruction::I32FromChar
| Instruction::I32FromU8
| Instruction::I32FromS8
| Instruction::I32FromChar8
| Instruction::I32FromU16
| Instruction::I32FromS16
| Instruction::I32FromU32
Expand All @@ -1461,13 +1455,13 @@ impl Bindgen for FunctionBindgen<'_> {
// necessary since we could chop bits off this should be more
// forward-compatible with any future changes.
Instruction::S8FromI32 => try_from("i8", operands, results),
Instruction::Char8FromI32 | Instruction::U8FromI32 => try_from("u8", operands, results),
Instruction::U8FromI32 => try_from("u8", operands, results),
Instruction::S16FromI32 => try_from("i16", operands, results),
Instruction::U16FromI32 => try_from("u16", operands, results),

// Casts of the same bit width simply use `as` since we're just
// reinterpreting the bits already there.
Instruction::U32FromI32 | Instruction::UsizeFromI32 => top_as("u32"),
Instruction::U32FromI32 => top_as("u32"),
Instruction::U64FromI64 => top_as("u64"),

Instruction::CharFromI32 => {
Expand Down
28 changes: 5 additions & 23 deletions crates/parser/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ def_instruction! {
I32FromU8 : [1] => [1],
/// Converts an interface type `s8` value to a wasm `i32`.
I32FromS8 : [1] => [1],
/// Converts a language-specific `usize` value to a wasm `i32`.
I32FromUsize : [1] => [1],
/// Converts a language-specific C `char` value to a wasm `i32`.
I32FromChar8 : [1] => [1],
/// Conversion an interface type `f32` value to a wasm `f32`.
///
/// This may be a noop for some implementations, but it's here in case the
Expand Down Expand Up @@ -252,12 +248,6 @@ def_instruction! {
If32FromF32 : [1] => [1],
/// Converts a native wasm `f64` to an interface type `f64`.
If64FromF64 : [1] => [1],
/// Converts a native wasm `i32` to a language-specific C `char`.
///
/// This will truncate the upper bits of the `i32`.
Char8FromI32 : [1] => [1],
/// Converts a native wasm `i32` to a language-specific `usize`.
UsizeFromI32 : [1] => [1],

// Handles

Expand Down Expand Up @@ -854,9 +844,7 @@ impl Interface {
| Type::S32
| Type::U32
| Type::Char
| Type::Handle(_)
| Type::CChar
| Type::Usize => result.push(WasmType::I32),
| Type::Handle(_) => result.push(WasmType::I32),

Type::U64 | Type::S64 => result.push(WasmType::I64),
Type::F32 => result.push(WasmType::F32),
Expand Down Expand Up @@ -1303,12 +1291,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
match *ty {
Type::S8 => self.emit(&I32FromS8),
Type::U8 => self.emit(&I32FromU8),
Type::CChar => self.emit(&I32FromChar8),
Type::S16 => self.emit(&I32FromS16),
Type::U16 => self.emit(&I32FromU16),
Type::S32 => self.emit(&I32FromS32),
Type::U32 => self.emit(&I32FromU32),
Type::Usize => self.emit(&I32FromUsize),
Type::S64 => self.emit(&I64FromS64),
Type::U64 => self.emit(&I64FromU64),
Type::Char => self.emit(&I32FromChar),
Expand Down Expand Up @@ -1478,12 +1464,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {

match *ty {
Type::S8 => self.emit(&S8FromI32),
Type::CChar => self.emit(&Char8FromI32),
Type::U8 => self.emit(&U8FromI32),
Type::S16 => self.emit(&S16FromI32),
Type::U16 => self.emit(&U16FromI32),
Type::S32 => self.emit(&S32FromI32),
Type::Usize => self.emit(&UsizeFromI32),
Type::U32 => self.emit(&U32FromI32),
Type::S64 => self.emit(&S64FromI64),
Type::U64 => self.emit(&U64FromI64),
Expand Down Expand Up @@ -1617,11 +1601,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
match *ty {
// Builtin types need different flavors of storage instructions
// depending on the size of the value written.
Type::U8 | Type::S8 | Type::CChar => {
self.lower_and_emit(ty, addr, &I32Store8 { offset })
}
Type::U8 | Type::S8 => self.lower_and_emit(ty, addr, &I32Store8 { offset }),
Type::U16 | Type::S16 => self.lower_and_emit(ty, addr, &I32Store16 { offset }),
Type::U32 | Type::S32 | Type::Usize | Type::Handle(_) | Type::Char => {
Type::U32 | Type::S32 | Type::Handle(_) | Type::Char => {
self.lower_and_emit(ty, addr, &I32Store { offset })
}
Type::U64 | Type::S64 => self.lower_and_emit(ty, addr, &I64Store { offset }),
Expand Down Expand Up @@ -1729,11 +1711,11 @@ impl<'a, B: Bindgen> Generator<'a, B> {
use Instruction::*;

match *ty {
Type::U8 | Type::CChar => self.emit_and_lift(ty, addr, &I32Load8U { offset }),
Type::U8 => self.emit_and_lift(ty, addr, &I32Load8U { offset }),
Type::S8 => self.emit_and_lift(ty, addr, &I32Load8S { offset }),
Type::U16 => self.emit_and_lift(ty, addr, &I32Load16U { offset }),
Type::S16 => self.emit_and_lift(ty, addr, &I32Load16S { offset }),
Type::U32 | Type::S32 | Type::Char | Type::Usize | Type::Handle(_) => {
Type::U32 | Type::S32 | Type::Char | Type::Handle(_) => {
self.emit_and_lift(ty, addr, &I32Load { offset })
}
Type::U64 | Type::S64 => self.emit_and_lift(ty, addr, &I64Load { offset }),
Expand Down
4 changes: 0 additions & 4 deletions crates/parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ enum Type<'a> {
F32,
F64,
Char,
#[allow(dead_code)]
Usize,
#[allow(dead_code)]
CChar,
Handle(Id<'a>),
Name(Id<'a>),
List(Box<Type<'a>>),
Expand Down
2 changes: 0 additions & 2 deletions crates/parser/src/ast/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ impl Resolver {
super::Type::F32 => TypeDefKind::Type(Type::F32),
super::Type::F64 => TypeDefKind::Type(Type::F64),
super::Type::Char => TypeDefKind::Type(Type::Char),
super::Type::CChar => TypeDefKind::Type(Type::CChar),
super::Type::Usize => TypeDefKind::Type(Type::Usize),
super::Type::Handle(resource) => {
let id = match self.resource_lookup.get(&*resource.name) {
Some(id) => *id,
Expand Down
6 changes: 1 addition & 5 deletions crates/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ pub enum Type {
F32,
F64,
Char,
CChar,
Usize,
Handle(ResourceId),
Id(TypeId),
}
Expand Down Expand Up @@ -433,9 +431,7 @@ impl Interface {
| Type::U64
| Type::S64
| Type::F32
| Type::F64
| Type::CChar
| Type::Usize => true,
| Type::F64 => true,

Type::Char | Type::Handle(_) => false,

Expand Down
8 changes: 4 additions & 4 deletions crates/parser/src/sizealign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ impl SizeAlign {

pub fn size(&self, ty: &Type) -> usize {
match ty {
Type::U8 | Type::S8 | Type::CChar => 1,
Type::U8 | Type::S8 => 1,
Type::U16 | Type::S16 => 2,
Type::U32 | Type::S32 | Type::F32 | Type::Char | Type::Handle(_) | Type::Usize => 4,
Type::U32 | Type::S32 | Type::F32 | Type::Char | Type::Handle(_) => 4,
Type::U64 | Type::S64 | Type::F64 => 8,
Type::Id(id) => self.map[id.index()].0,
}
}

pub fn align(&self, ty: &Type) -> usize {
match ty {
Type::U8 | Type::S8 | Type::CChar => 1,
Type::U8 | Type::S8 => 1,
Type::U16 | Type::S16 => 2,
Type::U32 | Type::S32 | Type::F32 | Type::Char | Type::Handle(_) | Type::Usize => 4,
Type::U32 | Type::S32 | Type::F32 | Type::Char | Type::Handle(_) => 4,
Type::U64 | Type::S64 | Type::F64 => 8,
Type::Id(id) => self.map[id.index()].1,
}
Expand Down
Loading