tool(cleanup): add sdf_parse_attribute() functions to decrease duplication - #592
Conversation
|
From body of tool(cleanup): impl ParseAttribute on PciDevice
How about we make the 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. |
|
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>
74c6b49 to
d26436c
Compare
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.