]> granicus.if.org Git - yasm/commitdiff
Don't use tasm_compatible_mode in nasm parser (use local var instead).
authorPeter Johnson <peter@tortall.net>
Tue, 7 Oct 2008 06:02:12 +0000 (06:02 -0000)
committerPeter Johnson <peter@tortall.net>
Tue, 7 Oct 2008 06:02:12 +0000 (06:02 -0000)
Fix a few warnings while here.

svn path=/trunk/yasm/; revision=2134

modules/parsers/nasm/nasm-parse.c
modules/parsers/nasm/nasm-parser.c
modules/parsers/nasm/nasm-parser.h
modules/parsers/nasm/nasm-token.re

index 7afd00861b9729ce25dcbc5a1d159426839c9d32..0e80b582ef8db7a21ceee436185cb3733791431e 100644 (file)
@@ -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);
index 12070061fb89f306fed2fdd3101ff89afc9fd9c4..ba3263ae3fe69213168165ef5f06c66625732786 100644 (file)
 
 #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 */
index 63127589b2aa0b8502368138e51a847aa79fa17a..3312027eb97bc7c4e6f2767363db64826275b78c 100644 (file)
@@ -87,6 +87,8 @@ typedef union {
 #define YYSTYPE yystype
 
 typedef struct yasm_parser_nasm {
+    int tasm;
+
     int debug;
 
     /*@only@*/ yasm_object *object;
index 72e15080e533b6b96ae02a86deb2e7d45caf726c..23a81a229f8165306678c66a1c1c2856634fd330 100644 (file)
@@ -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;
             }