From 212dd57e0a870e8fc5532477583e36e465825c5b Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 24 Apr 2019 21:13:46 -0700 Subject: Free functions when we're done with them --- cc.h | 1 + decl.c | 1 + qbe.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/cc.h b/cc.h index 0a6641f..e0f6d84 100644 --- a/cc.h +++ b/cc.h @@ -487,6 +487,7 @@ struct value *mkintconst(struct repr *, uint64_t); uint64_t intconstvalue(struct value *); struct func *mkfunc(char *, struct type *, struct scope *); +void delfunc(struct func *); struct type *functype(struct func *); void funclabel(struct func *, struct value *); struct value *funcexpr(struct func *, struct expr *); diff --git a/decl.c b/decl.c index 041d98b..6355689 100644 --- a/decl.c +++ b/decl.c @@ -938,6 +938,7 @@ decl(struct scope *s, struct func *f) stmt(f, s); emitfunc(f, d->linkage == LINKEXTERN); s = delscope(s); + delfunc(f); d->defined = true; return true; } diff --git a/qbe.c b/qbe.c index 6dc7ff1..465634f 100644 --- a/qbe.c +++ b/qbe.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "util.h" @@ -413,6 +414,23 @@ mkfunc(char *name, struct type *t, struct scope *s) return f; } +void +delfunc(struct func *f) +{ + struct block *b; + struct inst **inst; + + while (b = f->start) { + f->start = b->next; + arrayforeach (&b->insts, inst) + free(*inst); + free(b->insts.val); + free(b); + } + delmap(f->gotos, free); + free(f); +} + struct type * functype(struct func *f) { -- cgit v1.2.3