ESPL1000 Three Address Code / IR

ESPL1000 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.

Concepts

Table of IR Instructions

The table shows which fields of struct TAC are defined for each TAC_KIND.
It also specifies which values are allowed for these fields.

Control Flow outside the function

TAC_KIND Example uint32_t dest uint32_t arg1 (int32_t) const_value (uint32_t) label_index enum TAC_OP op (allowed values)
TAC_CALL t1 = call myfn TMP LABEL(index into SST) - - -
TAC_PARAM param t1 TMP - 8: 8 bit param,
16: 16 bit param
- -
TAC_SETUP_STACKFRAME setup_stackframe 3 - - CONST - -
TAC_SETUP_SP setup SP - - - - -
TAC_RETURN return t1 TMP - - - -
TAC_LABEL_FUNCTION main: LABEL(index into SST) - - - -

Control Flow inside a function

TAC_KIND Example uint32_t dest uint32_t arg1 (int32_t) const_value (uint32_t) label_index enum TAC_OP op (allowed values)
TAC_GOTO goto L1 - - - LABEL -
TAC_IF_GOTO if t1 goto L1 - TMP - LABEL -
TAC_IF_CMP_GOTO if t1 < t2 goto L1 TMP TMP - LABEL TAC_OP_CMP_*
TAC_LABEL_INDEXED L3: - - - LABEL -

Load/Store

TAC_KIND Example uint32_t dest uint32_t arg1 int32_t const_value uint32_t label_index enum TAC_OP op (allowed values)
TAC_LOAD_LOCAL t1 = x TMP LOCAL - - -
TAC_LOAD_LOCAL_ADDR t1 = address(y) TMP LOCAL - - -
TAC_STORE_LOCAL x = t1 LOCAL TMP - - -
TAC_LOAD_CONST_ADDR t1 = [const] TMP - CONST - -
TAC_STORE_CONST_ADDR [const] = t1 - TMP CONST - -
TAC_LOAD [NEW] t1 = [t2] TMP TMP number of bytes to load (1 or 2) - -
TAC_STORE [NEW] [t1] = t2 TMP TMP - - -

Other

TAC_KIND Example uint32_t dest uint32_t arg1 (int32_t) const_value (uint32_t) label_index enum TAC_OP op (allowed values)
TAC_BINARY_OP t1 += t2 TMP TMP - - TAC_OP_ADD, TAC_OP_SUB, TAC_OP_MUL, TAC_OP_XOR, TAC_OP_AND, TAC_OP_OR, TAC_OP_CMP_*
TAC_UNARY_OP t1 = -t2 TMP TMP - - TAC_OP_UNARY_*
TAC_COPY t1 = t2 TMP TMP - - -
TAC_CONST_VALUE t1 = 4 TMP - CONST - -
TAC_NOP nop - - - - -
TAC_BINARY_OP_IMMEDIATE t3 += 2, t3 |= 5 TMP - CONST - TAC_OP_ADD, TAC_OP_SUB, TAC_OP_MUL,
TAC_OP_XOR, TAC_OP_OR, TAC_OP_AND
TAC_OP_SHIFT_*