From 5ba17f6b11a993cb169791bd9443188cd11cad71 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Mon, 16 Dec 2019 20:14:59 -0600 Subject: [PATCH 01/10] add pattern module --- rust/origen/src/core/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/origen/src/core/mod.rs b/rust/origen/src/core/mod.rs index 40cb4eb4..b5e126f4 100644 --- a/rust/origen/src/core/mod.rs +++ b/rust/origen/src/core/mod.rs @@ -6,3 +6,4 @@ pub mod os; pub mod status; pub mod term; pub mod utility; +pub mod pattern; From 0dd35c385b8bbcca43f0e32f4159636ae132102f Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Mon, 16 Dec 2019 20:15:26 -0600 Subject: [PATCH 02/10] a few initial pattern action stucts/enums --- rust/origen/src/core/pattern/action.rs | 14 +++++++++ rust/origen/src/core/pattern/mod.rs | 3 ++ rust/origen/src/core/pattern/operation.rs | 38 +++++++++++++++++++++++ rust/origen/src/core/pattern/pinaction.rs | 21 +++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 rust/origen/src/core/pattern/action.rs create mode 100644 rust/origen/src/core/pattern/mod.rs create mode 100644 rust/origen/src/core/pattern/operation.rs create mode 100644 rust/origen/src/core/pattern/pinaction.rs diff --git a/rust/origen/src/core/pattern/action.rs b/rust/origen/src/core/pattern/action.rs new file mode 100644 index 00000000..21d3637c --- /dev/null +++ b/rust/origen/src/core/pattern/action.rs @@ -0,0 +1,14 @@ +//! Defines the set of actions associated with pattern generation +// TODO: Pick a better type for data integers will not suffice for very large registers or banks of pins + +use super::operation::Operation; +use super::pinaction::PinAction; + +pub enum Action { + Pin(PinAction), + Timeset{name: String}, + Cycle{repeat: u32}, + // likely need a larger storage type for address and data + Register{name: String, address: u32, data: u32, operation: Operation, start_stop: Operation}, + Driver{name: String, operation: Operation, data: u32, size: u32, target: String, start_stop: Operation}, +} diff --git a/rust/origen/src/core/pattern/mod.rs b/rust/origen/src/core/pattern/mod.rs new file mode 100644 index 00000000..15839e77 --- /dev/null +++ b/rust/origen/src/core/pattern/mod.rs @@ -0,0 +1,3 @@ +pub mod action; +pub mod operation; +pub mod pinaction; diff --git a/rust/origen/src/core/pattern/operation.rs b/rust/origen/src/core/pattern/operation.rs new file mode 100644 index 00000000..df4b43db --- /dev/null +++ b/rust/origen/src/core/pattern/operation.rs @@ -0,0 +1,38 @@ +//! Defines the set of actions associated with pattern generation + +pub enum Operation { + Read, + Write, + Store, + Drivemem, + Start, + Stop, +} + +impl Operation { + pub fn to_string(&self) -> String { + match self { + Operation::Read => "read".to_string(), + Operation::Write => "write".to_string(), + Operation::Store => "store".to_string(), + Operation::Drivemem => "drivemem".to_string(), + Operation::Start => "start".to_string(), + Operation::Stop => "stop".to_string(), + } + } +} + +#[cfg(test)] +mod tests { + use crate::core::pattern::operation::Operation; + + #[test] + fn converts_to_string() { + assert_eq!(Operation::Read.to_string(), "read"); + assert_eq!(Operation::Write.to_string(), "write"); + assert_eq!(Operation::Store.to_string(), "store"); + assert_eq!(Operation::Drivemem.to_string(), "drivemem"); + assert_eq!(Operation::Start.to_string(), "start"); + assert_eq!(Operation::Stop.to_string(), "stop"); + } +} diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs new file mode 100644 index 00000000..72671241 --- /dev/null +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -0,0 +1,21 @@ +//! Defines the set of actions associated with a pattern pin action +pub use super::operation::Operation; + +pub struct PinAction { + name: String, + data: u32, + operation: Operation, +} + +#[cfg(test)] +mod tests { + use crate::core::pattern::pinaction; + + #[test] + fn pinaction_readable() { + let pa = pinaction::PinAction { name: "porta_01".to_string(), data: 0, operation: pinaction::Operation::Read, }; + assert_eq!(pa.name, "porta_01"); + assert_eq!(pa.data, 0); + assert_eq!(pa.operation.to_string(), "read"); + } +} From a5b00fe947be2a6b03c3f2d1158ccf10333d3550 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 07:20:53 -0600 Subject: [PATCH 03/10] expanded the operation type enum --- rust/origen/src/core/pattern/operation.rs | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/rust/origen/src/core/pattern/operation.rs b/rust/origen/src/core/pattern/operation.rs index df4b43db..4f9734ef 100644 --- a/rust/origen/src/core/pattern/operation.rs +++ b/rust/origen/src/core/pattern/operation.rs @@ -1,10 +1,16 @@ -//! Defines the set of actions associated with pattern generation +//! Defines the set of operation types associated with pattern generation +// This enum will be used by all action types +// May need to be more of these and more precise names pub enum Operation { Read, Write, Store, - Drivemem, + Capture, + DriveMem, + ReadMem, + DriveFromSrc, + StoreToCap, Start, Stop, } @@ -15,7 +21,11 @@ impl Operation { Operation::Read => "read".to_string(), Operation::Write => "write".to_string(), Operation::Store => "store".to_string(), - Operation::Drivemem => "drivemem".to_string(), + Operation::Capture => "capture".to_string(), + Operation::DriveMem => "drive_mem".to_string(), + Operation::ReadMem => "read_mem".to_string(), + Operation::DriveFromSrc => "drive_from_src".to_string(), + Operation::StoreToCap => "store_to_cap".to_string(), Operation::Start => "start".to_string(), Operation::Stop => "stop".to_string(), } @@ -24,14 +34,18 @@ impl Operation { #[cfg(test)] mod tests { - use crate::core::pattern::operation::Operation; + use super::*; #[test] fn converts_to_string() { assert_eq!(Operation::Read.to_string(), "read"); assert_eq!(Operation::Write.to_string(), "write"); assert_eq!(Operation::Store.to_string(), "store"); - assert_eq!(Operation::Drivemem.to_string(), "drivemem"); + assert_eq!(Operation::Capture.to_string(), "capture"); + assert_eq!(Operation::DriveMem.to_string(), "drive_mem"); + assert_eq!(Operation::ReadMem.to_string(), "read_mem"); + assert_eq!(Operation::DriveFromSrc.to_string(), "drive_from_src"); + assert_eq!(Operation::StoreToCap.to_string(), "store_to_cap"); assert_eq!(Operation::Start.to_string(), "start"); assert_eq!(Operation::Stop.to_string(), "stop"); } From af4930b3fe3bbb5b36fced6b1c967839211e5c91 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 07:25:59 -0600 Subject: [PATCH 04/10] added comments for discussion --- rust/origen/src/core/pattern/action.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rust/origen/src/core/pattern/action.rs b/rust/origen/src/core/pattern/action.rs index 21d3637c..7b3fb0ca 100644 --- a/rust/origen/src/core/pattern/action.rs +++ b/rust/origen/src/core/pattern/action.rs @@ -1,5 +1,9 @@ //! Defines the set of actions associated with pattern generation -// TODO: Pick a better type for data integers will not suffice for very large registers or banks of pins +// TODO: Pick a better type for data. Integers will not suffice for very large registers or banks of pins +// Enum Structs will be defined for most action types to hold their associated info +// +// I envision the internal pattern storage type being a vector of type Pattern::Action +// Code processing the Pattern will use match with arms to process the type of Actions that are supported for the given output use super::operation::Operation; use super::pinaction::PinAction; @@ -8,7 +12,7 @@ pub enum Action { Pin(PinAction), Timeset{name: String}, Cycle{repeat: u32}, - // likely need a larger storage type for address and data - Register{name: String, address: u32, data: u32, operation: Operation, start_stop: Operation}, - Driver{name: String, operation: Operation, data: u32, size: u32, target: String, start_stop: Operation}, + // likely need a larger storage type for address and data, or maybe generics to provide options + // Register{name: String, address: u32, data: u32, operation: Operation, start_stop: Operation}, + // Driver{name: String, operation: Operation, data: u32, size: u32, target: String, start_stop: Operation}, } From 550c353fcb518017e80a6c52bd7e346d40c61415 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 08:49:58 -0600 Subject: [PATCH 05/10] data structure changed to string --- rust/origen/src/core/pattern/pinaction.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs index 72671241..81b3b688 100644 --- a/rust/origen/src/core/pattern/pinaction.rs +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -3,7 +3,7 @@ pub use super::operation::Operation; pub struct PinAction { name: String, - data: u32, + data: String, operation: Operation, } @@ -13,9 +13,9 @@ mod tests { #[test] fn pinaction_readable() { - let pa = pinaction::PinAction { name: "porta_01".to_string(), data: 0, operation: pinaction::Operation::Read, }; + let pa = pinaction::PinAction { name: "porta_01".to_string(), data: "0".to_string(), operation: pinaction::Operation::Read, }; assert_eq!(pa.name, "porta_01"); - assert_eq!(pa.data, 0); + assert_eq!(pa.data, "0"); assert_eq!(pa.operation.to_string(), "read"); } } From eb3039fe1c96cee60325ca7b266277fda763cdcc Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 09:11:28 -0600 Subject: [PATCH 06/10] comments and test update --- rust/origen/src/core/pattern/action.rs | 3 +++ rust/origen/src/core/pattern/pinaction.rs | 24 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/rust/origen/src/core/pattern/action.rs b/rust/origen/src/core/pattern/action.rs index 7b3fb0ca..05e498da 100644 --- a/rust/origen/src/core/pattern/action.rs +++ b/rust/origen/src/core/pattern/action.rs @@ -13,6 +13,9 @@ pub enum Action { Timeset{name: String}, Cycle{repeat: u32}, // likely need a larger storage type for address and data, or maybe generics to provide options + // These are place holders of action types as I think of them // Register{name: String, address: u32, data: u32, operation: Operation, start_stop: Operation}, // Driver{name: String, operation: Operation, data: u32, size: u32, target: String, start_stop: Operation}, + // Comment(String), + // Instrument{name: String, data: String, operation: Operation}, } diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs index 81b3b688..95b6e346 100644 --- a/rust/origen/src/core/pattern/pinaction.rs +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -7,15 +7,35 @@ pub struct PinAction { operation: Operation, } +impl PinAction { + // This exists to add window dressing to the data string. Default expected will be. + // TODO: "0x" will be added if no format designator is present. + pub fn new(name: &str, data: &str, operation: Operation) -> PinAction { + PinAction { + name: name.to_string(), + data: data.to_string(), + operation: operation, + } + } +} + #[cfg(test)] mod tests { - use crate::core::pattern::pinaction; + use super::*; #[test] fn pinaction_readable() { - let pa = pinaction::PinAction { name: "porta_01".to_string(), data: "0".to_string(), operation: pinaction::Operation::Read, }; + let pa = PinAction { name: "porta_01".to_string(), data: "0".to_string(), operation: Operation::Read, }; assert_eq!(pa.name, "porta_01"); assert_eq!(pa.data, "0"); assert_eq!(pa.operation.to_string(), "read"); } + + #[test] + fn new_creates_struct() { + let pa = PinAction::new("pingroup_name", "0x55", Operation::DriveMem); + assert_eq!(pa.name, "pingroup_name"); + assert_eq!(pa.data, "0x55"); + assert_eq!(pa.operation.to_string(), Operation::DriveMem.to_string()); + } } From d5ab34680b2868f2f0792baad21950eafd9c95a0 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 12:28:37 -0600 Subject: [PATCH 07/10] adding comments for things to be changed as more external content becomes available --- rust/origen/src/core/pattern/action.rs | 1 + rust/origen/src/core/pattern/operation.rs | 1 + rust/origen/src/core/pattern/pinaction.rs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rust/origen/src/core/pattern/action.rs b/rust/origen/src/core/pattern/action.rs index 05e498da..3b4edbc2 100644 --- a/rust/origen/src/core/pattern/action.rs +++ b/rust/origen/src/core/pattern/action.rs @@ -5,6 +5,7 @@ // I envision the internal pattern storage type being a vector of type Pattern::Action // Code processing the Pattern will use match with arms to process the type of Actions that are supported for the given output +// TODO: The operation/action type enum should come from the module that models the object (pins, regs, protocol, etc.) use super::operation::Operation; use super::pinaction::PinAction; diff --git a/rust/origen/src/core/pattern/operation.rs b/rust/origen/src/core/pattern/operation.rs index 4f9734ef..f6504e61 100644 --- a/rust/origen/src/core/pattern/operation.rs +++ b/rust/origen/src/core/pattern/operation.rs @@ -2,6 +2,7 @@ // This enum will be used by all action types // May need to be more of these and more precise names +// TODO: The operation/action type enum should come from the module that models the object (pins, regs, protocol, etc.) pub enum Operation { Read, Write, diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs index 95b6e346..38511323 100644 --- a/rust/origen/src/core/pattern/pinaction.rs +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -1,4 +1,5 @@ //! Defines the set of actions associated with a pattern pin action +// TODO: The operation/action type enum should come from the module that models the object (pins, regs, protocol, etc.) pub use super::operation::Operation; pub struct PinAction { @@ -8,7 +9,7 @@ pub struct PinAction { } impl PinAction { - // This exists to add window dressing to the data string. Default expected will be. + // This exists to add window dressing to the data string. Default expected will be hex. // TODO: "0x" will be added if no format designator is present. pub fn new(name: &str, data: &str, operation: Operation) -> PinAction { PinAction { From 14711a53be195ee39a6c2db55e4de11b76e50ccb Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 14:39:54 -0600 Subject: [PATCH 08/10] more functionality --- rust/origen/src/core/pattern/action.rs | 13 +++++++- rust/origen/src/core/pattern/actions.rs | 36 +++++++++++++++++++++++ rust/origen/src/core/pattern/mod.rs | 1 + rust/origen/src/core/pattern/pinaction.rs | 10 +++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 rust/origen/src/core/pattern/actions.rs diff --git a/rust/origen/src/core/pattern/action.rs b/rust/origen/src/core/pattern/action.rs index 3b4edbc2..6aad6172 100644 --- a/rust/origen/src/core/pattern/action.rs +++ b/rust/origen/src/core/pattern/action.rs @@ -11,7 +11,8 @@ use super::pinaction::PinAction; pub enum Action { Pin(PinAction), - Timeset{name: String}, + // Below this line are just test types for now + Timeset(String), Cycle{repeat: u32}, // likely need a larger storage type for address and data, or maybe generics to provide options // These are place holders of action types as I think of them @@ -20,3 +21,13 @@ pub enum Action { // Comment(String), // Instrument{name: String, data: String, operation: Operation}, } + +impl Action { + pub fn to_string(&self) -> String { + match self { + Action::Pin(p) => format!("PinAction -> {}", p.to_string()), + Action::Timeset(s) => format!("Timeset -> {}", s.to_string()), + Action::Cycle{repeat: r} => format!("Cycle -> repeat: {}", r.to_string()), + } + } +} \ No newline at end of file diff --git a/rust/origen/src/core/pattern/actions.rs b/rust/origen/src/core/pattern/actions.rs new file mode 100644 index 00000000..28f1540e --- /dev/null +++ b/rust/origen/src/core/pattern/actions.rs @@ -0,0 +1,36 @@ +//! Collects actions +pub use super::*; + +pub struct Actions { + list: Vec +} + +impl Actions { + pub fn new() -> Actions { + Actions { + list: Vec::new(), + } + } + + pub fn push(& mut self, pa: action::Action) { + self.list.push(pa); + } + + pub fn vec(&self) -> &Vec { + &self.list + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn actions_struct_loads_reads() { + let mut pattern_actions = Actions::new(); + pattern_actions.push(action::Action::Timeset("tp0".to_string())); + pattern_actions.push(action::Action::Pin(pinaction::PinAction::new("pa0", "1", operation::Operation::Read))); + assert_eq!((pattern_actions.vec()[0]).to_string(), "Timeset -> tp0"); + assert_eq!((pattern_actions.vec()[1]).to_string(), "PinAction -> pin: pa0, data: 1, operation: read"); + } +} \ No newline at end of file diff --git a/rust/origen/src/core/pattern/mod.rs b/rust/origen/src/core/pattern/mod.rs index 15839e77..95e4cec3 100644 --- a/rust/origen/src/core/pattern/mod.rs +++ b/rust/origen/src/core/pattern/mod.rs @@ -1,3 +1,4 @@ pub mod action; pub mod operation; pub mod pinaction; +pub mod actions; diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs index 38511323..4e16096f 100644 --- a/rust/origen/src/core/pattern/pinaction.rs +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -18,6 +18,10 @@ impl PinAction { operation: operation, } } + + pub fn to_string(&self) -> String { + format!("pin: {}, data: {}, operation: {}", self.name, self.data, self.operation.to_string()) + } } #[cfg(test)] @@ -39,4 +43,10 @@ mod tests { assert_eq!(pa.data, "0x55"); assert_eq!(pa.operation.to_string(), Operation::DriveMem.to_string()); } + + #[test] + fn converts_to_string() { + let pa = PinAction::new("pingroup_name", "0x55", Operation::DriveMem); + assert_eq!(pa.to_string(), "pin: pingroup_name, data: 0x55, operation: drive_mem"); + } } From e04b2da1bee8914c6474ff3086db7e1ab912d7b6 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Thu, 19 Dec 2019 14:57:54 -0600 Subject: [PATCH 09/10] added brief consumption example --- rust/origen/src/core/pattern/actions.rs | 22 ++++++++++++++++++++++ rust/origen/src/core/pattern/pinaction.rs | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/rust/origen/src/core/pattern/actions.rs b/rust/origen/src/core/pattern/actions.rs index 28f1540e..9652b5ac 100644 --- a/rust/origen/src/core/pattern/actions.rs +++ b/rust/origen/src/core/pattern/actions.rs @@ -33,4 +33,26 @@ mod tests { assert_eq!((pattern_actions.vec()[0]).to_string(), "Timeset -> tp0"); assert_eq!((pattern_actions.vec()[1]).to_string(), "PinAction -> pin: pa0, data: 1, operation: read"); } + + + // here is how the pattern actions would be consumed + #[test] + fn actions_can_be_consumed() { + // creating some actions + let mut pattern_actions = Actions::new(); + pattern_actions.push(action::Action::Timeset("tp0".to_string())); + pattern_actions.push(action::Action::Cycle{repeat: 35}); + pattern_actions.push(action::Action::Pin(pinaction::PinAction::new("pin1", "1", operation::Operation::Read))); + pattern_actions.push(action::Action::Pin(pinaction::PinAction::new("pin2", "0", operation::Operation::Read))); + pattern_actions.push(action::Action::Cycle{repeat: 2}); + + // consume the actions: + for op in pattern_actions.vec() { + match op { + action::Action::Pin(p) => println!("consuming stored pin action on {}", p.name.to_string()), + action::Action::Timeset(s) => println!("consuming timeset data for {}", s.to_string()), + action::Action::Cycle{repeat: r} => println!("consuming cycle action with repeat {}", r.to_string()), + } + } + } } \ No newline at end of file diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs index 4e16096f..c4bc7437 100644 --- a/rust/origen/src/core/pattern/pinaction.rs +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -3,9 +3,9 @@ pub use super::operation::Operation; pub struct PinAction { - name: String, - data: String, - operation: Operation, + pub name: String, + pub data: String, + pub operation: Operation, } impl PinAction { From 669f71643dcb1bf3d6150702212991914408a498 Mon Sep 17 00:00:00 2001 From: Paul DeRouen Date: Tue, 31 Dec 2019 09:52:27 -0600 Subject: [PATCH 10/10] updating to AST --- rust/origen/Cargo.lock | 7 +++ rust/origen/Cargo.toml | 1 + rust/origen/src/core/pattern/action.rs | 6 +-- rust/origen/src/core/pattern/actions.rs | 1 + rust/origen/src/core/pattern/ast_node.rs | 18 +++++++ rust/origen/src/core/pattern/mod.rs | 2 + rust/origen/src/core/pattern/operation.rs | 1 + rust/origen/src/core/pattern/pinaction.rs | 2 +- .../src/core/pattern/register_action.rs | 50 +++++++++++++++++++ 9 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 rust/origen/src/core/pattern/ast_node.rs create mode 100644 rust/origen/src/core/pattern/register_action.rs diff --git a/rust/origen/Cargo.lock b/rust/origen/Cargo.lock index 79ebfdf3..31f1700e 100644 --- a/rust/origen/Cargo.lock +++ b/rust/origen/Cargo.lock @@ -516,6 +516,11 @@ dependencies = [ "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "idna" version = "0.1.5" @@ -871,6 +876,7 @@ version = "2.0.0-pre0" dependencies = [ "built 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "id-arena 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "path-clean 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pathdiff 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1883,6 +1889,7 @@ dependencies = [ "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" "checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" +"checksum id-arena 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" diff --git a/rust/origen/Cargo.toml b/rust/origen/Cargo.toml index 0a1c203d..1fd2f196 100644 --- a/rust/origen/Cargo.toml +++ b/rust/origen/Cargo.toml @@ -24,6 +24,7 @@ serde = {version = "1.0", features = ["derive"]} path-clean = "0.1.0" time = "0.1.42" pyo3 = "^0.8" +id-arena = "2.2.1" [build-dependencies] built = "0.3" diff --git a/rust/origen/src/core/pattern/action.rs b/rust/origen/src/core/pattern/action.rs index 6aad6172..87cee328 100644 --- a/rust/origen/src/core/pattern/action.rs +++ b/rust/origen/src/core/pattern/action.rs @@ -1,11 +1,8 @@ //! Defines the set of actions associated with pattern generation -// TODO: Pick a better type for data. Integers will not suffice for very large registers or banks of pins +// String is used for data to allow very large (ex. 300-bit) numbers // Enum Structs will be defined for most action types to hold their associated info // -// I envision the internal pattern storage type being a vector of type Pattern::Action -// Code processing the Pattern will use match with arms to process the type of Actions that are supported for the given output -// TODO: The operation/action type enum should come from the module that models the object (pins, regs, protocol, etc.) use super::operation::Operation; use super::pinaction::PinAction; @@ -14,7 +11,6 @@ pub enum Action { // Below this line are just test types for now Timeset(String), Cycle{repeat: u32}, - // likely need a larger storage type for address and data, or maybe generics to provide options // These are place holders of action types as I think of them // Register{name: String, address: u32, data: u32, operation: Operation, start_stop: Operation}, // Driver{name: String, operation: Operation, data: u32, size: u32, target: String, start_stop: Operation}, diff --git a/rust/origen/src/core/pattern/actions.rs b/rust/origen/src/core/pattern/actions.rs index 9652b5ac..80032bb1 100644 --- a/rust/origen/src/core/pattern/actions.rs +++ b/rust/origen/src/core/pattern/actions.rs @@ -1,3 +1,4 @@ +//! This file is now obsolete and will be deleted //! Collects actions pub use super::*; diff --git a/rust/origen/src/core/pattern/ast_node.rs b/rust/origen/src/core/pattern/ast_node.rs new file mode 100644 index 00000000..8616a87c --- /dev/null +++ b/rust/origen/src/core/pattern/ast_node.rs @@ -0,0 +1,18 @@ +use id_arena::{Arena, Id}; +use super::operation::Operation; +use super::pinaction::PinAction; + +type AstNodeId = Id; + +#[derive(Debug, Eq, PartialEq)] +pub enum AstNode { + Pin(PinAction), + + // Below this line are just test types for now + Timeset(String), + Cycle{repeat: u32}, + Comment(String), + Instrument{name: String, data: String, operation: Operation}, + Register{name: String, address: u64, data: String, operation: Operation, children: Operation}, + // Driver{name: String, operation: Operation, data: u32, size: u32, target: String, start_stop: Operation}, +} \ No newline at end of file diff --git a/rust/origen/src/core/pattern/mod.rs b/rust/origen/src/core/pattern/mod.rs index 95e4cec3..5b1e8d9f 100644 --- a/rust/origen/src/core/pattern/mod.rs +++ b/rust/origen/src/core/pattern/mod.rs @@ -2,3 +2,5 @@ pub mod action; pub mod operation; pub mod pinaction; pub mod actions; +pub mod ast_node; +pub mod register_action; diff --git a/rust/origen/src/core/pattern/operation.rs b/rust/origen/src/core/pattern/operation.rs index f6504e61..1727b7fc 100644 --- a/rust/origen/src/core/pattern/operation.rs +++ b/rust/origen/src/core/pattern/operation.rs @@ -3,6 +3,7 @@ // May need to be more of these and more precise names // TODO: The operation/action type enum should come from the module that models the object (pins, regs, protocol, etc.) +#[derive(Debug, Eq, PartialEq)] pub enum Operation { Read, Write, diff --git a/rust/origen/src/core/pattern/pinaction.rs b/rust/origen/src/core/pattern/pinaction.rs index c4bc7437..cd96ce77 100644 --- a/rust/origen/src/core/pattern/pinaction.rs +++ b/rust/origen/src/core/pattern/pinaction.rs @@ -1,7 +1,7 @@ //! Defines the set of actions associated with a pattern pin action -// TODO: The operation/action type enum should come from the module that models the object (pins, regs, protocol, etc.) pub use super::operation::Operation; +#[derive(Debug, Eq, PartialEq)] pub struct PinAction { pub name: String, pub data: String, diff --git a/rust/origen/src/core/pattern/register_action.rs b/rust/origen/src/core/pattern/register_action.rs new file mode 100644 index 00000000..37221684 --- /dev/null +++ b/rust/origen/src/core/pattern/register_action.rs @@ -0,0 +1,50 @@ +//! Defines the set of actions associated with a register action +pub use super::operation::Operation; +use id_arena::Arena; +pub use super::ast_node::AstNode; + +#[derive(Debug, Eq, PartialEq)] +pub struct RegisterAction { + pub name: String, + pub address: u64, + pub data: String, + pub operation: Operation, + // register action can contain arbitrary number of child actions + pub children: Arena::, +} + +impl RegisterAction { + // This exists to add window dressing to the data string. Default expected will be hex. + // TODO: "0x" will be added if no format designator is present. + pub fn new(name: &str, address: &u64, data: &str, operation: Operation) -> RegisterAction { + RegisterAction { + name: name.to_string(), + address: *address, + data: data.to_string(), + operation: operation, + children: Arena::::new(), + } + } + + pub fn to_string(&self) -> String { + format!("register: {}, address: {}, data: {}, operation: {}, num children: {}", self.name, self.address, self.data, self.operation.to_string(), self.children.len()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn converts_to_string(){ + let ra_node = RegisterAction::new("cntrl", &300, "0x40", Operation::Read); + assert_eq!(ra_node.to_string(), "register: cntrl, address: 300, data: 0x40, operation: read, num children: 0"); + } + + #[test] + fn instantiates_new_mutable_arena() { + let mut ra_node = RegisterAction::new("cntrl", &300, "0x40", Operation::Read); + ra_node.children.alloc(AstNode::Timeset("tp0".to_string())); + assert_eq!(ra_node.children.len(), 1); + } +} \ No newline at end of file