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 <github43132@proton.me>
This commit is contained in:
Ronald Caesar
2025-12-22 19:31:45 -04:00
parent 69e6d2be63
commit f89fc03ec1

View File

@@ -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[???];
```