Commit Graph

58 Commits

Author SHA1 Message Date
Rui Ueyama 5e5d76ff55 Implement linear scan register allocator. 2018-09-01 06:01:03 +00:00
Rui Ueyama d56cb7cc4e Use r2 instead of r0 for IR_RETURN.
r0 is a destination register. If an instruction takes only
a source register, it should use r2 instead of r0.
2018-09-01 04:13:03 +00:00
Rui Ueyama 04df768a1f Assign offsets to local variables in gen_x86 instead of in gen_ir.
In SSA, we will promote local variables in memory to register values,
so that they are allocated to physical registers rather than the stack
if there are enough number of registers available. Therefore,
computing function's stack size in gen_ir is too early.
2018-09-01 02:58:06 +00:00
Rui Ueyama b2d2459dc0 Make IR SSA.
There's no Phi node in our IR. Instead, basic blocks take parameters.
I borrowed the idea from Swift Intermediate Language.
2018-09-01 00:36:26 +00:00
Rui Ueyama ac74d2ed4c Make the IR three-address form.
This is a preparation for introducing SSA so that we can apply
modern compiler optimization techniques to 9cc.
2018-08-31 12:36:15 +00:00
Rui Ueyama 1adfc8545f Define a new struct to represent a register. 2018-08-31 12:08:52 +00:00
Rui Ueyama 3235d3fa5c Rename registers to prepare for the three-address form. 2018-08-30 22:43:57 +00:00
Rui Ueyama 742be85d9e Remove IRInfo. 2018-08-30 22:04:10 +00:00
Rui Ueyama b93ef13283 Refactor. 2018-08-30 12:43:30 +00:00
Rui Ueyama d97091b48a Remove dead code. 2018-08-30 12:25:16 +00:00
Rui Ueyama fbf9223bda Introduce basic block.
Basic block is a straight-line code sequence with no branches in
except to the entry and no branches out except at the exit.
This change alone shouldn't make things better, but it allows us
to add optimization passes in later patches.
2018-08-30 00:11:30 +00:00
Rui Ueyama 4442c4cfc5 Split emit_code(). Code move only. 2018-08-29 23:59:57 +00:00
Rui Ueyama 49caa8e044 Remove IR insns that take immediate operands for simplicity. 2018-08-28 01:58:24 +00:00
Rui Ueyama cdf534efd6 Store negative (real) offsets from RBP.
Because that's logically more accurate.
2018-08-28 01:44:44 +00:00
Rui Ueyama cbe5868763 Simplify. 2018-08-28 00:37:46 +00:00
Rui Ueyama 4e2c1fb92f Remove extern varaibles from gvars. 2018-08-28 00:25:06 +00:00
Rui Ueyama 6a622ded26 Simplify. 2018-08-28 00:20:45 +00:00
Rui Ueyama 27aa9d9fe8 Support hexadecimal-escape-sequence. 2018-08-27 00:10:17 +00:00
Rui Ueyama a05a09d3cb Handle -x as 0-x. 2018-08-26 04:53:04 +00:00
Rui Ueyama 99c8ff4e66 Resolve break targets in Parse.c. 2018-08-26 03:54:38 +00:00
Rui Ueyama 59a8d7bf53 Emit .bss section for zero-initialized data. 2018-08-26 02:42:15 +00:00
Rui Ueyama adcd5723ac Move is_extern to Type. 2018-08-26 00:43:02 +00:00
Rui Ueyama a2521edccb Define struct Program to represent an entire input program. 2018-08-26 00:26:38 +00:00
Rui Ueyama f0d30b0ca8 Allow ptr - ptr. 2018-08-25 21:37:43 +00:00
Rui Ueyama 6070468cd8 Add "~" operator. 2018-08-24 23:28:49 +00:00
Rui Ueyama c72b0532b7 Rename a variable. 2018-08-24 01:04:52 +00:00
Rui Ueyama 78c11d5434 Simplfiy. 2018-08-24 00:43:54 +00:00
Rui Ueyama d392e3d704 Remove IR_{ADD,SUB,MUL}_IMM. 2018-08-22 22:41:24 +00:00
Rui Ueyama 8c1b6ff954 Merge IR_STORE_ARG{8,32,64} to IR_STORE_ARG. 2018-08-22 22:08:11 +00:00
Rui Ueyama 4e349e6243 Merge IR_STORE{8,32,64} to IR_STORE. 2018-08-22 22:04:13 +00:00
Rui Ueyama 1186375262 Merge IR_LOAD{8,32,64} to IR_LOAD. 2018-08-22 22:02:02 +00:00
Rui Ueyama d173ab8fb2 Fix a fall-through bug. 2018-08-22 08:43:37 +00:00
Rui Ueyama f0dd629dcb Make assembly emitter more concise. 2018-08-22 08:43:37 +00:00
Rui Ueyama 1cf71766d2 Use shorter variable name. 2018-08-22 08:43:37 +00:00
Rui Ueyama 515ddd371d Add IR_{ADD,SUB,MUL}_IMM instructions. 2018-08-22 08:43:37 +00:00
Rui Ueyama 2383988f60 Add unary "-" operator. 2018-08-22 08:43:36 +00:00
Rui Ueyama d0cb9096ff Add "%" operator. 2018-08-22 08:43:36 +00:00
Rui Ueyama f39ffaaf78 Add "<<" and ">>" operators. 2018-08-22 08:43:36 +00:00
Rui Ueyama e7c9558a5a Add "<=" and ">=" operators. 2018-08-22 08:43:36 +00:00
Rui Ueyama e71e74205c Add "&" operator. 2018-08-22 08:43:36 +00:00
Rui Ueyama 979e04698f Add "^" operator. 2018-08-22 08:43:36 +00:00
Rui Ueyama 635f014bd9 Add "|" operator. 2018-08-22 08:43:36 +00:00
Rui Ueyama 5c5ab6b933 Use StringBuilder. 2018-08-22 08:43:35 +00:00
Rui Ueyama 6862ca10ba Align stack data members. 2018-08-22 08:43:35 +00:00
Rui Ueyama c0adcc1a83 Remove IR_SUB_IMM and add IR_BPREL. 2018-08-22 08:43:35 +00:00
Rui Ueyama a4e14b22b7 Add comments. 2018-08-22 08:43:35 +00:00
Rui Ueyama 0006bc56ea Simplify. 2018-08-22 08:43:35 +00:00
Rui Ueyama 1849dce377 Rewrite tests in shell in C. 2018-08-22 08:43:35 +00:00
Rui Ueyama 59ddb6ee91 Add "extern". 2018-08-22 08:43:35 +00:00
Rui Ueyama 811e2dd733 Add do ~ while loop. 2018-08-22 08:43:35 +00:00