Skip to content

Split model into port and evaluator structs#169

Open
icewind1991 wants to merge 8 commits into
ethanuppal:mainfrom
icewind1991:pin-structs
Open

Split model into port and evaluator structs#169
icewind1991 wants to merge 8 commits into
ethanuppal:mainfrom
icewind1991:pin-structs

Conversation

@icewind1991

@icewind1991 icewind1991 commented Dec 12, 2025

Copy link
Copy Markdown
  • split out model ptr into a ModelRef struct for easier reuse
  • split model into separate pins and evaluator structs so it can be split

todo:

  • re-add >64bit ports
  • dynamic ports

The port structs interface directly with state in the verilator model

Async runtime implementation made possible with this api: https://codeberg.org/icewind/marlin_async/src/branch/pin-structs

The main api different for users not doing anything fancy is doing model.input_port.set(1) instead of model.input_port = 1 and let val = model.output_port.get() instead of let val = model.output_port.

In exchange we get the port direction enforced by the type system and the ability to split the model into separate parts and move individual pins into higher level constructs.

An example of a higher level construct this makes possible is:

pub struct UartRx<'ctx> {
    pub has_out: OutputPort<'ctx, u8>,
    pub out_val: OutputPort<'ctx, u8>,
    pub clear: InputPort<'ctx, u8>,
    pub waiter: Waiter, // from https://codeberg.org/icewind/marlin_async
}

impl UartRx<'_> {
    pub async fn recv(&mut self) -> u8 {
        ...
    }
}

that can then be used as a high level api for reading serial output from a model while being free to touch the other ports independently.

@icewind1991 icewind1991 changed the title Split model into pin and evaluator structs Split model into port and evaluator structs Dec 12, 2025
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991

Copy link
Copy Markdown
Author

Re-added support for wide ports

Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991

Copy link
Copy Markdown
Author

All features should work again, examples and documentation is updated. So this should be good for review now.

@icewind1991
icewind1991 marked this pull request as ready for review December 21, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant