cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 74b43a9973a22c95411137721775c11d58665660
parent 1df176029efa0d1e971e8835178f254ab8881592
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 13 Mar 2019 12:25:35 -0700

Make `struct function` opaque

Diffstat:
Mbackend.h | 10+---------
Mqbe.c | 15+++++++++++++++
Mstmt.c | 5+++--
3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/backend.h b/backend.h @@ -3,15 +3,6 @@ struct gotolabel { _Bool defined; }; -struct function { - char *name; - struct declaration *namedecl; - struct type *type; - struct block *start, *end; - struct hashtable *gotos; - uint64_t lastid; -}; - struct switchcases { void *root; struct value *defaultlabel; @@ -34,6 +25,7 @@ struct value *mkintconst(struct representation *, uint64_t); uint64_t intconstvalue(struct value *); struct function *mkfunc(char *, struct type *, struct scope *); +struct type *functype(struct function *); void funclabel(struct function *, struct value *); struct value *funcexpr(struct function *, struct expression *); void funcjmp(struct function *, struct value *); diff --git a/qbe.c b/qbe.c @@ -71,6 +71,15 @@ struct switchcase { struct value *body; }; +struct function { + char *name; + struct declaration *namedecl; + struct type *type; + struct block *start, *end; + struct hashtable *gotos; + uint64_t lastid; +}; + struct representation i8 = {'w', 'b'}; struct representation i16 = {'w', 'h'}; struct representation i32 = {'w', 'w'}; @@ -397,6 +406,12 @@ mkfunc(char *name, struct type *t, struct scope *s) return f; } +struct type * +functype(struct function *f) +{ + return f->type; +} + void funclabel(struct function *f, struct value *v) { diff --git a/stmt.c b/stmt.c @@ -275,8 +275,9 @@ stmt(struct function *f, struct scope *s) break; case TRETURN: next(); - if (f->type->base != &typevoid) { - e = exprconvert(expr(s), f->type->base); + t = functype(f); + if (t->base != &typevoid) { + e = exprconvert(expr(s), t->base); v = funcexpr(f, e); delexpr(e); } else {