commit 04988d5245f29f669d7f4909e00ecd07d8957ebc
parent 1696ab0af0305d71ce23bac0b6a2b8a0b4404b3c
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 26 Dec 2020 09:25:18 -0500
gen: add some comments clarifying qbe_value usage
Diffstat:
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/include/qbe.h b/include/qbe.h
@@ -40,6 +40,11 @@ enum qbe_value_kind {
QV_TEMPORARY,
};
+// Represents a value which can be an argument to a QBE instruction.
+//
+// If indirect, this value is a pointer to the actual value, which is allocated
+// elsewhere (e.g. the stack). This is usually true unless we have temporarily
+// loaded a value as an input into an instruction.
struct qbe_value {
enum qbe_value_kind kind;
const struct qbe_type *type;
diff --git a/src/gen.c b/src/gen.c
@@ -116,6 +116,9 @@ qval_deref(struct gen_context *ctx,
struct qbe_value *val, const struct type *type)
{
assert(val->type == &qbe_long); // Invariant // XXX: ARCH
+ // Because we stack-allocate all variables and store a pointer to them
+ // in qbe_value, this is generally as easy as changing the
+ // interpretation of the value from direct to indirect.
val->indirect = true;
val->type = qtype_for_type(ctx, type, false);
}
@@ -124,6 +127,9 @@ qval_deref(struct gen_context *ctx,
static void
qval_address(struct qbe_value *val)
{
+ // Because we stack-allocate all variables and store a pointer to them
+ // in qbe_value, this is generally as easy as changing the
+ // interpretation of the value from indirect to direct.
val->type = &qbe_long; // XXX: ARCH
val->indirect = false;
}