Getting the application binary interface right
With the latest addition of arrays and records to the code generator, you may notice that sometimes the generated code does not execute as expected. The reason is that we have ignored the calling conventions of the platform so far. Each platform defines its own rules for how one function can call another function in the same program or a library. These rules are summarized in the application binary interface (ABI) documentation. Typical information includes the following:
- Are machine registers used for parameter passing? If yes, which?
- How are aggregates such as arrays and structs passed to a function?
- How are return values handled?
There is a wide variety of rules in use. On some platforms, aggregates are always passed indirectly, meaning that a copy of the aggregate is placed on the stack and only a pointer to the copy is passed as a parameter. On other platforms, a small aggregate (say 128- or 256-bit-wide) is...