Compiler-explorer: Option to convert constants to hex in asm output (other than binary mode)

Created on 13 Mar 2016  路  5Comments  路  Source: compiler-explorer/compiler-explorer

It would be great if there was an option to filter the compiler-output asm and replace bare numbers with their hex equivalent. gcc and clang have the annoying habit of using decimal output for everything, including constants that have a nice pattern in hex but are just nonsense in decimal.

This is my main use for binary mode, since the objdump output uses hex for all constants. It doesn't show the data / rodata sections, though, and is generally less nice than compiler asm output if you aren't looking at the instruction encodings / alignments.

For signed decimal integers, -0x8 is a lot easier to read than 0xFFFFFFF8, though. objdump's output is a bit inconsistent in its choices:

int foo(int n) { return n-0x1257; }
int bar(){ return -0x1257; }

foo:  lea    eax,[rdi-0x1257]   / ret
bar:  mov    eax,0xffffeda9    / ret

I guess it's choosing based on the fact that it's a relative displacement.

Maybe some clever heuristics could choose between the signed hex and the hex representation of their 2's complement encoding? Choosing based on context like objdump does is harder for a text filter. Maybe have an option to make output like mov eax, 0xffffeda9 (-4695) which is no longer valid asm, but which has constants in hex and decimal?

A good first step would be an option to hex everything. That would be plenty useful in a lot of cases.

enhancement

All 5 comments

Agreed; either a blanket option or at least a tool-tip for each constant.

Lots of offline email conversation with Leon de Boer: parsing all the numbers and offering tooltips to convert to/from hex and whatnot seems sensible.

I've become somewhat familiar with Monaco implementing the linking of code and I want to try this one now. Just to make sure, we want a tooltip for numeric constants that converts hex to decimal, and decimal to hex? If it's not hex nor decimal, (binary?) should both be displayed?

Great stuff! Something like that yes!

I think having them only in tooltips is a lot less good for some use-cases than as an extra comment, or replacing the decimal constant with hex. With multiple nearby constants, your eye can't really scan down them if you have to mouseover them one at a time.

Of course, having a floating-point interpretation as well as hex is very nice.

This is much better than nothing, and a nice improvement. I'll have to see whether I still really miss having all constants in hex.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pps83 picture pps83  路  5Comments

Sahnvour picture Sahnvour  路  4Comments

crea7or picture crea7or  路  4Comments

mathbunnyru picture mathbunnyru  路  4Comments

adiba picture adiba  路  4Comments