Skip to content

tool(cleanup): add sdf_parse_attribute() functions to decrease duplication - #592

Merged
midnightveil merged 7 commits into
mainfrom
julia/parsing-cleanup
Aug 14, 2026
Merged

tool(cleanup): add sdf_parse_attribute() functions to decrease duplication#592
midnightveil merged 7 commits into
mainfrom
julia/parsing-cleanup

Conversation

@midnightveil

@midnightveil midnightveil commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Please review commit by commit.

Fixes #537.

This removes a lot of the number/bool/etc parsing logic that exists in every single sdf file, instead separating out into helper functions.

Something that could be maybe done, but hasn't been, is adding support for parsing numbers in a valid range.

Comment thread tool/microkit/src/sdf/util.rs
Comment thread tool/microkit/src/sdf/util.rs Outdated
@dreamliner787-9

dreamliner787-9 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

From body of tool(cleanup): impl ParseAttribute on PciDevice

Not sure of the best way to deal with IommuDeviceIdentifier
however in this framework. I think if I passed "config" to
parse then it might make more sense, but that means I need
an extra argument for all sdf_parse_attribute calls. Unless
it forms a part of the SystemDescription struct which
currently only contains a file, which might be a good idea.

How about we make the Config object a global? Since it is not mutated once created. In context of the wider "refactoring the tool into a library" work, I don't believe this will introduce any issues.

Alternatively, you can just not check the architecture in the parser function, and let the caller deal with architecture specific logic, as the SDF parser always know the target arch.

@midnightveil

Copy link
Copy Markdown
Collaborator Author

I think making it part of the Xml_sdf arg makes sense. It's already passed everywhere including to these functions?

I don't like globals for that. Testing become hard, function no longer pure.

Let's stop duplicating all the `sdf_parse_number` checks
around everywhere.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Somehow this was missed, so this would instead fail
at runtime. Add tests to check this.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Stop duplicating this logic everywhere.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Implement the IsNum trait via a macro to stop
duplicating the same code so often.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Previously, this was using `::parse<i64>()` or
`::parse<u64>()` which will panic with no nice error
message.

The code surrounding these should be refactored too,
as the checks about "> 0" and range checks can be
done as helpers. This is done as a later commit, for
now, it is left as 'i64' and casts are done later.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
This allows arbitrary types to work and be parsed without
needing to duplicate the code for each type.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
This means we can use the sdf_parse_attribute** functions
for PCI devices, which cleans up some code.

Not sure of the best way to deal with IommuDeviceIdentifier
however in this framework. I think if I passed "config" to
parse then it might make more sense, but that means I need
an extra argument for all sdf_parse_attribute calls. Unless
it forms a part of the SystemDescription struct which
currently only contains a file, which might be a good idea.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
@midnightveil
midnightveil force-pushed the julia/parsing-cleanup branch from 74c6b49 to d26436c Compare August 14, 2026 00:51
@midnightveil
midnightveil merged commit 0fb3b4e into main Aug 14, 2026
12 checks passed
@midnightveil
midnightveil deleted the julia/parsing-cleanup branch August 14, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sdf parsing should be consistent with integer parsing

2 participants