I've been looking out how to improve the aarch64 backend testing and how to do some refactoring in how we describe our instruction and the encoding process. I've now been pointed at the serde crate and it seems like it could be a very useful to do instead of writing raw rust. Has anybody looked into describing instructions, tests, or anything else in the backend using something like JSON?
@Sam Parker interesting idea! We could potentially do this, yes; if we have the Decode
trait on the Inst
then in theory we could build it from JSON. IMHO it's not a huge difference in accessibility to write ~5 lines of rust vs. ~5 lines of JSON for a new instruction encoding test case, so this doesn't seem super-high-priority for me, but maybe others think differently
plus there's already the filetest infrastructure: there used to be a test binemit
or something like that that we used for checking the encodings of instructions. It could be resurrected if that was more convenient than the Rust unit tests.
IMHO, both are at about the same level of ease-of-use
I think a good contribution would be to add something to care the encodings of instructions against a separate tool/library (e.g., manually I check many encodings against XED)
Yes, +1 to that for sure. When I wrote the initial aarch64 backend I took care to validate against as
(all of the instructions' pretty-printed forms were valid as
syntax at first) but we never automated that
Yes, automation would be my main goal - especially for writing tests. There is VIXL (https://github.com/Linaro/vixl) which can generate assemblers, and is a simulator, so I would really like to reuse some output from that to get better test coverage in the backend. I think it would be a bonus if we could have a single place to describe register usage for instructions too, so we don't have to implement both get_regs and map_regs.
Merging get_regs
and map_regs
should be possible using a macro I think. Said macro could also directly define the instruction enum and implement the display code.
Last updated: Nov 22 2024 at 17:03 UTC