Skip to content

Commit

Permalink
Generate code for comma operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Lai-YT authored and leewei05 committed Jun 13, 2024
1 parent 1b66997 commit 23c60b5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/qbe_ir_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,17 @@ void QbeIrGenerator::Visit(const UnaryExprNode& unary_expr) {

void QbeIrGenerator::Visit(const BinaryExprNode& bin_expr) {
bin_expr.lhs->Accept(*this);

if (bin_expr.op == BinaryOperator::kComma) {
// For the comma operator, the value of its left operand is not used and can
// be eliminated if it has no side effects or if its definition is
// immediately dead. However, we leave these optimizations to QBE.
bin_expr.rhs->Accept(*this);
const int right_num = num_recorder.NumOfPrevExpr();
num_recorder.Record(right_num);
return;
}

const int left_num = num_recorder.NumOfPrevExpr();
// Due to the lack of direct support for logical operators in QBE, we
// implement logical expressions using comparison and jump instructions.
Expand Down

0 comments on commit 23c60b5

Please sign in to comment.