diff options
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 85 |
1 files changed, 46 insertions, 39 deletions
@@ -81,12 +81,12 @@ void yyerror(const char *msg) %type <inst> inst %type <arg> imm -%type <args> reg2 -%type <args> reg3 -%type <args> regp -%type <args> regp_reg -%type <args> reg_regp -%type <args> reg_imm +%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 <lval> intlit %% @@ -100,31 +100,32 @@ line: T_SPACE inst eol | eol ; -inst: T_ADD reg3 { $$ = INSTRUCTION_ARGS(ADD, $2); } - | T_SUB reg3 { $$ = INSTRUCTION_ARGS(SUB, $2); } - | T_MUL reg3 { $$ = INSTRUCTION_ARGS(MUL, $2); } - | T_DIV reg3 { $$ = INSTRUCTION_ARGS(DIV, $2); } - | T_AND reg3 { $$ = INSTRUCTION_ARGS(AND, $2); } - | T_OR reg3 { $$ = INSTRUCTION_ARGS(OR, $2); } - | T_XOR reg3 { $$ = INSTRUCTION_ARGS(XOR, $2); } - | T_LSL reg3 { $$ = INSTRUCTION_ARGS(LSL, $2); } - | T_LSR reg3 { $$ = INSTRUCTION_ARGS(LSR, $2); } - | T_ASL reg3 { $$ = INSTRUCTION_ARGS(ASL, $2); } - | T_ASR reg3 { $$ = INSTRUCTION_ARGS(ASR, $2); } - | T_ROL reg3 { $$ = INSTRUCTION_ARGS(ROL, $2); } - | T_ROR reg3 { $$ = INSTRUCTION_ARGS(ROR, $2); } - | T_NOT reg2 { $$ = INSTRUCTION_ARGS(NOT, $2); } - | T_NEG reg2 { $$ = INSTRUCTION_ARGS(NEG, $2); } - | T_BTC reg2 { $$ = INSTRUCTION_ARGS(BTC, $2); } - | T_BTS reg2 { $$ = INSTRUCTION_ARGS(BTS, $2); } - | T_MOV reg2 { $$ = INSTRUCTION_ARGS(MOV, $2); } - | T_ST_B regp_reg { $$ = INSTRUCTION_ARGS(ST_B, $2); } - | T_ST_W regp_reg { $$ = INSTRUCTION_ARGS(ST_W, $2); } - | T_LD_BL reg_regp { $$ = INSTRUCTION_ARGS(LD_BL, $2); } - | T_LD_BH reg_regp { $$ = INSTRUCTION_ARGS(LD_BH, $2); } - | T_LD_W reg_regp { $$ = INSTRUCTION_ARGS(LD_W, $2); } - | T_LDI_BL reg_imm { $$ = INSTRUCTION_ARGS(LDI_BL, $2); } - | T_LDI_BH reg_imm { $$ = INSTRUCTION_ARGS(LDI_BH, $2); } +inst: + T_ADD a_reg3 { $$ = INSTRUCTION_ARGS(ADD, $2); } + | T_SUB a_reg3 { $$ = INSTRUCTION_ARGS(SUB, $2); } + | T_MUL a_reg3 { $$ = INSTRUCTION_ARGS(MUL, $2); } + | T_DIV a_reg3 { $$ = INSTRUCTION_ARGS(DIV, $2); } + | T_AND a_reg3 { $$ = INSTRUCTION_ARGS(AND, $2); } + | T_OR a_reg3 { $$ = INSTRUCTION_ARGS(OR, $2); } + | T_XOR a_reg3 { $$ = INSTRUCTION_ARGS(XOR, $2); } + | T_LSL a_reg3 { $$ = INSTRUCTION_ARGS(LSL, $2); } + | T_LSR a_reg3 { $$ = INSTRUCTION_ARGS(LSR, $2); } + | T_ASL a_reg3 { $$ = INSTRUCTION_ARGS(ASL, $2); } + | T_ASR a_reg3 { $$ = INSTRUCTION_ARGS(ASR, $2); } + | T_ROL a_reg3 { $$ = INSTRUCTION_ARGS(ROL, $2); } + | T_ROR a_reg3 { $$ = INSTRUCTION_ARGS(ROR, $2); } + | T_NOT a_reg2 { $$ = INSTRUCTION_ARGS(NOT, $2); } + | T_NEG a_reg2 { $$ = INSTRUCTION_ARGS(NEG, $2); } + | T_BTC a_reg2 { $$ = INSTRUCTION_ARGS(BTC, $2); } + | T_BTS a_reg2 { $$ = INSTRUCTION_ARGS(BTS, $2); } + | T_MOV a_reg2 { $$ = INSTRUCTION_ARGS(MOV, $2); } + | T_ST_B a_regp_reg { $$ = INSTRUCTION_ARGS(ST_B, $2); } + | T_ST_W a_regp_reg { $$ = INSTRUCTION_ARGS(ST_W, $2); } + | T_LD_BL a_reg_regp { $$ = INSTRUCTION_ARGS(LD_BL, $2); } + | T_LD_BH a_reg_regp { $$ = INSTRUCTION_ARGS(LD_BH, $2); } + | 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 @@ -139,18 +140,24 @@ inst: T_ADD reg3 { $$ = INSTRUCTION_ARGS(ADD, $2); } { $$ = INSTRUCTION(BLE); } | T_BRA { $$ = INSTRUCTION(BRA); } - | T_JMP regp { $$ = INSTRUCTION_ARGS(JMP, $2); } - | T_ADDPC reg_imm { $$ = INSTRUCTION_ARGS(ADDPC, $2); } + | T_JMP a_regp { $$ = INSTRUCTION_ARGS(JMP, $2); } + | T_ADDPC a_reg_imm { $$ = INSTRUCTION_ARGS(ADDPC, $2); } | T_NOP { $$ = INSTRUCTION(NOP); } ; -reg2: T_SPACE T_REG "," T_REG { $$ = MKARGS($2, $4); } -reg3: T_SPACE T_REG "," T_REG "," T_REG { $$ = MKARGS($2, $4, $6); } -regp: T_SPACE T_REGPTR { $$ = MKARGS($2); } -regp_reg: T_SPACE T_REGPTR "," T_REG { $$ = MKARGS($2, $4); } -reg_regp: T_SPACE T_REG "," T_REGPTR { $$ = MKARGS($2, $4); } -reg_imm: T_SPACE T_REG "," imm { $$ = MKARGS($2, $4); } +a_reg2: + T_SPACE T_REG "," T_REG { $$ = MKARGS($2, $4); } +a_reg3: + T_SPACE T_REG "," T_REG "," T_REG { $$ = MKARGS($2, $4, $6); } +a_regp: + T_SPACE T_REGPTR { $$ = MKARGS($2); } +a_regp_reg: + T_SPACE T_REGPTR "," T_REG { $$ = MKARGS($2, $4); } +a_reg_regp: + T_SPACE T_REG "," T_REGPTR { $$ = MKARGS($2, $4); } +a_reg_imm: + T_SPACE T_REG "," imm { $$ = MKARGS($2, $4); } imm: intlit { if (-0x80 > $1 || $1 > 0xff) { |