diff --git a/boot.c b/boot.c index 85cc5d0..3d41e6e 100644 --- a/boot.c +++ b/boot.c @@ -884,22 +884,40 @@ int parse_add_expr() { return lhs; } -int parse_cmp_expr() { +int parse_shift_expr() { int lhs = parse_add_expr(); while (1) { next_token(); - if (token_type == TOKEN_LT) { + if (token_type == TOKEN_LSHIFT) { 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); } else if (token_type == TOKEN_GT) { - int rhs = parse_add_expr(); + int rhs = parse_shift_expr(); lhs = asm_rr("sgt", lhs, rhs); } else if (token_type == TOKEN_LE) { - int rhs = parse_add_expr(); + int rhs = parse_shift_expr(); int sgt = asm_rr("sgt", lhs, rhs); lhs = asm_r("seqz", sgt); } else if (token_type == TOKEN_GE) { - int rhs = parse_add_expr(); + int rhs = parse_shift_expr(); int slt = asm_rr("slt", lhs, rhs); lhs = asm_r("seqz", slt); } else {