diff --git a/Cargo.lock b/Cargo.lock index 41cfe73..3817ea3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "encoding_rs" version = "0.8.34" @@ -17,12 +27,30 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -58,6 +86,7 @@ version = "0.1.0" dependencies = [ "quick-xml", "serde", + "time", ] [[package]] @@ -91,6 +120,37 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "unicode-ident" version = "1.0.12" diff --git a/Cargo.toml b/Cargo.toml index 5e63379..88cd8b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -# time = { version = "0.3.36", features = ["serde", "serde-human-readable"] } +time = { version = "0.3.36", features = ["serde", "serde-human-readable"] } [dependencies.serde] version = "1.0.209" diff --git a/src/dataformats/mod.rs b/src/dataformats/mod.rs index 7ace226..4a003d3 100644 --- a/src/dataformats/mod.rs +++ b/src/dataformats/mod.rs @@ -1,6 +1,7 @@ use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] + +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Range { #[serde(rename = "@Order")] @@ -10,7 +11,7 @@ pub struct Range { bit_offset: i8, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct BitLayout { #[serde(rename = "@RangeCount")] @@ -18,7 +19,7 @@ pub struct BitLayout { range: Range, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Field { #[serde(rename = "@Signedness")] @@ -28,7 +29,7 @@ pub struct Field { bit_layout: BitLayout, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct BitMap { #[serde(rename = "@Order")] @@ -37,7 +38,7 @@ pub struct BitMap { field: Option, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct DataFormat { pub data_format_name: String, @@ -48,7 +49,7 @@ pub struct DataFormat { pub data_attributes: BitMap, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct DataFormats { pub data_format: Vec diff --git a/src/encodings/cond.rs b/src/encodings/cond.rs index 6ff21d8..3c9aa74 100644 --- a/src/encodings/cond.rs +++ b/src/encodings/cond.rs @@ -1,14 +1,14 @@ use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct SubExpressions { pub expression: Vec, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct ValueType { #[serde(rename = "@Name")] pub name: String, @@ -17,8 +17,8 @@ pub struct ValueType { pub size: i8, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Expression { #[serde(rename = "@Type")] pub ty: Option, @@ -30,21 +30,21 @@ pub struct Expression { pub value_type: Option, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct ConditionExpression { pub expression: Expression, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct EncodingCondition { pub condition_name: String, pub condtion_expression: ConditionExpression, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct EncodingConditions { pub encoding_condition: Vec, } diff --git a/src/encodings/ident.rs b/src/encodings/ident.rs index c8cc2bd..b102665 100644 --- a/src/encodings/ident.rs +++ b/src/encodings/ident.rs @@ -1,7 +1,7 @@ use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] pub struct EncodingIdentifier { #[serde(rename = "@Radix")] pub radix: i8, @@ -9,7 +9,7 @@ pub struct EncodingIdentifier { pub text: String, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] pub struct EncodingIdentifierMask { #[serde(rename = "@Radix")] pub radix: i8, @@ -17,8 +17,8 @@ pub struct EncodingIdentifierMask { pub text: String, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct EncodingIdentifiers { pub encoding_identifier: Vec, } diff --git a/src/encodings/microcode.rs b/src/encodings/microcode.rs index ad3570d..83b03b8 100644 --- a/src/encodings/microcode.rs +++ b/src/encodings/microcode.rs @@ -1,7 +1,7 @@ use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Range { #[serde(rename = "@Order")] @@ -10,7 +10,7 @@ pub struct Range { pub bit_offset: i8, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct BitLayout { #[serde(rename = "@RangeCount")] @@ -18,8 +18,8 @@ pub struct BitLayout { pub range: Range, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Field { #[serde(rename = "@IsConditional")] pub is_conditional: bool, @@ -29,14 +29,14 @@ pub struct Field { pub bit_layout: BitLayout, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct BitMap { pub field: Vec, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct MicrocodeFormat { pub bit_map: BitMap, } diff --git a/src/encodings/mod.rs b/src/encodings/mod.rs index eb0be20..ab19615 100644 --- a/src/encodings/mod.rs +++ b/src/encodings/mod.rs @@ -5,8 +5,8 @@ pub mod microcode; use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Encoding { #[serde(rename = "@Order")] pub order: i8, @@ -22,8 +22,8 @@ pub struct Encoding { pub microcode_format: microcode::MicrocodeFormat, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Encodings { pub encoding: Vec, } diff --git a/src/instructions/encodings.rs b/src/instructions/encodings.rs index 2c78be2..ad25b35 100644 --- a/src/instructions/encodings.rs +++ b/src/instructions/encodings.rs @@ -1,7 +1,7 @@ use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Operand { #[serde(rename = "@Input")] @@ -21,7 +21,7 @@ pub struct Operand { pub operand_size: i16, } -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct Operands { pub operand: Option>, @@ -35,8 +35,8 @@ pub struct Opcode { pub btext: i16, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct InstructionEncoding { pub encoding_name: String, pub encoding_condition: String, @@ -45,8 +45,8 @@ pub struct InstructionEncoding { } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct InstructionEncodings { pub instruction_encoding: Vec, } diff --git a/src/instructions/mod.rs b/src/instructions/mod.rs index db3b36c..a407cae 100644 --- a/src/instructions/mod.rs +++ b/src/instructions/mod.rs @@ -3,8 +3,8 @@ mod encodings; use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct InstructionFlags { pub is_branch: bool, pub is_conditional_branch: bool, @@ -13,8 +13,8 @@ pub struct InstructionFlags { pub is_immediately_executed: bool, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Instruction { pub instruction_name: String, pub description: String, @@ -23,8 +23,8 @@ pub struct Instruction { pub functional_group: crate::FunctionalGroup, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Instructions { pub instruction: Vec, } diff --git a/src/lib.rs b/src/lib.rs index bf1075c..0d433af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,12 @@ pub mod dataformats; pub mod encodings; pub mod instructions; +pub mod operand_types; use serde::Deserialize; -#[derive(Debug, Default, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Deserialize)] pub struct Spec { #[serde(rename = "Document")] pub document: Document, @@ -13,43 +14,46 @@ pub struct Spec { pub isa: ISA, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Document { pub copyright: String, pub sensitivity: String, - // FIXME: figure out how to make it parse date... (returns None) - // pub release_data: Option, + // FIXME: Error: Custom("a character literal was not valid") + // + // #[serde(with = "time::serde::rfc3339")] + // pub release_date: time::OffsetDateTime, pub schema_version: String, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct FunctionalGroups { pub functional_group: Vec, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct FunctionalGroup { pub name: String, pub subgroup: Option, pub description: Option, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct Architecture { pub architecture_name: String, pub architecture_id: String, } -#[derive(Debug, Default, PartialEq, Deserialize)] -#[serde(default, rename_all = "PascalCase")] +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct ISA { pub architecture: Architecture, pub encodings: encodings::Encodings, pub instructions: instructions::Instructions, pub data_formats: dataformats::DataFormats, + pub operand_types: operand_types::OperandTypes, pub functional_groups: FunctionalGroups, } diff --git a/src/operand_types/mod.rs b/src/operand_types/mod.rs new file mode 100644 index 0000000..cb5e4cb --- /dev/null +++ b/src/operand_types/mod.rs @@ -0,0 +1,80 @@ +use serde::Deserialize; + + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct Range { + #[serde(rename = "@Order")] + pub order: i8, + pub bit_count: i8, + pub bit_offset: i8, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct BitLayout { + #[serde(rename = "@RangeCount")] + pub range_count: i8, + pub range: Range, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct PredefinedValue { + pub name: String, + pub description: String, + pub value: i16, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct FieldPredefinedValues { + pub predefined_value: Vec, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct Field { + #[serde(rename = "@IsConditional")] + pub is_conditional: bool, + + pub field_name: String, + pub description: String, + pub bit_layout: BitLayout, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct BitMap { + pub field: Vec, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct MicrocodeFormat { + pub bit_map: BitMap, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct OperandPredefinedValues { + predefined_value: Vec, +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct OperandType { + #[serde(rename = "@IsPartitioned")] + pub is_partitioned: bool, + + pub operand_type_name: String, + pub description: String, + pub operand_predefined_values: Option, + pub microcode_format: Option +} + +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct OperandTypes { + pub operand_type: Vec, +}