Possible to get structured assembly code?

I have seen code_native and code_typed and code_llvm.

These seem to only provide an unstructured text. Though the text itself appears structured and could be parsed to create a structure, this is tedious.

Should the internals not have this information available in a structured manner?

code_lowered gives structured information, but not at assembly level.

May I please present what I am actually trying to achieve, and perhaps someone can point to an idea:

I would like to translate julia code into another computer language, one that is very basic and operates on a stack, with registers, like an assembly machine.

I am hoping that I can write a translation from the julia assembly code to this language and that this would be easiest way to get correct translations.

Thanks

I assume by unstructured you mean that it’s presented as text. This is simply because there’s nothing julia specific about them so there is nothing in julia to represent them. They are simply being handled by other library.

There are of course binary representation for both but not necessary structured representation. For LLVM code, there are ways to get pointer to the LLVM functions/modules (I believe you can just look at the implementation of code_llvm). For assembly code, there’s no builtin structured and just binary code.

6 Likes

I see, you are saying it’s an output of llvm.

Need to check out the code behind code_native etc.

Might it be possible to get it structured from llvm?
I guess If should ask there.

As I said, you can get the pointer to llvm structure.

I would say that the first part is not quite true anymore. GitHub - kimikage/ColoredLLCodes.jl: Color `code_llvm` and `code_native` printing , which has been incorporated into the stdlib, reconstructs some structure to stylize the output.

1 Like

This would be really useful for doing rewriting on the SSA IR with Metatheory.jl. I’m interested.

Are you sure you want to do this at the assembly level (assembly is also not an SSA form)?

I’d like to do this at the SSA IR level

1 Like

Tools for working with Julia’s untyped SSA IR already exist. You might want to check out IRTools.jl or Cassette.jl. Their documentation should help get you started.

2 Likes

Out of curiosity, could code emitted by @code_native be used as input into an assembler to generate an exe or dll? Like for
GNU Assembler Examples (lmu.edu)
Creating Assembly Language DLL Modules for Windows - CodeProject
Writing DLL in Assembly Language for External Calling in Maple - Application Center (maplesoft.com)

1 Like

With dump_module=true, it is now a proper asm file (in v1.8-dev)

5 Likes