mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-10 05:38:18 +02:00
kraid/isa: Specially handle small_constant_t
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41841>
This commit is contained in:
parent
348fd5d3e0
commit
4c1d579db4
3 changed files with 61 additions and 1 deletions
|
|
@ -64,6 +64,12 @@ pub trait TryDecode<T>: Sized {
|
|||
fn try_decode(value: T, arch: u8) -> Result<Self, Self::Error>;
|
||||
}
|
||||
|
||||
pub trait SmallConstantTable: TryDecode<u8> {
|
||||
const TABLE_LEN: u8;
|
||||
fn name(&self) -> &'static str;
|
||||
fn const_value(&self) -> u32;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct EncodedSrc<S: Copy> {
|
||||
pub encoded: u8,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub struct EnumValue {
|
|||
pub arch: ArchSet,
|
||||
pub canonical: bool,
|
||||
pub value: u8,
|
||||
pub const_value: Option<u32>,
|
||||
}
|
||||
|
||||
impl EnumValue {
|
||||
|
|
@ -38,6 +39,7 @@ impl EnumValue {
|
|||
.get_u8_attr("value")
|
||||
.ok_or(err("Enum value has no value"))?
|
||||
.into(),
|
||||
const_value: xml.get_u32_attr("const_value"),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -245,6 +247,40 @@ impl Enum {
|
|||
});
|
||||
}
|
||||
|
||||
if self.name == "small_constant_t" {
|
||||
let mut const_name_cases_ts = TokenStream2::new();
|
||||
let mut const_value_cases_ts = TokenStream2::new();
|
||||
for v in self.values.values() {
|
||||
let v_name = &v.name;
|
||||
let v_ident = &v.ident;
|
||||
let const_value = v.const_value.unwrap();
|
||||
const_name_cases_ts.extend(quote! {
|
||||
#e_ident::#v_ident => #v_name,
|
||||
});
|
||||
const_value_cases_ts.extend(quote! {
|
||||
#e_ident::#v_ident => #const_value,
|
||||
});
|
||||
}
|
||||
let table_len = max_value + 1;
|
||||
ts.extend(quote! {
|
||||
impl SmallConstantTable for #e_ident {
|
||||
const TABLE_LEN: u8 = #table_len;
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
match self {
|
||||
#const_name_cases_ts
|
||||
}
|
||||
}
|
||||
|
||||
fn const_value(&self) -> u32 {
|
||||
match self {
|
||||
#const_value_cases_ts
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add a per-value arch array which we'll use for TryEncode/Decode
|
||||
|
||||
if unique_values {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,16 @@ use xml::attribute::OwnedAttribute;
|
|||
use xml::name::OwnedName;
|
||||
use xml::reader::{EventReader, XmlEvent};
|
||||
|
||||
fn split_str_radix(s: &str) -> (&str, u32) {
|
||||
if s.starts_with("0x") || s.starts_with("0X") {
|
||||
(&s[2..], 16)
|
||||
} else if s.starts_with("0b") || s.starts_with("0B") {
|
||||
(&s[2..], 2)
|
||||
} else {
|
||||
(s, 10)
|
||||
}
|
||||
}
|
||||
|
||||
/// A very simpl DOM
|
||||
pub struct XmlElement {
|
||||
pub name: OwnedName,
|
||||
|
|
@ -73,7 +83,15 @@ impl XmlElement {
|
|||
|
||||
pub fn get_u8_attr(&self, name: &str) -> Option<u8> {
|
||||
let s = self.attrs.get(name)?;
|
||||
let u = u8::from_str_radix(s, 10).unwrap();
|
||||
let (s, r) = split_str_radix(s);
|
||||
let u = u8::from_str_radix(s, r).unwrap();
|
||||
Some(u)
|
||||
}
|
||||
|
||||
pub fn get_u32_attr(&self, name: &str) -> Option<u32> {
|
||||
let s = self.attrs.get(name)?;
|
||||
let (s, r) = split_str_radix(s);
|
||||
let u = u32::from_str_radix(s, r).unwrap();
|
||||
Some(u)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue