Change how flags are stored in serialized modules.
This commit changes how both the shared flags and ISA flags are stored in the serialized module to detect incompatibilities when a serialized module is instantiated. It improves the error reporting when a compiled module has mismatched shared flags.
This commit is contained in:
@@ -72,6 +72,50 @@ pub struct Setting {
|
||||
pub values: Option<&'static [&'static str]>,
|
||||
}
|
||||
|
||||
/// Represents a setting value.
|
||||
///
|
||||
/// This is used for iterating values in `Flags`.
|
||||
pub struct Value {
|
||||
/// The name of the setting associated with this value.
|
||||
pub name: &'static str,
|
||||
pub(crate) detail: detail::Detail,
|
||||
pub(crate) values: Option<&'static [&'static str]>,
|
||||
pub(crate) value: u8,
|
||||
}
|
||||
|
||||
impl Value {
|
||||
/// Gets the kind of setting.
|
||||
pub fn kind(&self) -> SettingKind {
|
||||
match &self.detail {
|
||||
detail::Detail::Enum { .. } => SettingKind::Enum,
|
||||
detail::Detail::Num => SettingKind::Num,
|
||||
detail::Detail::Bool { .. } => SettingKind::Bool,
|
||||
detail::Detail::Preset => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the enum value if the value is from an enum setting.
|
||||
pub fn as_enum(&self) -> Option<&'static str> {
|
||||
self.values.map(|v| v[self.value as usize])
|
||||
}
|
||||
|
||||
/// Gets the numerical value if the value is from a num setting.
|
||||
pub fn as_num(&self) -> Option<u8> {
|
||||
match &self.detail {
|
||||
detail::Detail::Num => Some(self.value),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the boolean value if the value is from a boolean setting.
|
||||
pub fn as_bool(&self) -> Option<bool> {
|
||||
match &self.detail {
|
||||
detail::Detail::Bool { bit } => Some(self.value & (1 << bit) != 0),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect settings values based on a template.
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct Builder {
|
||||
|
||||
Reference in New Issue
Block a user