From 8b5cca921b632d39162e0cfed30bf290743ac2a1 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 8 Jul 2025 15:43:46 +0200 Subject: [PATCH] Added IR documentation --- docs/ir.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/ir.md diff --git a/docs/ir.md b/docs/ir.md new file mode 100644 index 0000000..777a2cf --- /dev/null +++ b/docs/ir.md @@ -0,0 +1,27 @@ +# Intermediate Representation + +## Static Single Assignment + +The SSA IR follows a simple rule: every value is assigned exactly once. + +### Basic Blocks + +Every function has a list of basic blocks. Basic blocks store values in the order they appear in the original code. + +### Instructions + +Instructions are no different from values. The calculation `1 + 2` is represented as 3 values using 2 int constants and 1 binary operation: + +``` +t0 = 1 +t1 = 2 +t2 = t0 + t1 +``` + +All of these are considered values even in cases where the type of the value is `void` such as in procedural function calls with side effects. + +### Pointers + +There are no IDs or indices, therefore values don't know their position in a basic block. + +Values reference other values by including a pointer to them. \ No newline at end of file