aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend.h10
-rw-r--r--qbe.c15
-rw-r--r--stmt.c5
3 files changed, 19 insertions, 11 deletions
diff --git a/backend.h b/backend.h
index c4b1eaf..ae8699c 100644
--- 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
index a20851d..ceede55 100644
--- 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
index e642353..d732c31 100644
--- 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 {