pacak / cargo-show-asm

cargo subcommand showing the assembly, LLVM-IR and MIR generated for Rust code
Apache License 2.0
714 stars 35 forks source link

Add the ability to strip data #304

Open zesterer opened 2 months ago

zesterer commented 2 months ago

I'm writing code that's making considerable use of LUTs generated inline via const code. As a result, I end up with the LUT data being displayed inline with the code, which is often many thousands of times larger than the code itself. It would be useful to have the option to strip data or - even better - data over a specific length from the output.

EDIT:

For anybody with a similar problem, my solution for now is:

cargo asm ... | grep -v "asciz"

which strips all lines containing asciz from the output (if your assembly language uses another keyword to denote data, use that instead). You will also want to add --color to the cargo command to retain colour output.

pacak commented 2 months ago

Do you have an example to reproduce the problem?

zesterer commented 2 months ago

Not that I can easily extract. Something like this should work on your end though:

fn square(x: usize) -> usize {
    let lut = const {
        let mut lut = [0; 4096];
        let mut i = 0;
        while i < 4096 {
            lut[i] = i * i;
        }
        lut
    };
    lut[x]
}

It might be worth noting that I'm compiling for an ARM-based platform so perhaps the way the compiler treats static data might be a little different given the differences in addressing mode (ARM only really supports near addresses without building up a pointer manually in a register).

pacak commented 2 months ago

On x86 this generates a huge table but it goes into a separate section so output is still perfectly readable. Can you post some sample output of how it looks on arm? Preferably something not too huge?

zesterer commented 2 months ago

Here's an example. Note the extremely long lines which, when displayed in a terminal, wrap.

pacak commented 2 months ago

Here's an example.

Is that the output from cargo-show-asm? Those tables go into separate sections and I expect them not to be displayed by default.

pacak commented 2 months ago

If it dumps in a single line I'd use something like cargo asm ... --color | less -SR

pacak commented 2 months ago

Anyway, I don't mind adding something to deal with this issue, but only if it can't be solved with less as I shown above.

zesterer commented 2 months ago

In theory I can process the output in any number of ways, but I think an option like --code-only would be fairly consistent with the existing features of the crate (such as --simplify).