X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=assembler%2Fparser.y;h=84a5c2466bd7a3c70970b0d6378df69222dedd95;hb=244653f03d1ba8fda31b0a467cc9c15e56ab9029;hp=753be084c1d98925335a3fc4cbec1cfe30750beb;hpb=b9e19faa25ad9e1b24f08dc77267760df1b98504;p=b43-tools.git diff --git a/assembler/parser.y b/assembler/parser.y index 753be08..84a5c24 100644 --- a/assembler/parser.y +++ b/assembler/parser.y @@ -38,7 +38,7 @@ extern struct initvals_sect *cur_initvals_sect; %token SECTION_TEXT SECTION_IVALS -%token ASM_ARCH ASM_START SPR GPR OFFR LR COMMA BRACK_OPEN BRACK_CLOSE PAREN_OPEN PAREN_CLOSE HEXNUM DECNUM ARCH_NEWWORLD ARCH_OLDWORLD LABEL IDENT LABELREF +%token ASM_ARCH ASM_START SPR GPR OFFR LR COMMA SEMICOLON BRACK_OPEN BRACK_CLOSE PAREN_OPEN PAREN_CLOSE HEXNUM DECNUM ARCH_NEWWORLD ARCH_OLDWORLD LABEL IDENT LABELREF %token PLUS MINUS MULTIPLY DIVIDE BITW_OR BITW_AND BITW_XOR BITW_NOT LEFTSHIFT RIGHTSHIFT @@ -50,17 +50,19 @@ extern struct initvals_sect *cur_initvals_sect; %% -line : /* empty */ - | line statement { +line : line_terminator { + /* empty */ + } + | line statement line_terminator { struct statement *s = $2; if (section != SECTION_TEXT) yyerror("Microcode text instruction in non .text section"); memcpy(&s->info, &cur_lineinfo, sizeof(struct lineinfo)); list_add_tail(&s->list, &infile.sl); } - | line section_switch { + | line section_switch line_terminator { } - | line ivals_write { + | line ivals_write line_terminator { struct initval_op *io = $2; if (section != SECTION_IVALS) yyerror("InitVals write in non .initvals section"); @@ -70,6 +72,11 @@ line : /* empty */ } ; +/* Allow terminating lines with the ";" char */ +line_terminator : /* Nothing */ + | SEMICOLON line_terminator + ; + section_switch : SECTION_TEXT { section = SECTION_TEXT; } @@ -95,35 +102,35 @@ section_switch : SECTION_TEXT { } ; -ivals_write : IVAL_MMIO16 hexnum_decnum COMMA hexnum_decnum { +ivals_write : IVAL_MMIO16 imm_value COMMA imm_value { struct initval_op *iop = xmalloc(sizeof(struct initval_op)); iop->type = IVAL_W_MMIO16; iop->args[0] = (unsigned int)(unsigned long)$2; iop->args[1] = (unsigned int)(unsigned long)$4; $$ = iop; } - | IVAL_MMIO32 hexnum_decnum COMMA hexnum_decnum { + | IVAL_MMIO32 imm_value COMMA imm_value { struct initval_op *iop = xmalloc(sizeof(struct initval_op)); iop->type = IVAL_W_MMIO32; iop->args[0] = (unsigned int)(unsigned long)$2; iop->args[1] = (unsigned int)(unsigned long)$4; $$ = iop; } - | IVAL_PHY hexnum_decnum COMMA hexnum_decnum { + | IVAL_PHY imm_value COMMA imm_value { struct initval_op *iop = xmalloc(sizeof(struct initval_op)); iop->type = IVAL_W_PHY; iop->args[0] = (unsigned int)(unsigned long)$2; iop->args[1] = (unsigned int)(unsigned long)$4; $$ = iop; } - | IVAL_RADIO hexnum_decnum COMMA hexnum_decnum { + | IVAL_RADIO imm_value COMMA imm_value { struct initval_op *iop = xmalloc(sizeof(struct initval_op)); iop->type = IVAL_W_RADIO; iop->args[0] = (unsigned int)(unsigned long)$2; iop->args[1] = (unsigned int)(unsigned long)$4; $$ = iop; } - | IVAL_SHM16 hexnum_decnum COMMA hexnum_decnum COMMA hexnum_decnum { + | IVAL_SHM16 imm_value COMMA imm_value COMMA imm_value { struct initval_op *iop = xmalloc(sizeof(struct initval_op)); iop->type = IVAL_W_SHM16; iop->args[0] = (unsigned int)(unsigned long)$2; @@ -131,7 +138,7 @@ ivals_write : IVAL_MMIO16 hexnum_decnum COMMA hexnum_decnum { iop->args[2] = (unsigned int)(unsigned long)$6; $$ = iop; } - | IVAL_SHM32 hexnum_decnum COMMA hexnum_decnum COMMA hexnum_decnum { + | IVAL_SHM32 imm_value COMMA imm_value COMMA imm_value { struct initval_op *iop = xmalloc(sizeof(struct initval_op)); iop->type = IVAL_W_SHM32; iop->args[0] = (unsigned int)(unsigned long)$2; @@ -487,8 +494,11 @@ statement : asmdir { ; /* ASM directives */ -asmdir : asmarch { - $$ = $1; +asmdir : ASM_ARCH hexnum_decnum { + struct asmdir *ad = xmalloc(sizeof(struct asmdir)); + ad->type = ADIR_ARCH; + ad->u.arch = (unsigned int)(unsigned long)$2; + $$ = ad; } | ASM_START identifier { struct asmdir *ad = xmalloc(sizeof(struct asmdir)); @@ -501,20 +511,6 @@ asmdir : asmarch { } ; -asmarch : ASM_ARCH ARCH_NEWWORLD { - struct asmdir *ad = xmalloc(sizeof(struct asmdir)); - ad->type = ADIR_ARCH; - ad->u.arch = NEWWORLD; - $$ = ad; - } - | ASM_ARCH ARCH_OLDWORLD { - struct asmdir *ad = xmalloc(sizeof(struct asmdir)); - ad->type = ADIR_ARCH; - ad->u.arch = OLDWORLD; - $$ = ad; - } - ; - label : LABEL { struct label *label = xmalloc(sizeof(struct label)); char *l; @@ -1008,15 +1004,13 @@ extended_operlist : decnum COMMA decnum COMMA operand COMMA operand COMMA operan } ; -external_jump_operands : hexnum COMMA operand COMMA operand COMMA labelref { +external_jump_operands : imm COMMA labelref { struct operlist *ol = xmalloc(sizeof(struct operlist)); struct operand *cond = xmalloc(sizeof(struct operand)); - cond->type = OPER_RAW; - cond->u.raw = (unsigned long)$1; + cond->type = OPER_IMM; + cond->u.imm = $1; ol->oper[0] = cond; ol->oper[1] = $3; - ol->oper[2] = $5; - ol->oper[3] = $7; $$ = ol; } ; @@ -1088,35 +1082,37 @@ reg : GPR regnr { } ; -mem : BRACK_OPEN hexnum_decnum BRACK_CLOSE { +mem : BRACK_OPEN imm BRACK_CLOSE { struct memory *mem = xmalloc(sizeof(struct memory)); + struct immediate *offset_imm = $2; mem->type = MEM_DIRECT; - mem->offset = (unsigned long)$2; + mem->offset = offset_imm->imm; + free(offset_imm); $$ = mem; } - | BRACK_OPEN hexnum_decnum COMMA OFFR regnr BRACK_CLOSE { + | BRACK_OPEN imm COMMA OFFR regnr BRACK_CLOSE { struct memory *mem = xmalloc(sizeof(struct memory)); + struct immediate *offset_imm = $2; mem->type = MEM_INDIRECT; - mem->offset = (unsigned long)$2; + mem->offset = offset_imm->imm; + free(offset_imm); mem->offr_nr = (unsigned long)$5; $$ = mem; } ; -imm : hexnum { +imm : imm_value { struct immediate *imm = xmalloc(sizeof(struct immediate)); imm->imm = (unsigned long)$1; $$ = imm; } - | decnum { - struct immediate *imm = xmalloc(sizeof(struct immediate)); - imm->imm = (unsigned long)$1; - $$ = imm; + ; + +imm_value : hexnum_decnum { + $$ = $1; } | complex_imm { - struct immediate *imm = xmalloc(sizeof(struct immediate)); - imm->imm = (unsigned long)$1; - $$ = imm; + $$ = $1; } ;