From 0f8532d4e7315b86e160abf4ced461e7678b5587 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 7 Apr 2024 01:29:12 +0300 Subject: add features that make machine generation easier --- src/parser.y | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index ec133eb..bda8f31 100644 --- a/src/parser.y +++ b/src/parser.y @@ -64,7 +64,6 @@ %token LEXI9 "i9" %token LEXI27 "i27" -%nterm mem_loc %nterm mem_base %nterm mem_off %nterm int @@ -262,8 +261,7 @@ type | "i27" { $$ = I27; } const - : "i9" int - | "i27" int + : int consts : const "," consts @@ -307,8 +305,8 @@ arg : id { $$ = IDTOVAL($[id]); } - | type int { - $$ = imm_val($[int], $[type]); + | int { + $$ = imm_val($[int], NOTYPE); } arith @@ -359,17 +357,19 @@ mem_base mem_off : int -mem_loc - : "(" mem_base mem_off ")" {$$ = mem_val(IDTOVAL($[mem_base]).r, $[mem_off]);} - mem - : type id "<<" mem_loc { - struct val t = IDALLOC($[id]); - INSADD(LOAD, $[type], t, $[mem_loc], noclass()); + : type id "<<" mem_base mem_off { + struct val t = IDTOVAL($[id]); + struct val b = IDTOVAL($[mem_base]); + struct val o = imm_val($[mem_off], I27); + INSADD(LOAD, $[type], t, b, o); } - | id ">>" type mem_loc { - struct val t = IDALLOC($[id]); - INSADD(STORE, $[type], noclass(), t, $[mem_loc]); + | id ">>" type mem_base mem_off { + struct val t = IDTOVAL($[id]); + struct val b = IDTOVAL($[mem_base]); + struct val o = imm_val($[mem_off], I27); + /* really not a huge fan or 'reusing' the output slot... */ + INSADD(STORE, $[type], o, b, t); } stack @@ -444,6 +444,12 @@ branch | arg ">" arg "->" local { NEW_BLOCK(BGT, $1, $3, $[local]); } + | arg "->" local { + NEW_BLOCK(BNZ, $[arg], noclass(), $[local]); + } + | "!" arg "->" local { + NEW_BLOCK(BEZ, $[arg], noclass(), $[local]); + } | "->" local { NEW_BLOCK(J, noclass(), noclass(), $[local]); } -- cgit v1.3