From 5fae3f4d76822c56368c94745f26192a29a577a2 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 9 Mar 2021 09:08:06 +0100 Subject: [PATCH] remove lists completely --- Makefile | 2 +- sem/scc.c | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 50af22d..1600f4c 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ LDFLAGS+=-Wl,--gc-sections,--print-gc-sections YFLAGS+=--locations -Wno-yacc --defines=parse.h LFLAGS+=--header-file=scan.h -OBJECTS:=scan.o parse.o ast.o type.o util.o list.o sem.o genc.o ident.o\ +OBJECTS:=array.o scan.o parse.o ast.o type.o util.o sem.o genc.o ident.o\ $(addprefix sem,.o /scc.o $(addprefix /hm, .o /gamma.o /subst.o /scheme.o)) all: splc diff --git a/sem/scc.c b/sem/scc.c index 2a53f7c..05c527b 100644 --- a/sem/scc.c +++ b/sem/scc.c @@ -147,8 +147,8 @@ struct components *tarjans( return tj.head; } -struct list *edges_expr(int ndecls, struct decl **decls, void *parent, - struct expr *expr, struct list *l) +struct array edges_expr(int ndecls, struct decl **decls, void *parent, + struct expr *expr, struct array l) { if (expr == NULL) return l; @@ -172,7 +172,7 @@ struct list *edges_expr(int ndecls, struct decl **decls, void *parent, struct edge *edge = xalloc(1, struct edge); edge->from = parent; edge->to = (void *)decls[i]; - l = list_cons(edge, l); + l = array_append(l, edge); found = true; } } @@ -202,8 +202,8 @@ struct list *edges_expr(int ndecls, struct decl **decls, void *parent, return l; } -struct list *edges_stmt(int ndecls, struct decl **decls, void *parent, - struct stmt *stmt, struct list *l) +struct array edges_stmt(int ndecls, struct decl **decls, void *parent, + struct stmt *stmt, struct array l) { switch(stmt->type) { case sassign: @@ -261,18 +261,17 @@ struct ast *ast_scc(struct ast *ast) //Calculate the edges struct decl **fundecls = ast->decls+ffun; - struct list *edges = NULL; + struct array edges; + array_init(&edges, nfun*2); for (size_t i = 0; idata.dfun->body) edges = edges_stmt(nfun, fundecls, fundecls[i], s, edges); AIEND } - int nedges; - struct edge **edata = (struct edge **) - list_to_array(edges, &nedges, false, 0); // Do tarjan's and convert back into the declaration list - struct components *cs = tarjans(nfun, (void **)fundecls, nedges, edata); + struct components *cs = tarjans(nfun, (void **)fundecls, + ARRAY_SIZE(edges), ARRAY_ELS(struct edge *, edges)); int i = ffun; for (struct components *c = cs; c != NULL; c = c->next) { @@ -287,9 +286,7 @@ struct ast *ast_scc(struct ast *ast) ast->ndecls = i; //Cleanup - for (int i = 0; i