Skip to content

Commit

Permalink
Update assignment expression logic for array subscripting
Browse files Browse the repository at this point in the history
  • Loading branch information
leewei05 authored and Lai-YT committed Jul 7, 2024
1 parent 5aef2d1 commit 9c7ee3a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/qbe_ir_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,12 +1101,16 @@ void QbeIrGenerator::Visit(const SimpleAssignmentExprNode& assign_expr) {
FuncScopeTemp{reg_num_to_id_num.at(lhs_num)});
}
} else {
// Global array subscripting will return the target address instead of the
// address of `id`.
if (assign_expr.lhs->is_global &&
!dynamic_cast<ArrSubExprNode*>(assign_expr.lhs.get())) {
WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num},
user_defined::GlobalPointer{reg_num_to_id.at(lhs_num)});
if (assign_expr.lhs->is_global) {
// Global array subscripting will return the target address instead of the
// address of `id`.
if (dynamic_cast<ArrSubExprNode*>(assign_expr.lhs.get())) {
WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num},
FuncScopeTemp{reg_num_to_id_num.at(lhs_num)});
} else {
WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num},
user_defined::GlobalPointer{reg_num_to_id.at(lhs_num)});
}
} else {
WriteInstr_("storew {}, {}", FuncScopeTemp{rhs_num},
FuncScopeTemp{reg_num_to_id_num.at(lhs_num)});
Expand Down

0 comments on commit 9c7ee3a

Please sign in to comment.