From 0cc22c8c657e3cd7bac683e566ea21bbba7cc358 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 8 Apr 2021 20:20:17 -0400 Subject: [PATCH] [spv-in] move the matrix decoration handling to structure parsing --- src/front/spv/mod.rs | 54 +++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 6a4164665d..c3df4a8af8 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -2301,36 +2301,14 @@ impl> Parser { let vector_type_lookup = self.lookup_type.lookup(vector_type_id)?; let inner = match module.types[vector_type_lookup.handle].inner { - crate::TypeInner::Vector { size, width, .. } => { - if let Some(Decoration { - matrix_stride: Some(stride), - .. - }) = decor - { - if stride.get() != (size as u32) * (width as u32) { - return Err(Error::UnsupportedMatrixStride(stride.get())); - } - } - crate::TypeInner::Matrix { - columns: map_vector_size(num_columns)?, - rows: size, - width, - } - } + crate::TypeInner::Vector { size, width, .. } => crate::TypeInner::Matrix { + columns: map_vector_size(num_columns)?, + rows: size, + width, + }, _ => return Err(Error::InvalidInnerType(vector_type_id)), }; - if let Some(Decoration { - matrix_major: Some(ref major), - .. - }) = decor - { - match *major { - Majority::Column => (), - Majority::Row => return Err(Error::UnsupportedRowMajorMatrix), - } - } - self.lookup_type.insert( id, LookupType { @@ -2496,17 +2474,37 @@ impl> Parser { .future_member_decor .remove(&(id, i)) .unwrap_or_default(); - let binding = decor.io_binding().ok(); + let binding = decor.io_binding().ok(); let offset = match decor.offset { Some(offset) => offset, None => match members.last() { Some(member) => { + //TODO: is this needed? + // If offsets are required, we can just put 0 here member.offset + module.types[member.ty].inner.span(&module.constants) } None => 0, }, }; + + if let crate::TypeInner::Matrix { + columns: _, + rows, + width, + } = module.types[ty].inner + { + if let Some(stride) = decor.matrix_stride { + if stride.get() != (rows as u32) * (width as u32) { + return Err(Error::UnsupportedMatrixStride(stride.get())); + } + } + match decor.matrix_major { + None | Some(Majority::Column) => (), + Some(Majority::Row) => return Err(Error::UnsupportedRowMajorMatrix), + } + } + members.push(crate::StructMember { name: decor.name, ty,