IR - PatrickDahlin/LuaExe GitHub Wiki
After the AST is generated and the syntax is validated we can start generating IR code that will be parsed down to assembly. The reason for the use of an Intermediate Representation is to get a structured data object that has more specific instruction-like syntax and can be optimized/reordered for faster runtimes. This step also figures out the stack-allocated variables and their locations which will be needed when assembling.
The structure of the IR is as shown below using 3 example lines of code:
stack:
- alloc: 64 "a"
- mov: [rsp-0], 1 # a = 1
- alloc: 64 "b"
- mov: [rsp-0], 8 # b = 8
- mov: r10, [rsp-0]
- mov: r11, [rsp-64]
- add: r10, r11 # c = b + a
- alloc: 64 "c"
- mov [rsp-0], r10
Note that this example doesn't necessarily represent the notation that is used in the lua tables.
All computations use registers 10 and 11 for consistency and simplicity, this may change in the future