Search code examples
rustcompiler-constructioncranelift

Emit ASM from Cranelift


Is there the possibility to emit ASM when compiling something using Cranelift? By "ASM" I mean the assembler text-representation, in e.g. Intel-Syntax or similar

Now I was planing on implementing this myself using a dissasembler-library like Capstone or Iced, but then I found Context::set_disasm(bool) which apparently does exactly what I need. The problem is I'm unable to find where to extract this assembler-code from. There's no function like get_disasm as far as I looked.

If it's relevant, I'm building both a JIT and an AOT compiler and I want the dissasembler to work when using either.

Can one help me out?


Solution

  • Retrieve the vcode field of CompiledCode. It is in CompiledCodeBase, so it is not documented, unfortunately.