Support TIMES prefix. Split expr parsing to have a no-float and no-string

version (for times and reserve space).

svn path=/trunk/yasm/; revision=275
0.3
Peter Johnson 23 years ago
parent 256511eea8
commit 84de990744
  1. 21
      libyasm/bytecode.c
  2. 2
      libyasm/bytecode.h
  3. 25
      modules/parsers/nasm/bison.y.in
  4. 25
      modules/parsers/nasm/nasm-bison.y
  5. 21
      src/bytecode.c
  6. 2
      src/bytecode.h
  7. 25
      src/parsers/nasm/bison.y.in
  8. 25
      src/parsers/nasm/nasm-bison.y

@ -156,7 +156,10 @@ struct bytecode {
} reserve;
} data;
unsigned long len; /* total length of entire bytecode */
expr *multiple; /* number of times bytecode is repeated */
unsigned long len; /* total length of entire bytecode (including
multiple copies) */
/* where it came from */
char *filename;
@ -385,11 +388,21 @@ SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel)
*old_sel = new_sel;
}
void
SetBCMultiple(bytecode *bc, expr *e)
{
if (bc->multiple)
bc->multiple = expr_new_tree(bc->multiple, EXPR_MUL, e);
else
bc->multiple = e;
}
static bytecode *
bytecode_new_common(void)
{
bytecode *bc = xmalloc(sizeof(bytecode));
bc->multiple = (expr *)NULL;
bc->len = 0;
bc->filename = xstrdup(in_filename);
@ -632,6 +645,12 @@ bytecode_print(bytecode *bc)
default:
printf("_Unknown_\n");
}
printf("Multiple=");
if (!bc->multiple)
printf("1");
else
expr_print(bc->multiple);
printf("\n");
printf("Length=%lu\n", bc->len);
printf("Filename=\"%s\" Line Number=%u\n",
bc->filename ? bc->filename : "<UNKNOWN>", bc->lineno);

@ -81,6 +81,8 @@ void SetInsnShiftFlag(bytecode *bc);
void SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel);
void SetBCMultiple(bytecode *bc, expr *e);
/* IMPORTANT: ea_ptr and im_ptr cannot be reused or freed after calling this
* function (it doesn't make a copy).
*/

@ -117,7 +117,7 @@ static bytecode *nasm_parser_temp_bc;
%type <ea> rm8x rm16x rm32x /*rm64x rm128x*/
%type <ea> rm8 rm16 rm32 rm64 rm128
%type <im_val> imm imm8x imm16x imm32x imm8 imm16 imm32
%type <exp> expr expr_no_string
%type <exp> expr expr_no_string expr_no_fltstr
%type <sym> explabel
%type <str_val> label_id
%type <tgt_val> target
@ -154,17 +154,19 @@ line: '\n' { $$ = (bytecode *)NULL; }
;
lineexp: exp
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label_id EQU expr {
| TIMES expr_no_fltstr exp { $$ = $3; SetBCMultiple($$, $2); }
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label TIMES expr_no_fltstr exp { $$ = $4; SetBCMultiple($$, $3); }
| label_id EQU expr {
symrec_define_equ($1, $3);
$$ = (bytecode *)NULL;
}
;
exp: instr
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr_no_fltstr { $$ = bytecode_new_reserve($2, $1); }
;
datavals: dataval {
@ -385,14 +387,17 @@ imm32: imm
;
/* jump targets */
target: expr { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
target: expr_no_string { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
;
/* expression trees */
expr_no_string: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
expr_no_string: expr_no_fltstr
| FLTNUM { $$ = expr_new_ident(ExprFloat($1)); }
;
expr_no_fltstr: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
| explabel { $$ = expr_new_ident(ExprSym($1)); }
/*| expr '||' expr { $$ = expr_new_tree($1, EXPR_LOR, $3); }*/
| expr '|' expr { $$ = expr_new_tree($1, EXPR_OR, $3); }

@ -117,7 +117,7 @@ static bytecode *nasm_parser_temp_bc;
%type <ea> rm8x rm16x rm32x /*rm64x rm128x*/
%type <ea> rm8 rm16 rm32 rm64 rm128
%type <im_val> imm imm8x imm16x imm32x imm8 imm16 imm32
%type <exp> expr expr_no_string
%type <exp> expr expr_no_string expr_no_fltstr
%type <sym> explabel
%type <str_val> label_id
%type <tgt_val> target
@ -154,17 +154,19 @@ line: '\n' { $$ = (bytecode *)NULL; }
;
lineexp: exp
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label_id EQU expr {
| TIMES expr_no_fltstr exp { $$ = $3; SetBCMultiple($$, $2); }
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label TIMES expr_no_fltstr exp { $$ = $4; SetBCMultiple($$, $3); }
| label_id EQU expr {
symrec_define_equ($1, $3);
$$ = (bytecode *)NULL;
}
;
exp: instr
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr_no_fltstr { $$ = bytecode_new_reserve($2, $1); }
;
datavals: dataval {
@ -385,14 +387,17 @@ imm32: imm
;
/* jump targets */
target: expr { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
target: expr_no_string { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
;
/* expression trees */
expr_no_string: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
expr_no_string: expr_no_fltstr
| FLTNUM { $$ = expr_new_ident(ExprFloat($1)); }
;
expr_no_fltstr: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
| explabel { $$ = expr_new_ident(ExprSym($1)); }
/*| expr '||' expr { $$ = expr_new_tree($1, EXPR_LOR, $3); }*/
| expr '|' expr { $$ = expr_new_tree($1, EXPR_OR, $3); }

@ -156,7 +156,10 @@ struct bytecode {
} reserve;
} data;
unsigned long len; /* total length of entire bytecode */
expr *multiple; /* number of times bytecode is repeated */
unsigned long len; /* total length of entire bytecode (including
multiple copies) */
/* where it came from */
char *filename;
@ -385,11 +388,21 @@ SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel)
*old_sel = new_sel;
}
void
SetBCMultiple(bytecode *bc, expr *e)
{
if (bc->multiple)
bc->multiple = expr_new_tree(bc->multiple, EXPR_MUL, e);
else
bc->multiple = e;
}
static bytecode *
bytecode_new_common(void)
{
bytecode *bc = xmalloc(sizeof(bytecode));
bc->multiple = (expr *)NULL;
bc->len = 0;
bc->filename = xstrdup(in_filename);
@ -632,6 +645,12 @@ bytecode_print(bytecode *bc)
default:
printf("_Unknown_\n");
}
printf("Multiple=");
if (!bc->multiple)
printf("1");
else
expr_print(bc->multiple);
printf("\n");
printf("Length=%lu\n", bc->len);
printf("Filename=\"%s\" Line Number=%u\n",
bc->filename ? bc->filename : "<UNKNOWN>", bc->lineno);

@ -81,6 +81,8 @@ void SetInsnShiftFlag(bytecode *bc);
void SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel);
void SetBCMultiple(bytecode *bc, expr *e);
/* IMPORTANT: ea_ptr and im_ptr cannot be reused or freed after calling this
* function (it doesn't make a copy).
*/

@ -117,7 +117,7 @@ static bytecode *nasm_parser_temp_bc;
%type <ea> rm8x rm16x rm32x /*rm64x rm128x*/
%type <ea> rm8 rm16 rm32 rm64 rm128
%type <im_val> imm imm8x imm16x imm32x imm8 imm16 imm32
%type <exp> expr expr_no_string
%type <exp> expr expr_no_string expr_no_fltstr
%type <sym> explabel
%type <str_val> label_id
%type <tgt_val> target
@ -154,17 +154,19 @@ line: '\n' { $$ = (bytecode *)NULL; }
;
lineexp: exp
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label_id EQU expr {
| TIMES expr_no_fltstr exp { $$ = $3; SetBCMultiple($$, $2); }
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label TIMES expr_no_fltstr exp { $$ = $4; SetBCMultiple($$, $3); }
| label_id EQU expr {
symrec_define_equ($1, $3);
$$ = (bytecode *)NULL;
}
;
exp: instr
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr_no_fltstr { $$ = bytecode_new_reserve($2, $1); }
;
datavals: dataval {
@ -385,14 +387,17 @@ imm32: imm
;
/* jump targets */
target: expr { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
target: expr_no_string { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
;
/* expression trees */
expr_no_string: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
expr_no_string: expr_no_fltstr
| FLTNUM { $$ = expr_new_ident(ExprFloat($1)); }
;
expr_no_fltstr: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
| explabel { $$ = expr_new_ident(ExprSym($1)); }
/*| expr '||' expr { $$ = expr_new_tree($1, EXPR_LOR, $3); }*/
| expr '|' expr { $$ = expr_new_tree($1, EXPR_OR, $3); }

@ -117,7 +117,7 @@ static bytecode *nasm_parser_temp_bc;
%type <ea> rm8x rm16x rm32x /*rm64x rm128x*/
%type <ea> rm8 rm16 rm32 rm64 rm128
%type <im_val> imm imm8x imm16x imm32x imm8 imm16 imm32
%type <exp> expr expr_no_string
%type <exp> expr expr_no_string expr_no_fltstr
%type <sym> explabel
%type <str_val> label_id
%type <tgt_val> target
@ -154,17 +154,19 @@ line: '\n' { $$ = (bytecode *)NULL; }
;
lineexp: exp
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label_id EQU expr {
| TIMES expr_no_fltstr exp { $$ = $3; SetBCMultiple($$, $2); }
| label { $$ = (bytecode *)NULL; }
| label exp { $$ = $2; }
| label TIMES expr_no_fltstr exp { $$ = $4; SetBCMultiple($$, $3); }
| label_id EQU expr {
symrec_define_equ($1, $3);
$$ = (bytecode *)NULL;
}
;
exp: instr
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
| RESERVE_SPACE expr_no_fltstr { $$ = bytecode_new_reserve($2, $1); }
;
datavals: dataval {
@ -385,14 +387,17 @@ imm32: imm
;
/* jump targets */
target: expr { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
target: expr_no_string { $$.val = $1; SetOpcodeSel(&$$.op_sel, JR_NONE); }
| SHORT target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_SHORT_FORCED); }
| NEAR target { $$ = $2; SetOpcodeSel(&$$.op_sel, JR_NEAR_FORCED); }
;
/* expression trees */
expr_no_string: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
expr_no_string: expr_no_fltstr
| FLTNUM { $$ = expr_new_ident(ExprFloat($1)); }
;
expr_no_fltstr: INTNUM { $$ = expr_new_ident(ExprInt($1)); }
| explabel { $$ = expr_new_ident(ExprSym($1)); }
/*| expr '||' expr { $$ = expr_new_tree($1, EXPR_LOR, $3); }*/
| expr '|' expr { $$ = expr_new_tree($1, EXPR_OR, $3); }

Loading…
Cancel
Save