From f89fc03ec1cd3ee58773aefd748a8e5118fade40 Mon Sep 17 00:00:00 2001 From: Ronald Caesar Date: Mon, 22 Dec 2025 19:31:45 -0400 Subject: [PATCH] docs: Rework variable design implementation When I was designing the instruction struct, I needed to figure out how an instruction knows which argument position is a variable and a constant. So the variable type is baked into the struct. I also added a variable array for obvious reasons. Signed-off-by: Ronald Caesar --- src/IR_DESIGN_DOC.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/IR_DESIGN_DOC.md b/src/IR_DESIGN_DOC.md index 873f54a..e4eafbc 100644 --- a/src/IR_DESIGN_DOC.md +++ b/src/IR_DESIGN_DOC.md @@ -6,7 +6,22 @@ All memory will be allocated from a contiguous memory arena before the pass begi // Ref: Chapter 3.1.3 typedef struct { - instruction_t* defining_instruction; + type_t type; // TYPE_INT, TYPE_FLOAT + + // 1: x = 4 Defines x so reachingDef = 1 (x₁) + // 2: y = x + 1 Only uses x so reachingDef is still 1. + // 3: x = 5 Redefines x so reachingDef = 2 (x₂). int reaching_definition; -} variable_t; +} original_variable_t; + +// This array maps the source code definition to its SSA version. +// IT is the frontend's job to populate this array. +// +// Example: +// +// Instruction 100: x = y + z +// +// If `x` is at index 5, original_variables[5].reachingDef = 100. +// `x` maps to instruction 100. +original_variable_t original_variables[???]; ```