From d3b7bc03f97a5b08f9ab098a5511aaa8e4db4f78 Mon Sep 17 00:00:00 2001 From: Yaossg Date: Sat, 16 Nov 2024 10:23:03 +0800 Subject: [PATCH] shift --- boot.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) 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 {