diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-07 01:29:12 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-07 01:29:12 +0300 |
| commit | 0f8532d4e7315b86e160abf4ced461e7678b5587 (patch) | |
| tree | 2cf1a728b1f4383926a5c39908754b6eb4a5a2dd /src/parser.y | |
| parent | 68059b52c389143e766c5499c76c6c90c6b82846 (diff) | |
| download | qbt-0f8532d4e7315b86e160abf4ced461e7678b5587.tar.gz qbt-0f8532d4e7315b86e160abf4ced461e7678b5587.zip | |
add features that make machine generation easier
Diffstat (limited to 'src/parser.y')
| -rw-r--r-- | src/parser.y | 34 |
1 files changed, 20 insertions, 14 deletions
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 <val> mem_loc %nterm <str> mem_base %nterm <integer> mem_off %nterm <integer> 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]); } |
