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
+= lookup_var_type(sym_table, ID);
+ array_type = get_elem_type(array_type);
+ elem_type // address of the first element in the array,
+// which is accutally the stack address represented
+// by a 'alloca' instruction.
+= lookup(sym_table, ID);
+ addr_value // indices
+= [];
+ indices for idx in Idx1..IdxN:
++= translate_expr(idx, sym_table, current_bb);
+ indices // bounds
+= get_bounds(array_type);
+ bounds
+return create_offset(
+,
+ elem_type,
+ addr_value,
+ indices
+ bounds);