Skip to content

Commit

Permalink
deserial data up to </Encodings>
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacy Koper <[email protected]>
  • Loading branch information
heavyrain266 committed Aug 28, 2024
1 parent 7a627bd commit 15b5bd2
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 3 deletions.
73 changes: 73 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
52 changes: 52 additions & 0 deletions src/decode/encodings/cond.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use serde::Deserialize;


#[derive(Debug, Default, PartialEq, Deserialize)]
pub struct SubExpressions {
expression: Option<Vec<Expression>>,
}

#[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<String>,

operator: Option<String>,
subexpressions: Option<SubExpressions>,
label: Option<String>,
value: Option<i8>,
value_type: Option<ValueType>,
}

#[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<EncodingCondition>,
}
24 changes: 24 additions & 0 deletions src/decode/encodings/ident.rs
Original file line number Diff line number Diff line change
@@ -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<EncodingIdentifier>
}
45 changes: 45 additions & 0 deletions src/decode/encodings/microcode.rs
Original file line number Diff line number Diff line change
@@ -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<Field>,
}

#[derive(Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct MicrocodeFormat {
bit_map: BitMap,
}
34 changes: 34 additions & 0 deletions src/decode/encodings/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ident::EncodingIdentifiers>,
#[serde(rename = "EncodingConditions")]
conditions: Vec<cond::EncodingConditions>,

#[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<Encoding>,
}
37 changes: 37 additions & 0 deletions src/decode/mod.rs
Original file line number Diff line number Diff line change
@@ -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<time::Date>,
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,
}
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
mod decode;


fn main() -> Result<(), Box<dyn std::error::Error>> {
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(());
}

0 comments on commit 15b5bd2

Please sign in to comment.