CensoredUsername / dynasm-rs

A dynasm-like tool for rust.
https://censoredusername.github.io/dynasm-rs/language/index.html
Mozilla Public License 2.0
705 stars 52 forks source link

Is emitting text output possible? #54

Open jamesblacklock opened 3 years ago

jamesblacklock commented 3 years ago

It would be extremely helpful to be able to dump a text version of the assembly to stdout as the code is being generated. Is this currently possible to do? If not, is this something that could be planned in the future?

thx

CensoredUsername commented 3 years ago

I've not thought of a feature like that, but it does sound interesting. Personally I've always just thrown generated bytes in a disassembler if I wanted to debug.

I'm thinking of how something like this could be implemented. The easiest would be to, per line, take the ast just after enough has been parsed to separate expressions from syntax, and then stringify that again to format strings with the relevant expressions executed. This means it won't contain stuff like actual jump offsets, but any expressions will be evaluated. That should be possible at least, but I'm not planning anything like that on the short term.

jamesblacklock commented 3 years ago

Yeah, I hadn't thought through all of the details like jump offsets, but that sounds basically like what I was looking for. I may try to (partially) implement this as a declarative macro that calls dysnasm!().

Dumping the generated code to a file and using a disassembler will be extra trouble, but that could work too.