diff --git a/docs/middle-ir-gen.md b/docs/middle-ir-gen.md index a134c6a..38d36be 100644 --- a/docs/middle-ir-gen.md +++ b/docs/middle-ir-gen.md @@ -667,8 +667,8 @@ class="sourceCode c">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. +// which is actually the stack address represented +// by a 'alloca' instruction or a global variable. addr_value = lookup(sym_table, ID); // indices indices = []; @@ -677,12 +677,12 @@ class="sourceCode c">// bounds bounds = get_bounds(array_type); -return create_offset( +return create_load(create_offset( elem_type, addr_value, indices, bounds -); +)); @@ -706,6 +706,8 @@ void insert_instruction(Instruction *inst, BasicBlock *block) { 它记录优化 Pass 中所有的变化,并在最后进行统一插入更新,以提高效率. 如果你对此感兴趣,可以阅读 [WebKit Blog](https://webkit.org/blog/5852/introducing-the-b3-jit-compiler/) +需要注意的是,Expr 对应的是右值,也即实际的值,所以需要一条 load 指令;LVal 对应的是左值,以某个地址/指针类型的 Value 表示,不需要一条额外的 load 指令. + ### 语句生成 我们定义: