add type_flags to ModuleInfo

This commit is contained in:
teoxoy 2023-01-05 13:40:47 +01:00 committed by Teodor Tanasoaia
parent a42857d291
commit 85e3b0844f
4 changed files with 126 additions and 5 deletions

View File

@ -124,10 +124,18 @@ bitflags::bitflags! {
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct ModuleInfo {
type_flags: Vec<TypeFlags>,
functions: Vec<FunctionInfo>,
entry_points: Vec<FunctionInfo>,
}
impl ops::Index<Handle<crate::Type>> for ModuleInfo {
type Output = TypeFlags;
fn index(&self, handle: Handle<crate::Type>) -> &Self::Output {
&self.type_flags[handle.index()]
}
}
impl ops::Index<Handle<crate::Function>> for ModuleInfo {
type Output = FunctionInfo;
fn index(&self, handle: Handle<crate::Function>) -> &Self::Output {
@ -346,6 +354,12 @@ impl Validator {
}
}
let mut mod_info = ModuleInfo {
type_flags: Vec::with_capacity(module.types.len()),
functions: Vec::with_capacity(module.functions.len()),
entry_points: Vec::with_capacity(module.entry_points.len()),
};
for (handle, ty) in module.types.iter() {
let ty_info = self
.validate_type(handle, &module.types, &module.constants)
@ -357,6 +371,7 @@ impl Validator {
}
.with_span_handle(handle, &module.types)
})?;
mod_info.type_flags.push(ty_info.flags);
self.types[handle.index()] = ty_info;
}
@ -373,11 +388,6 @@ impl Validator {
})?;
}
let mut mod_info = ModuleInfo {
functions: Vec::with_capacity(module.functions.len()),
entry_points: Vec::with_capacity(module.entry_points.len()),
};
for (handle, fun) in module.functions.iter() {
match self.validate_function(fun, module, &mod_info, false) {
Ok(info) => mod_info.functions.push(info),

View File

@ -9,6 +9,8 @@ bitflags::bitflags! {
///
/// [`Type`]: crate::Type
/// [`Validator`]: crate::valid::Validator
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[repr(transparent)]
pub struct TypeFlags: u8 {
/// Can be used for data variables.

View File

@ -1,4 +1,18 @@
(
type_flags: [
(
bits: 223,
),
(
bits: 21,
),
(
bits: 21,
),
(
bits: 223,
),
],
functions: [
(
flags: (

View File

@ -1,4 +1,99 @@
(
type_flags: [
(
bits: 223,
),
(
bits: 223,
),
(
bits: 223,
),
(
bits: 223,
),
(
bits: 199,
),
(
bits: 223,
),
(
bits: 64,
),
(
bits: 64,
),
(
bits: 223,
),
(
bits: 70,
),
(
bits: 70,
),
(
bits: 223,
),
(
bits: 223,
),
(
bits: 6,
),
(
bits: 6,
),
(
bits: 6,
),
(
bits: 215,
),
(
bits: 215,
),
(
bits: 21,
),
(
bits: 21,
),
(
bits: 6,
),
(
bits: 6,
),
(
bits: 6,
),
(
bits: 6,
),
(
bits: 70,
),
(
bits: 70,
),
(
bits: 6,
),
(
bits: 6,
),
(
bits: 70,
),
(
bits: 64,
),
(
bits: 64,
),
],
functions: [
(
flags: (