Search code examples
scalascalacintermediate-code

Specification of Scala compiler's intermediate code


Is there any formal specification or detailed description of the intermediate code generated by the Scala compiler (i.e. passing the -Xprint-icode option to scalac)?

Thanks.


Solution

  • The icode format is going away, with the introduction of the new GenBCode backend, which goes directly from scalac Trees to ASM's bytecode representation. If I were you, I wouldn't invest time in learning it.

    Instead, I suggest you print after cleanup instead (-Xprint:cleanup), which is the last phase before the backend, with scalac Trees, which are very easy to understand because they're basically Java code with a Scala syntax.

    That said, if you insist on dealing with icode, I don't think there's any real documentation about it. But it almost has a one-to-one correspondance with the JVM bytecode: it has classes, fields and methods. And inside methods, there is a stack-based instruction set.