~mcf/cproc

212dd57e0a870e8fc5532477583e36e465825c5b — Michael Forney 1 year, 7 months ago 79a8df4
Free functions when we're done with them
3 files changed, 20 insertions(+), 0 deletions(-)

M cc.h
M decl.c
M qbe.c
M cc.h => cc.h +1 -0
@@ 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 *);

M decl.c => decl.c +1 -0
@@ 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;
			}

M qbe.c => qbe.c +18 -0
@@ 3,6 3,7 @@
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#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)
{