This commit is contained in:
Yaossg 2024-11-16 10:23:03 +08:00
parent cf45cf1e2f
commit d3b7bc03f9

28
boot.c
View File

@ -884,22 +884,40 @@ int parse_add_expr() {
return lhs; return lhs;
} }
int parse_cmp_expr() { int parse_shift_expr() {
int lhs = parse_add_expr(); int lhs = parse_add_expr();
while (1) { while (1) {
next_token(); next_token();
if (token_type == TOKEN_LT) { if (token_type == TOKEN_LSHIFT) {
int rhs = parse_add_expr(); int rhs = parse_add_expr();
lhs = asm_rr("sll", lhs, rhs);
} else if (token_type == TOKEN_RSHIFT) {
int rhs = parse_add_expr();
lhs = asm_rr("sra", lhs, rhs);
} else {
unget_token();
break;
}
}
return lhs;
}
int parse_cmp_expr() {
int lhs = parse_shift_expr();
while (1) {
next_token();
if (token_type == TOKEN_LT) {
int rhs = parse_shift_expr();
lhs = asm_rr("slt", lhs, rhs); lhs = asm_rr("slt", lhs, rhs);
} else if (token_type == TOKEN_GT) { } else if (token_type == TOKEN_GT) {
int rhs = parse_add_expr(); int rhs = parse_shift_expr();
lhs = asm_rr("sgt", lhs, rhs); lhs = asm_rr("sgt", lhs, rhs);
} else if (token_type == TOKEN_LE) { } else if (token_type == TOKEN_LE) {
int rhs = parse_add_expr(); int rhs = parse_shift_expr();
int sgt = asm_rr("sgt", lhs, rhs); int sgt = asm_rr("sgt", lhs, rhs);
lhs = asm_r("seqz", sgt); lhs = asm_r("seqz", sgt);
} else if (token_type == TOKEN_GE) { } else if (token_type == TOKEN_GE) {
int rhs = parse_add_expr(); int rhs = parse_shift_expr();
int slt = asm_rr("slt", lhs, rhs); int slt = asm_rr("slt", lhs, rhs);
lhs = asm_r("seqz", slt); lhs = asm_r("seqz", slt);
} else { } else {