SmallDragon uses a variant of Three-Address Code as an intermediate representation for Assembly Code Generation.
Implementation can be found in tac.c / tac.h
This web page is to document and formalize the representation.
The table shows which fields of struct TAC are defined for each TAC_KIND.
TAC_KIND | Example | ARG0/dest | ARG1/src | (int32_t) const_value | (uint32_t) label_index |
---|---|---|---|---|---|
TAC_BINARY_OP | t1 += t2 | TMP | TMP | - | - |
TAC_UNARY_OP | t1 = -t2 | TMP | TMP | - | - |
TAC_GOTO | goto L1 | - | - | - | LABEL |
TAC_IF_GOTO | if t1 goto L1 | - | TMP | - | LABEL |
TAC_DEREF | t1 = *t2 | TMP | TMP | - | - |
TAC_COPY | t1 = t2 | TMP | TMP / LOCAL / ARG | - | - |
TAC_CONST_VALUE | t1 = 4 | TMP | - | CONST | - |
TAC_CALL | call myfn | LABEL | - | - | - |
TAC_PARAM | param t1 | TMP | - | - | - |
TAC_RETURN | return t1 | TMP | - | - | - |
TAC_NOP | nop | - | - | - | - |
TAC_LABEL | L3: | - | - | - | LABEL |
TAC_LABEL | main: | LABEL | - | - | - |
TAC_BINARY_OP_IMMEDIATE | t3 += 2, t3 |= 5 | TMP | - | CONST | - |