Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate code of simple assignment expression #36

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ std::string NotEqualToExprNode::Op_() const {
return "!=";
}

int SimpleAssignmentExprNode::CodeGen() const {}
int SimpleAssignmentExprNode::CodeGen() const {
int expr_num = expr_->CodeGen();
output << "storew " << PrefixSigil(expr_num) << ", "
<< PrefixSigil(id_to_num.at(id_)) << std::endl;
return expr_num;
}

void SimpleAssignmentExprNode::Dump(int pad) const {
std::cout << Pad(pad) << '(' << '=' << std::endl;
Expand Down
7 changes: 7 additions & 0 deletions test/codegen/simple_assignment_expr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main() {
int i;
int j;
i = 0;
i = (j = 1 + 2 + 3 + 4) + 5;
return i + j;
}
1 change: 1 addition & 0 deletions test/codegen/simple_assignment_expr.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
25