scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit c73f4071591a3c11ae68f082d751e957e39c14fb
parent e430542e447c41173e8b94e77b52d2c20177bc2f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 11 Dec 2024 10:45:47 +0100

cc2: Add index nodes

These nodes are going to be useful when we want to express
an indirect access based in a register with some offset.

Diffstat:
Msrc/cmd/scc-cc/cc2/cc2.h | 15+++++++++------
Msrc/cmd/scc-cc/cc2/code.c | 19+++++++++++++++++--
2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h @@ -60,6 +60,7 @@ enum op { /* kind of operand */ /* operands */ OMEM = 'M', + OINDEX = 'I', OTMP = 'N', OAUTO = 'A', OREG = 'R', @@ -167,7 +168,7 @@ struct symbol { char *name; char kind; union { - unsigned long off; + long off; Node *stmt; Inst *inst; } u; @@ -178,16 +179,17 @@ struct symbol { struct node { char op; Type type; - char complex; - char address; - unsigned char flags; + int complex; + int address; + unsigned flags; union { TUINT i; TFLOAT f; - char reg; char *s; Symbol *sym; - char subop; + int reg; + int subop; + long off; } u; Symbol *label; Node *left, *right; @@ -234,6 +236,7 @@ extern void setlabel(Symbol *); extern Node *label2node(Node *np, Symbol *sym); extern Node *constnode(Node *np, TUINT n, Type *tp); extern Node *tmpnode(Type *); +extern Node *idxnode(Node *, long); extern Symbol *newlabel(void); extern void pprint(char *s); extern void deftype(Type *); diff --git a/src/cmd/scc-cc/cc2/code.c b/src/cmd/scc-cc/cc2/code.c @@ -43,6 +43,10 @@ addr(Node *np, Addr *addr) /* TODO: Add support for more type of constants */ addr->u.i = np->u.i; break; + case OINDEX: + addr->kind = SINDEX; + addr->u.off = np->u.off; + break; case OREG: case OTMP: case OLABEL: @@ -154,13 +158,24 @@ tmpnode(Type *tp) } Node * +idxnode(Node *np, long off) +{ + if (!np) + np = node(OINDEX); + np->op = OINDEX; + np->left = np->right = NULL; + np->type = ptrtype; + np->u.off = off; + return np; +} + +Node * constnode(Node *np, TUINT n, Type *tp) { if (!np) np = node(OCONST); np->op = OCONST; - np->left = NULL; - np->right = NULL; + np->left = np->right = NULL; np->type = *tp; np->u.i = n; return np;