From 1c67ecc869aab80d6b47cf6c483689f03c643d4d Mon Sep 17 00:00:00 2001 From: Zhu Siyuan <3200100491@zju.edu.cn> Date: Thu, 28 Mar 2024 10:31:49 +0800 Subject: [PATCH] [docs] lab3 offset translate --- docs/middle-ir-gen.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/middle-ir-gen.md b/docs/middle-ir-gen.md index 55072ef..9fef01b 100644 --- a/docs/middle-ir-gen.md +++ b/docs/middle-ir-gen.md @@ -783,6 +783,30 @@ class="sourceCode c"> return exit_bb; + +ID[Idx1]...[IdxN] +
// element type
+array_type = lookup_var_type(sym_table, ID);
+elem_type = get_elem_type(array_type);
+// address of the first element in the array,
+// which is accutally the stack address represented
+// by a 'alloca' instruction.
+addr_value = lookup(sym_table, ID);
+// indices
+indices = [];
+for idx in Idx1..IdxN:
+  indices += translate_expr(idx, sym_table, current_bb);
+// bounds
+bounds = get_bounds(array_type);
+
+return create_offset(
+  elem_type,
+  addr_value,
+  indices,
+  bounds
+);
+