cakeml icon indicating copy to clipboard operation
cakeml copied to clipboard

LabLang refactor

Open myreen opened this issue 1 year ago • 1 comments

LabLang is an assembly style IL at the bottom of the CakeML compiler. It represents the program as a list of functions which in turn are lists of assembly instructions. The type of assembly instructions is shared among all target architectures (x64, arm8, risc-v, etc.). When LabLang programs are converted to machine code, each generic asm instruction is processed by a target-specific asm encoder function. These encoders convert each asm instruction into one or more target instructions before encoding each target instruction to concrete bytes of the targeted ISA.

There are several problems with LabLang but the most significant is that the compiler as structured currently has no IL where the program is a list of target instructions (as opposed to generic asm instructions). A list of target instructions could enable interesting target-specific peephole optimisations.

This issue is about redoing LabLang such that it is parametrised by the type of assembly instructions. When targeting arm8 the instructions should be instantiated to arm8 instructions.

There are also a few other clean ups it would be good to include in this refactor/rewrite of LabLang:

  • Only two-byte align function entry labels. Currently all labels are two-byte aligned.
  • Don't use a program counter in the semantics of LabLang; that was a mistake. Instead, treat the program as a list of instructions to execute; jumping to a label loads a new list to execute.
  • Make it impossible for functions to refer to each other's internal labels. It was a mistake to make this possible in the current semantics and that causes bloat in the compiler state.

myreen avatar Nov 04 '24 21:11 myreen

Lablang should also try to easily support switch statements

ordinarymath avatar Dec 17 '24 04:12 ordinarymath