diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-14 16:14:35 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-15 23:19:20 -0600 |
commit | ca8e5e46c4d3bcb402cb3439a9a1cdc42d6d45c7 (patch) | |
tree | 6f0a4948ef45f48c9d7d6766fdbdcc2dc3e254ae /parser.y | |
parent | a339532b50bfc4ad36fc3225bf75eae28dee1a4c (diff) |
nqasm: Handle pc offset arguments
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -81,12 +81,14 @@ void yyerror(const char *msg) %type <inst> inst %type <arg> imm +%type <arg> pcoff %type <args> a_reg2 %type <args> a_reg3 %type <args> a_regp %type <args> a_regp_reg %type <args> a_reg_regp %type <args> a_reg_imm +%type <args> a_pcoff %type <lval> intlit %% @@ -126,20 +128,13 @@ inst: | T_LD_W a_reg_regp { $$ = INSTRUCTION_ARGS(LD_W, $2); } | T_LDI_BL a_reg_imm { $$ = INSTRUCTION_ARGS(LDI_BL, $2); } | T_LDI_BH a_reg_imm { $$ = INSTRUCTION_ARGS(LDI_BH, $2); } - | T_BEQ - { $$ = INSTRUCTION(BEQ); } - | T_BNE - { $$ = INSTRUCTION(BNE); } - | T_BGT - { $$ = INSTRUCTION(BGT); } - | T_BGE - { $$ = INSTRUCTION(BGE); } - | T_BLT - { $$ = INSTRUCTION(BLT); } - | T_BLE - { $$ = INSTRUCTION(BLE); } - | T_BRA - { $$ = INSTRUCTION(BRA); } + | T_BEQ a_pcoff { $$ = INSTRUCTION_ARGS(BEQ, $2); } + | T_BNE a_pcoff { $$ = INSTRUCTION_ARGS(BNE, $2); } + | T_BGT a_pcoff { $$ = INSTRUCTION_ARGS(BGT, $2); } + | T_BGE a_pcoff { $$ = INSTRUCTION_ARGS(BGE, $2); } + | T_BLT a_pcoff { $$ = INSTRUCTION_ARGS(BLT, $2); } + | T_BLE a_pcoff { $$ = INSTRUCTION_ARGS(BLE, $2); } + | T_BRA a_pcoff { $$ = INSTRUCTION_ARGS(BRA, $2); } | T_JMP a_regp { $$ = INSTRUCTION_ARGS(JMP, $2); } | T_ADDPC a_reg_imm { $$ = INSTRUCTION_ARGS(ADDPC, $2); } | T_NOP @@ -158,6 +153,17 @@ a_reg_regp: T_SPACE T_REG "," T_REGPTR { $$ = MKARGS($2, $4); } a_reg_imm: T_SPACE T_REG "," imm { $$ = MKARGS($2, $4); } +a_pcoff: + T_SPACE pcoff { $$ = MKARGS($2); } + +pcoff: intlit { + if (-0x80 > $1 || $1 > 0x7f) { + yyerror("pc offset operand out of range"); + YYERROR; + } else { + $$ = MKARGVALUE((uint8_t) $1); + } + } imm: intlit { if (-0x80 > $1 || $1 > 0xff) { |