diff options
author | Michael Forney <mforney@mforney.org> | 2019-03-13 12:25:35 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-03-13 12:25:35 -0700 |
commit | 74b43a9973a22c95411137721775c11d58665660 (patch) | |
tree | 1f7c953bcb28a8dc9ee05772ab2f6c6979d17be6 | |
parent | 1df176029efa0d1e971e8835178f254ab8881592 (diff) | |
download | cproc-74b43a9973a22c95411137721775c11d58665660.tar.xz |
Make `struct function` opaque
-rw-r--r-- | backend.h | 10 | ||||
-rw-r--r-- | qbe.c | 15 | ||||
-rw-r--r-- | stmt.c | 5 |
3 files changed, 19 insertions, 11 deletions
@@ -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 *); @@ -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) { @@ -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 { |