LCC common code changes from Gigatron-LCC
Here is a list of changes to the LCC common code that were required for the Gigatron VCPU backend. The changes have been reorganized as a succession of self-contained commits that can be taken independently with suitable comments. The 61ab and 7e12 commits are of general interest as they fix bugs that appear when compiling cpp or rcc with optimization enabled on a modern gcc-9 compiler on x86_64.
The gigatron backend (see https://raw.githubusercontent.com/lb3361/gigatron-lcc/master/src/gigatron.md) is very unusual because each lcc "instruction" can be a long sequence of opcodes that use the accumulator in a nearly optimal way. So instead of convering a tree with instructions, we map tree segments to sequences of instructions. Here is what the comment in gigatron.md says:
Once LCC has encoded a C function as a forest of trees, the LCC/Lburg code generator computes an optimal cover of the trees with assembly instructions in which only the registers are left to be specified. This optimality ignores the effects of the limited number of registers and the specialization of registers. When such problems occur, the register allocator spills registers to memory as needed for correctness, but without regard for optimality. That does not work well for a simplistic CPU like the Gigagron VCPU. Once vAC is allocated, there is nothing left one can do. The following code repurposes the LCC mechanisms in the following way. The LCC register allocator no longer deals with actual registers but with a piece of page zero memory that we call registers. Instead of computing a cover of the trees with instruction, we cover the trees with sequences of instructions that use the accumulator vAC and the scratch registers (T0..T3) as they see fit. The LBURG grammar is no longer a tree grammar, but a transducer that converts tree fragments into sequences. As a result, each nonterminal must be defined by two components: the role it occupies on the tree grammar and the role it occupies in the sequence grammar.