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 28cd81d248d2f57e02f539964134ad592758098f
parent 8691ccdccf8ea72f9af11b3891c511c303826831
Author: Michael Forney <mforney@mforney.org>
Date:   Fri,  5 Jul 2019 23:15:37 -0700

Move some functions around

Diffstat:
Mqbe.c | 114++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 58 insertions(+), 56 deletions(-)

diff --git a/qbe.c b/qbe.c @@ -96,7 +96,7 @@ switchcase(struct switchcases *cases, uint64_t i, struct value *v) c->body = v; } -/* functions */ +/* values */ struct value * mkblock(char *name) @@ -115,6 +115,63 @@ mkblock(char *name) return &b->label; } +struct value * +mkglobal(char *name, bool private) +{ + static uint64_t id; + struct value *v; + + v = xmalloc(sizeof(*v)); + v->kind = VALGLOBAL; + v->repr = &iptr; + v->name.str = name; + v->name.id = private ? ++id : 0; + + return v; +} + +char * +globalname(struct value *v) +{ + assert(v->kind == VALGLOBAL && !v->name.id); + return v->name.str; +} + +struct value * +mkintconst(struct repr *r, uint64_t n) +{ + struct value *v; + + v = xmalloc(sizeof(*v)); + v->kind = VALCONST; + v->repr = r; + v->i = n; + + return v; +} + +uint64_t +intconstvalue(struct value *v) +{ + assert(v->kind == VALCONST); + return v->i; +} + +static struct value * +mkfltconst(struct repr *r, double n) +{ + struct value *v; + + v = xmalloc(sizeof(*v)); + v->kind = VALCONST; + v->repr = r; + v->f = n; + + return v; +} + +/* functions */ + static void emittype(struct type *); static void emitvalue(struct value *); @@ -176,39 +233,6 @@ funcinstn(struct func *f, int op, struct repr *repr, struct value *args[]) #define funcinst(f, op, repr, ...) funcinstn(f, op, repr, (struct value *[]){__VA_ARGS__}) -struct value * -mkintconst(struct repr *r, uint64_t n) -{ - struct value *v; - - v = xmalloc(sizeof(*v)); - v->kind = VALCONST; - v->repr = r; - v->i = n; - - return v; -} - -uint64_t -intconstvalue(struct value *v) -{ - assert(v->kind == VALCONST); - return v->i; -} - -static struct value * -mkfltconst(struct repr *r, double n) -{ - struct value *v; - - v = xmalloc(sizeof(*v)); - v->kind = VALCONST; - v->repr = r; - v->f = n; - - return v; -} - static void funcalloc(struct func *f, struct decl *d) { @@ -352,28 +376,6 @@ funcload(struct func *f, struct type *t, struct lvalue lval) return funcbits(f, t, v, lval.bits); } -struct value * -mkglobal(char *name, bool private) -{ - static uint64_t id; - struct value *v; - - v = xmalloc(sizeof(*v)); - v->kind = VALGLOBAL; - v->repr = &iptr; - v->name.str = name; - v->name.id = private ? ++id : 0; - - return v; -} - -char * -globalname(struct value *v) -{ - assert(v->kind == VALGLOBAL && !v->name.id); - return v->name.str; -} - /* XXX: If a function declared without a prototype is declared with a parameter affected by default argument promotion, we need to emit a QBE