diff --git a/docs/middle-ir-gen.md b/docs/middle-ir-gen.md index 55072ef..f3735aa 100644 --- a/docs/middle-ir-gen.md +++ b/docs/middle-ir-gen.md @@ -615,6 +615,30 @@ for arg in Args: args_list += translate_expr(arg, sym_table, current_bb); return create_function_call(function, args_list, current_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);