📄 nasm-bison.y
字号:
} } | STRING { $$ = yasm_vp_create($1, NULL); } | ID '=' direxpr { yasm_expr__traverse_leaves_in($3, parser_nasm, fix_directive_symrec); $$ = yasm_vp_create($1, $3); };/* memory addresses */memaddr: expr { $$ = yasm_arch_ea_create(parser_nasm->arch, $1); } | SEGREG ':' memaddr { $$ = $3; yasm_arch_parse_seg_override(parser_nasm->arch, $$, $1[0], cur_line); } | SIZE_OVERRIDE memaddr { $$ = $2; yasm_ea_set_len($$, $1); } | NOSPLIT memaddr { $$ = $2; yasm_ea_set_nosplit($$, 1); };/* instruction operands */operands: operand { yasm_ops_initialize(&$$.operands); yasm_ops_append(&$$.operands, $1); $$.num_operands = 1; } | operands ',' operand { yasm_ops_append(&$1.operands, $3); $$.operands = $1.operands; $$.num_operands = $1.num_operands+1; };operand: '[' memaddr ']' { $$ = yasm_operand_create_mem($2); } | expr { $$ = yasm_operand_create_imm($1); } | SEGREG { $$ = yasm_operand_create_segreg($1[0]); } | SIZE_OVERRIDE operand { $$ = $2; if ($$->type == YASM_INSN__OPERAND_REG && yasm_arch_get_reg_size(parser_nasm->arch, $$->data.reg) != $1) yasm__error(cur_line, N_("cannot override register size")); else $$->size = $1; } | TARGETMOD operand { $$ = $2; $$->targetmod = $1[0]; };/* expression trees *//* expr w/o FLTNUM and unary + and -, for use in directives */direxpr: INTNUM { $$ = p_expr_new_ident(yasm_expr_int($1)); } | ID { $$ = p_expr_new_ident(yasm_expr_sym( yasm_symtab_define_label(p_symtab, $1, yasm_section_bcs_first(parser_nasm->cur_section), 0, cur_line))); yasm_xfree($1); } | direxpr '|' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_OR, $3); } | direxpr '^' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_XOR, $3); } | direxpr '&' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_AND, $3); } | direxpr LEFT_OP direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_SHL, $3); } | direxpr RIGHT_OP direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_SHR, $3); } | direxpr '+' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_ADD, $3); } | direxpr '-' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_SUB, $3); } | direxpr '*' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_MUL, $3); } | direxpr '/' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_DIV, $3); } | direxpr SIGNDIV direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_SIGNDIV, $3); } | direxpr '%' direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_MOD, $3); } | direxpr SIGNMOD direxpr { $$ = p_expr_new_tree($1, YASM_EXPR_SIGNMOD, $3); } /*| '!' expr { $$ = p_expr_new_branch(YASM_EXPR_LNOT, $2); }*/ | '~' direxpr %prec UNARYOP { $$ = p_expr_new_branch(YASM_EXPR_NOT, $2); } | '(' direxpr ')' { $$ = $2; };dvexpr: INTNUM { $$ = p_expr_new_ident(yasm_expr_int($1)); } | FLTNUM { $$ = p_expr_new_ident(yasm_expr_float($1)); } | explabel { $$ = p_expr_new_ident(yasm_expr_sym($1)); } /*| dvexpr '||' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_LOR, $3); }*/ | dvexpr '|' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_OR, $3); } | dvexpr '^' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_XOR, $3); } /*| dvexpr '&&' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_LAND, $3); }*/ | dvexpr '&' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_AND, $3); } /*| dvexpr '==' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_EQUALS, $3); }*/ /*| dvexpr '>' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_GT, $3); }*/ /*| dvexpr '<' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_GT, $3); }*/ /*| dvexpr '>=' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_GE, $3); }*/ /*| dvexpr '<=' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_GE, $3); }*/ /*| dvexpr '!=' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_NE, $3); }*/ | dvexpr LEFT_OP dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_SHL, $3); } | dvexpr RIGHT_OP dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_SHR, $3); } | dvexpr '+' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_ADD, $3); } | dvexpr '-' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_SUB, $3); } | dvexpr '*' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_MUL, $3); } | dvexpr '/' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_DIV, $3); } | dvexpr SIGNDIV dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_SIGNDIV, $3); } | dvexpr '%' dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_MOD, $3); } | dvexpr SIGNMOD dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_SIGNMOD, $3); } | '+' dvexpr %prec UNARYOP { $$ = $2; } | '-' dvexpr %prec UNARYOP { $$ = p_expr_new_branch(YASM_EXPR_NEG, $2); } /*| '!' dvexpr { $$ = p_expr_new_branch(YASM_EXPR_LNOT, $2); }*/ | '~' dvexpr %prec UNARYOP { $$ = p_expr_new_branch(YASM_EXPR_NOT, $2); } | SEG dvexpr { $$ = p_expr_new_branch(YASM_EXPR_SEG, $2); } | dvexpr WRT dvexpr { $$ = p_expr_new_tree($1, YASM_EXPR_WRT, $3); } | '(' dvexpr ')' { $$ = $2; };/* Expressions for operands and memory expressions. * We don't attempt to check memory expressions for validity here. * Essentially the same as expr_no_string above but adds REG and STRING. */expr: INTNUM { $$ = p_expr_new_ident(yasm_expr_int($1)); } | FLTNUM { $$ = p_expr_new_ident(yasm_expr_float($1)); } | REG { $$ = p_expr_new_ident(yasm_expr_reg($1[0])); } | STRING { $$ = p_expr_new_ident(yasm_expr_int( yasm_intnum_create_charconst_nasm($1, cur_line))); yasm_xfree($1); } | explabel { $$ = p_expr_new_ident(yasm_expr_sym($1)); } /*| expr '||' expr { $$ = p_expr_new_tree($1, YASM_EXPR_LOR, $3); }*/ | expr '|' expr { $$ = p_expr_new_tree($1, YASM_EXPR_OR, $3); } | expr '^' expr { $$ = p_expr_new_tree($1, YASM_EXPR_XOR, $3); } /*| expr '&&' expr { $$ = p_expr_new_tree($1, YASM_EXPR_LAND, $3); }*/ | expr '&' expr { $$ = p_expr_new_tree($1, YASM_EXPR_AND, $3); } /*| expr '==' expr { $$ = p_expr_new_tree($1, YASM_EXPR_EQUALS, $3); }*/ /*| expr '>' expr { $$ = p_expr_new_tree($1, YASM_EXPR_GT, $3); }*/ /*| expr '<' expr { $$ = p_expr_new_tree($1, YASM_EXPR_GT, $3); }*/ /*| expr '>=' expr { $$ = p_expr_new_tree($1, YASM_EXPR_GE, $3); }*/ /*| expr '<=' expr { $$ = p_expr_new_tree($1, YASM_EXPR_GE, $3); }*/ /*| expr '!=' expr { $$ = p_expr_new_tree($1, YASM_EXPR_NE, $3); }*/ | expr LEFT_OP expr { $$ = p_expr_new_tree($1, YASM_EXPR_SHL, $3); } | expr RIGHT_OP expr { $$ = p_expr_new_tree($1, YASM_EXPR_SHR, $3); } | expr '+' expr { $$ = p_expr_new_tree($1, YASM_EXPR_ADD, $3); } | expr '-' expr { $$ = p_expr_new_tree($1, YASM_EXPR_SUB, $3); } | expr '*' expr { $$ = p_expr_new_tree($1, YASM_EXPR_MUL, $3); } | expr '/' expr { $$ = p_expr_new_tree($1, YASM_EXPR_DIV, $3); } | expr SIGNDIV expr { $$ = p_expr_new_tree($1, YASM_EXPR_SIGNDIV, $3); } | expr '%' expr { $$ = p_expr_new_tree($1, YASM_EXPR_MOD, $3); } | expr SIGNMOD expr { $$ = p_expr_new_tree($1, YASM_EXPR_SIGNMOD, $3); } | '+' expr %prec UNARYOP { $$ = $2; } | '-' expr %prec UNARYOP { $$ = p_expr_new_branch(YASM_EXPR_NEG, $2); } /*| '!' expr { $$ = p_expr_new_branch(YASM_EXPR_LNOT, $2); }*/ | '~' expr %prec UNARYOP { $$ = p_expr_new_branch(YASM_EXPR_NOT, $2); } | SEG expr { $$ = p_expr_new_branch(YASM_EXPR_SEG, $2); } | expr WRT expr { $$ = p_expr_new_tree($1, YASM_EXPR_WRT, $3); } | expr ':' expr { $$ = p_expr_new_tree($1, YASM_EXPR_SEGOFF, $3); } | '(' expr ')' { $$ = $2; };explabel: ID { $$ = yasm_symtab_use(p_symtab, $1, cur_line); yasm_xfree($1); } | SPECIAL_ID { $$ = yasm_symtab_use(p_symtab, $1, cur_line); yasm_xfree($1); } | LOCAL_ID { $$ = yasm_symtab_use(p_symtab, $1, cur_line); yasm_xfree($1); } | '$' { /* "$" references the current assembly position */ $$ = yasm_symtab_define_label(p_symtab, "$", parser_nasm->prev_bc, 0, cur_line); } | START_SECTION_ID { /* "$$" references the start of the current section */ $$ = yasm_symtab_define_label(p_symtab, "$$", yasm_section_bcs_first(parser_nasm->cur_section), 0, cur_line); };%%/*@=usedef =nullassign =memtrans =usereleased =compdef =mustfree@*/#undef parser_nasmstatic voiddefine_label(yasm_parser_nasm *parser_nasm, char *name, int local){ if (!local) { if (parser_nasm->locallabel_base) yasm_xfree(parser_nasm->locallabel_base); parser_nasm->locallabel_base_len = strlen(name); parser_nasm->locallabel_base = yasm_xmalloc(parser_nasm->locallabel_base_len+1); strcpy(parser_nasm->locallabel_base, name); } yasm_symtab_define_label(p_symtab, name, parser_nasm->prev_bc, 1, cur_line); yasm_xfree(name);}static intfix_directive_symrec(yasm_expr__item *ei, void *d){ yasm_parser_nasm *parser_nasm = (yasm_parser_nasm *)d; if (!ei || ei->type != YASM_EXPR_SYM) return 0; /* FIXME: Delete current symrec */ ei->data.sym = yasm_symtab_use(p_symtab, yasm_symrec_get_name(ei->data.sym), cur_line); return 0;}static voidnasm_parser_directive(yasm_parser_nasm *parser_nasm, const char *name, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams){ yasm_valparam *vp, *vp2; unsigned long line = cur_line; /* Handle (mostly) output-format independent directives here */ if (yasm__strcasecmp(name, "extern") == 0) { vp = yasm_vps_first(valparams); if (vp->val) { yasm_objfmt_extern_declare(parser_nasm->objfmt, vp->val, objext_valparams, line); } else yasm__error(line, N_("invalid argument to [%s]"), "EXTERN"); } else if (yasm__strcasecmp(name, "global") == 0) { vp = yasm_vps_first(valparams); if (vp->val) { yasm_objfmt_global_declare(parser_nasm->objfmt, vp->val, objext_valparams, line); } else yasm__error(line, N_("invalid argument to [%s]"), "GLOBAL"); } else if (yasm__strcasecmp(name, "common") == 0) { vp = yasm_vps_first(valparams); if (vp->val) { vp2 = yasm_vps_next(vp); if (!vp2 || (!vp2->val && !vp2->param)) yasm__error(line, N_("no size specified in %s declaration"), "COMMON"); else { if (vp2->val) { yasm_objfmt_common_declare(parser_nasm->objfmt, vp->val, p_expr_new_ident(yasm_expr_sym( yasm_symtab_use(p_symtab, vp2->val, line))), objext_valparams, line); } else if (vp2->param) { yasm_objfmt_common_declare(parser_nasm->objfmt, vp->val, vp2->param, objext_valparams, line); vp2->param = NULL; } } } else yasm__error(line, N_("invalid argument to [%s]"), "COMMON"); } else if (yasm__strcasecmp(name, "section") == 0 || yasm__strcasecmp(name, "segment") == 0) { yasm_section *new_section = yasm_objfmt_section_switch(parser_nasm->objfmt, valparams, objext_valparams, line); if (new_section) { parser_nasm->cur_section = new_section; parser_nasm->prev_bc = yasm_section_bcs_last(new_section); } else yasm__error(line, N_("invalid argument to [%s]"), "SECTION"); } else if (yasm__strcasecmp(name, "absolute") == 0) { /* it can be just an ID or a complete expression, so handle both. */ vp = yasm_vps_first(valparams); if (vp->val) parser_nasm->cur_section = yasm_object_create_absolute(parser_nasm->object, p_expr_new_ident(yasm_expr_sym( yasm_symtab_use(p_symtab, vp->val, line))), line); else if (vp->param) { parser_nasm->cur_section = yasm_object_create_absolute(parser_nasm->object, vp->param, line); vp->param = NULL; } parser_nasm->prev_bc = yasm_section_bcs_last(parser_nasm->cur_section); } else if (yasm__strcasecmp(name, "cpu") == 0) { yasm_vps_foreach(vp, valparams) { if (vp->val) yasm_arch_parse_cpu(parser_nasm->arch, vp->val, line); else if (vp->param) { const yasm_intnum *intcpu; intcpu = yasm_expr_get_intnum(&vp->param, NULL); if (!intcpu) yasm__error(line, N_("invalid argument to [%s]"), "CPU"); else { char strcpu[16]; sprintf(strcpu, "%lu", yasm_intnum_get_uint(intcpu)); yasm_arch_parse_cpu(parser_nasm->arch, strcpu, line); } } } } else if (!yasm_arch_parse_directive(parser_nasm->arch, name, valparams, objext_valparams, parser_nasm->object, line)) { ; } else if (yasm_objfmt_directive(parser_nasm->objfmt, name, valparams, objext_valparams, line)) { yasm__error(line, N_("unrecognized directive [%s]"), name); } yasm_vps_delete(valparams); if (objext_valparams) yasm_vps_delete(objext_valparams);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -