diff --git a/Cargo.lock b/Cargo.lock index 132d24c..41cfe73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,19 +2,54 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + [[package]] name = "quick-xml" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc" dependencies = [ + "encoding_rs", "memchr", + "serde", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", ] [[package]] @@ -22,4 +57,42 @@ name = "rdna3_isa" version = "0.1.0" dependencies = [ "quick-xml", + "serde", ] + +[[package]] +name = "serde" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/Cargo.toml b/Cargo.toml index b7ec7de..5e63379 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,12 @@ version = "0.1.0" edition = "2021" [dependencies] -quick-xml = "0.36.1" +# time = { version = "0.3.36", features = ["serde", "serde-human-readable"] } + +[dependencies.serde] +version = "1.0.209" +features = ["derive"] + +[dependencies.quick-xml] +version = "0.36.1" +features = ["serialize", "encoding"] diff --git a/src/decode/encodings/cond.rs b/src/decode/encodings/cond.rs new file mode 100644 index 0000000..3465a3c --- /dev/null +++ b/src/decode/encodings/cond.rs @@ -0,0 +1,52 @@ +use serde::Deserialize; + + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct SubExpressions { + expression: Option>, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct ValueType { + #[serde(rename = "@Name")] + name: String, + + #[serde(rename = "BaseType")] + base_type: char, + #[serde(rename = "Size")] + size: i8, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct Expression { + #[serde(rename = "@Type")] + ty: Option, + + operator: Option, + subexpressions: Option, + label: Option, + value: Option, + value_type: Option, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct ConditionExpression { + expression: Expression, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct EncodingCondition { + #[serde(rename = "ConditionName")] + name: String, + + #[serde(rename = "CondtionExpression")] + expression: ConditionExpression +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct EncodingConditions { + #[serde(rename = "EncodingCondition")] + condition: Vec, +} diff --git a/src/decode/encodings/ident.rs b/src/decode/encodings/ident.rs new file mode 100644 index 0000000..aa2e765 --- /dev/null +++ b/src/decode/encodings/ident.rs @@ -0,0 +1,24 @@ +use serde::Deserialize; + + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct EncodingIdentifier { + #[serde(rename = "@Radix")] + radix: i8, + #[serde(rename = "$text")] + text: String, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct EncodingIdentifierMask { + #[serde(rename = "@Radix")] + radix: i8, + #[serde(rename = "$text")] + text: String, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct EncodingIdentifiers { + #[serde(rename = "EncodingIdentifier")] + identifier: Vec +} diff --git a/src/decode/encodings/microcode.rs b/src/decode/encodings/microcode.rs new file mode 100644 index 0000000..039e37c --- /dev/null +++ b/src/decode/encodings/microcode.rs @@ -0,0 +1,45 @@ +use serde::Deserialize; + + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct Range { + #[serde(rename = "@Order")] + order: i8, + #[serde(rename = "BitCount")] + bit_count: i8, + #[serde(rename = "BitOffset")] + bit_offset: i8 +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct BitLayout { + #[serde(rename = "@RangeCount")] + range_count: i8, + #[serde(rename = "Range")] + range: Range, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct Field { + #[serde(rename = "@IsConditional")] + is_conditional: bool, + + #[serde(rename = "FieldName")] + field_name: String, + #[serde(rename = "Description")] + description: String, + #[serde(rename = "BitLayout")] + bit_layout: BitLayout, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct BitMap { + field: Vec, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct MicrocodeFormat { + bit_map: BitMap, +} diff --git a/src/decode/encodings/mod.rs b/src/decode/encodings/mod.rs new file mode 100644 index 0000000..3461d94 --- /dev/null +++ b/src/decode/encodings/mod.rs @@ -0,0 +1,34 @@ +mod cond; +mod ident; +mod microcode; + + +use serde::Deserialize; + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct Encoding { + #[serde(rename = "@Order")] + order: i8, + + #[serde(rename = "EncodingName")] + name: String, + #[serde(rename = "BitCount")] + bit_count: i8, + #[serde(rename = "EncodingIdentifierMask")] + identifier_mask: ident::EncodingIdentifierMask, + #[serde(rename = "EncodingIdentifiers")] + identifiers: Vec, + #[serde(rename = "EncodingConditions")] + conditions: Vec, + + #[serde(rename = "Description")] + description: String, + #[serde(rename = "MicrocodeFormat")] + microcode_format: microcode::MicrocodeFormat, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct Encodings { + encoding: Vec, +} diff --git a/src/decode/mod.rs b/src/decode/mod.rs new file mode 100644 index 0000000..ee1045d --- /dev/null +++ b/src/decode/mod.rs @@ -0,0 +1,37 @@ +mod encodings; + +use serde::Deserialize; + + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct Spec { + #[serde(rename = "Document")] + document: Document, + #[serde(rename = "ISA")] + isa: ISA, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(default, rename_all = "PascalCase")] +pub struct Document { + copyright: String, + sensitivity: String, + // FIXME: figure out how to make it parse date... (returns None) + // release_data: Option, + schema_version: String, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +#[serde(default, rename_all = "PascalCase")] +pub struct ISA { + architecture: Architecture, + encodings: encodings::Encodings, +} + +#[derive(Debug, Default, PartialEq, Deserialize)] +pub struct Architecture { + #[serde(rename = "ArchitectureName")] + name: String, + #[serde(rename = "ArchitectureId")] + id: String, +} diff --git a/src/main.rs b/src/main.rs index b210d63..f3d04ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,14 @@ +mod decode; + + fn main() -> Result<(), Box> { - let spec: String = std::fs::read_to_string("./spec/amdgpu_isa_rdna3.xml")?; + let path: String = std::fs::read_to_string( + format!("{}/spec/amdgpu_isa_rdna3.xml", env!("CARGO_MANIFEST_DIR")) + )?; + + let spec: decode::Spec = quick_xml::de::from_str(path.as_str())?; - println!("{:?}", spec); + println!("{:#?}", spec); return Ok(()); }