harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c5383c6cff89a4a03c89c60ba5c366a762b8713d
parent 8a2eb2c5daadfcc8a1beb25c2378ea5c95687beb
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Fri, 16 Jul 2021 11:37:02 +0000

gen: implement delaration access

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Minclude/gen.h | 1+
Msrc/gen.c | 21++++++++++++++++++---
Msrc/genutil.c | 6+++++-
3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/include/gen.h b/include/gen.h @@ -21,6 +21,7 @@ struct gen_temp { char *name; const struct type *type; bool indirect; + bool is_global; }; // A gen binding stores the gen_temp for a scope object and is part of a linked diff --git a/src/gen.c b/src/gen.c @@ -171,9 +171,24 @@ static void gen_address_object(struct gen_context *ctx, struct gen_temp *temp, const struct scope_object *obj) { - const struct gen_binding *binding = binding_lookup(ctx, obj); - assert(binding->temp.indirect); - *temp = binding->temp; + const struct gen_binding *binding = NULL; + switch (obj->otype) { + case O_BIND: + binding = binding_lookup(ctx, obj); + assert(binding->temp.indirect); + *temp = binding->temp; + return; + case O_DECL: + temp->is_global = true; + temp->indirect = false; + temp->type = obj->type; + temp->name = ident_to_sym(&obj->ident); + return; + case O_CONST: + case O_TYPE: + abort(); // Invariant + } + abort(); } static void diff --git a/src/genutil.c b/src/genutil.c @@ -20,7 +20,11 @@ qval_temp(struct gen_context *ctx, struct qbe_value *out, const struct gen_temp *temp) { - out->kind = QV_TEMPORARY; + if (temp->is_global) { + out->kind = QV_GLOBAL; + } else { + out->kind = QV_TEMPORARY; + } out->type = qtype_lookup(ctx, temp->type, true); out->name = temp->name; }