From: Peter Johnson Date: Tue, 7 Oct 2008 06:02:12 +0000 (-0000) Subject: Don't use tasm_compatible_mode in nasm parser (use local var instead). X-Git-Tag: v0.8.0~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8986aa0764fb69855bba04f3d4f3580fcccccd1a;p=yasm Don't use tasm_compatible_mode in nasm parser (use local var instead). Fix a few warnings while here. svn path=/trunk/yasm/; revision=2134 --- diff --git a/modules/parsers/nasm/nasm-parse.c b/modules/parsers/nasm/nasm-parse.c index 7afd0086..0e80b582 100644 --- a/modules/parsers/nasm/nasm-parse.c +++ b/modules/parsers/nasm/nasm-parse.c @@ -68,7 +68,7 @@ static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name, static void yasm_ea_set_implicit_size_segment(yasm_parser_nasm *parser_nasm, yasm_effaddr *ea, yasm_expr *e) { - if (tasm_compatible_mode) { + if (parser_nasm->tasm) { const char *segment = yasm_expr_segment(e); ea->data_len = yasm_expr_size(e); if (segment) { @@ -373,7 +373,7 @@ parse_line(yasm_parser_nasm *parser_nasm) case LOCAL_ID: { char *name = ID_val; - int local = tasm_compatible_mode + int local = parser_nasm->tasm ? (curtok == ID || curtok == LOCAL_ID || (curtok == SPECIAL_ID && name[0] == '@')) : (curtok != ID); @@ -390,12 +390,12 @@ parse_line(yasm_parser_nasm *parser_nasm) if (curtok == ':') get_next_token(); - if (curtok == EQU || (tasm_compatible_mode && curtok == '=')) { + if (curtok == EQU || (parser_nasm->tasm && curtok == '=')) { /* label EQU expr */ yasm_expr *e; get_next_token(); - if (tasm_compatible_mode && curtok == SIZE_OVERRIDE) { + if (parser_nasm->tasm && curtok == SIZE_OVERRIDE) { size = SIZE_OVERRIDE_val; get_next_token(); } @@ -412,10 +412,10 @@ parse_line(yasm_parser_nasm *parser_nasm) return NULL; } - if (tasm_compatible_mode && curtok == LABEL) + if (parser_nasm->tasm && curtok == LABEL) get_next_token(); - if (tasm_compatible_mode && curtok == SIZE_OVERRIDE) { + if (parser_nasm->tasm && curtok == SIZE_OVERRIDE) { size = SIZE_OVERRIDE_val; get_next_token(); } @@ -430,10 +430,10 @@ parse_line(yasm_parser_nasm *parser_nasm) return parse_times(parser_nasm); } bc = parse_exp(parser_nasm); - if (!tasm_compatible_mode && !bc) + if (!parser_nasm->tasm && !bc) yasm_error_set(YASM_ERROR_SYNTAX, N_("instruction expected after label")); - if (tasm_compatible_mode && bc && !size) + if (parser_nasm->tasm && bc && !size) size = yasm_bc_elem_size(bc); define_label(parser_nasm, name, size, local); return bc; @@ -795,8 +795,8 @@ parse_operand(yasm_parser_nasm *parser_nasm) return NULL; } - if (tasm_compatible_mode && !is_eol() && curtok != ',') { - yasm_expr *e, *f; + if (parser_nasm->tasm && !is_eol() && curtok != ',') { + yasm_expr *e = NULL, *f; yasm_effaddr *ea; switch (op->type) { @@ -867,7 +867,7 @@ parse_operand(yasm_parser_nasm *parser_nasm) { uintptr_t segreg = SEGREG_val; get_next_token(); - if (tasm_compatible_mode && curtok == ':') { + if (parser_nasm->tasm && curtok == ':') { get_next_token(); op = parse_operand(parser_nasm); if (!op) @@ -875,8 +875,10 @@ parse_operand(yasm_parser_nasm *parser_nasm) if (op->type == YASM_INSN__OPERAND_IMM) { yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch, op->data.val); - yasm_ea_set_implicit_size_segment(parser_nasm, ea, op->data.val); - yasm_insn_operand *op2 = yasm_operand_create_mem(ea); + yasm_insn_operand *op2; + yasm_ea_set_implicit_size_segment(parser_nasm, ea, + op->data.val); + op2 = yasm_operand_create_mem(ea); op2->size = op->size; yasm_xfree(op); op = op2; @@ -946,7 +948,7 @@ parse_operand(yasm_parser_nasm *parser_nasm) case ID: case LOCAL_ID: case NONLOCAL_ID: - if (tasm_compatible_mode) { + if (parser_nasm->tasm) { get_peek_token(parser_nasm); if (parser_nasm->peek_token == '[') { yasm_symrec *sym = yasm_symtab_use(p_symtab, ID_val, @@ -981,7 +983,7 @@ parse_operand(yasm_parser_nasm *parser_nasm) if (!e) return NULL; if (curtok != ':') - if (tasm_compatible_mode && yasm_expr_size(e)) { + if (parser_nasm->tasm && yasm_expr_size(e)) { yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch, e); yasm_ea_set_implicit_size_segment(parser_nasm, ea, e); op = yasm_operand_create_mem(ea); @@ -1386,7 +1388,7 @@ parse_expr6(yasm_parser_nasm *parser_nasm, expr_type type) case STRING: { yasm_intnum *intn; - if (tasm_compatible_mode) + if (parser_nasm->tasm) intn = yasm_intnum_create_charconst_tasm(STRING_val.contents); else intn = yasm_intnum_create_charconst_nasm(STRING_val.contents); @@ -1442,7 +1444,7 @@ define_label(yasm_parser_nasm *parser_nasm, char *name, unsigned int size, { yasm_symrec *symrec; - if ((!tasm_compatible_mode || tasm_locals) && !local) { + if ((!parser_nasm->tasm || tasm_locals) && !local) { if (parser_nasm->locallabel_base) yasm_xfree(parser_nasm->locallabel_base); parser_nasm->locallabel_base_len = strlen(name); diff --git a/modules/parsers/nasm/nasm-parser.c b/modules/parsers/nasm/nasm-parser.c index 12070061..ba3263ae 100644 --- a/modules/parsers/nasm/nasm-parser.c +++ b/modules/parsers/nasm/nasm-parser.c @@ -31,16 +31,15 @@ #include "nasm-parser.h" -#include "modules/preprocs/nasm/nasm.h" - static void -nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, - int save_input, yasm_linemap *linemap, - yasm_errwarns *errwarns) +nasm_do_parse(yasm_object *object, yasm_preproc *pp, int save_input, + yasm_linemap *linemap, yasm_errwarns *errwarns, int tasm) { yasm_parser_nasm parser_nasm; + parser_nasm.tasm = tasm; + parser_nasm.object = object; parser_nasm.linemap = linemap; @@ -79,6 +78,14 @@ nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_symtab_parser_finalize(object->symtab, 0, errwarns); } +static void +nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, + int save_input, yasm_linemap *linemap, + yasm_errwarns *errwarns) +{ + nasm_do_parse(object, pp, save_input, linemap, errwarns, 0); +} + #include "nasm-macros.c" /* Define valid preprocessors to use with this parser */ @@ -108,10 +115,9 @@ tasm_parser_do_parse(yasm_object *object, yasm_preproc *pp, int save_input, yasm_linemap *linemap, yasm_errwarns *errwarns) { - tasm_compatible_mode = 1; yasm_symtab_set_case_sensitive(object->symtab, 0); yasm_warn_disable(YASM_WARN_IMPLICIT_SIZE_OVERRIDE); - nasm_parser_do_parse(object, pp, save_input, linemap, errwarns); + nasm_do_parse(object, pp, save_input, linemap, errwarns, 1); } /* Define valid preprocessors to use with this parser */ diff --git a/modules/parsers/nasm/nasm-parser.h b/modules/parsers/nasm/nasm-parser.h index 63127589..3312027e 100644 --- a/modules/parsers/nasm/nasm-parser.h +++ b/modules/parsers/nasm/nasm-parser.h @@ -87,6 +87,8 @@ typedef union { #define YYSTYPE yystype typedef struct yasm_parser_nasm { + int tasm; + int debug; /*@only@*/ yasm_object *object; diff --git a/modules/parsers/nasm/nasm-token.re b/modules/parsers/nasm/nasm-token.re index 72e15080..23a81a22 100644 --- a/modules/parsers/nasm/nasm-token.re +++ b/modules/parsers/nasm/nasm-token.re @@ -77,14 +77,14 @@ handle_dot_label(YYSTYPE *lvalp, char *tok, size_t toklen, size_t zeropos, { /* check for special non-local labels like ..start */ if (tok[zeropos+1] == '.') { - lvalp->str_val = yasm__xstrndup(tok+zeropos+(tasm_compatible_mode?2:0), - toklen-zeropos-(tasm_compatible_mode?2:0)); + lvalp->str_val = yasm__xstrndup(tok+zeropos+(parser_nasm->tasm?2:0), + toklen-zeropos-(parser_nasm->tasm?2:0)); /* check for special non-local ..@label */ if (lvalp->str_val[zeropos+2] == '@') return NONLOCAL_ID; return SPECIAL_ID; } - if (tasm_compatible_mode && (!tasm_locals || + if (parser_nasm->tasm && (!tasm_locals || (tok[zeropos] == '.' && tok[zeropos+1] != '@' && tok[zeropos+2] != '@'))) { /* no locals on Tasm without the 'locals' directive */ @@ -376,7 +376,7 @@ scan: /* forced identifier */ "$" [a-zA-Z0-9_$#@~.?]+ { if (TOK[1] == '.' || - (tasm_compatible_mode && TOK[1] == '@' && TOK[2] == '@')) { + (parser_nasm->tasm && TOK[1] == '@' && TOK[2] == '@')) { /* handle like .label */ RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 1, parser_nasm)); } @@ -419,7 +419,7 @@ scan: default: break; } - if (tasm_compatible_mode) { + if (parser_nasm->tasm) { if (!strcasecmp(TOK, "shl")) { s->tok[TOKLEN] = savech; RETURN(LEFT_OP); @@ -737,7 +737,7 @@ stringconst_scan: strbuf_size + STRBUF_ALLOC_SIZE); strbuf_size += STRBUF_ALLOC_SIZE; } - } else if (!tasm_compatible_mode) { + } else if (!parser_nasm->tasm) { YYCURSOR--; goto stringconst_end; }