]> granicus.if.org Git - yasm/commitdiff
Add support for NASM's %line.
authorPeter Johnson <peter@tortall.net>
Sun, 2 Dec 2001 20:12:04 +0000 (20:12 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 2 Dec 2001 20:12:04 +0000 (20:12 -0000)
svn path=/trunk/yasm/; revision=376

12 files changed:
libyasm/linemgr.c
libyasm/linemgr.h
modules/parsers/nasm/bison.y.in
modules/parsers/nasm/nasm-bison.y
modules/parsers/nasm/token.l.in
src/globals.c
src/globals.h
src/linemgr.c
src/linemgr.h
src/parsers/nasm/bison.y.in
src/parsers/nasm/nasm-bison.y
src/parsers/nasm/token.l.in

index 10d87f5f476a85220c89471e661e94cc99244685..bcdd65e32c1ba3706e14245d0673be7c579596de 100644 (file)
@@ -35,6 +35,7 @@
 
 /*@null@*/ /*@dependent@*/ const char *in_filename = (const char *)NULL;
 unsigned int line_number = 1;
+unsigned int line_number_inc = 1;
 unsigned int asm_options = 0;
 
 int indent_level = 0;
index 4ae8532c5f77375acd459d8ce1a8185d9b03a7e5..be2fcf4359549b32f8788d8e34cf7777266c709b 100644 (file)
@@ -30,6 +30,13 @@ extern /*@null@*/ objfmt *cur_objfmt;
 
 /*@null@*/ /*@dependent@*/ extern const char *in_filename;
 extern unsigned int line_number;
+
+/* Amount to increase line_number by after each line.  Should be 0 or 1, set by
+ * %line (in NASM syntax).  Initialized to 1 at startup.
+ * (0 is for 1-line macros that expand to multiple lines).
+ */
+extern unsigned int line_number_inc;
+
 extern unsigned int asm_options;
 
 extern int indent_level;
index af3c34acbd7bce2a5128ac527fc2eeadb567d206..66d913c785400f6509be42047f42962392203194 100644 (file)
@@ -84,7 +84,7 @@ static bytecode *nasm_parser_temp_bc;
 
 %token <intn> INTNUM
 %token <flt> FLTNUM
-%token <str_val> DIRECTIVE_NAME STRING
+%token <str_val> DIRECTIVE_NAME STRING FILENAME
 %token <int_info> BYTE WORD DWORD QWORD TWORD DQWORD
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
@@ -101,6 +101,7 @@ static bytecode *nasm_parser_temp_bc;
 %token <int_info> REG_ES REG_CS REG_SS REG_DS REG_FS REG_GS
 %token LEFT_OP RIGHT_OP SIGNDIV SIGNMOD START_SECTION_ID
 %token <str_val> ID LOCAL_ID SPECIAL_ID
+%token LINE
 
 /* instruction tokens (dynamically generated) */
 /* @TOKENS@ */
@@ -144,12 +145,22 @@ input: /* empty */
                                               $2);
        if (nasm_parser_temp_bc)
            nasm_parser_prev_bc = nasm_parser_temp_bc;
-       line_number++;
+       line_number += line_number_inc;
     }
 ;
 
 line: '\n'             { $$ = (bytecode *)NULL; }
     | lineexp '\n'
+    | LINE INTNUM '+' INTNUM FILENAME '\n' {
+       line_number = intnum_get_uint($2);
+       line_number_inc = intnum_get_uint($4);
+       line_number -= line_number_inc; /* as we'll add it back in */
+       switch_filename($5);
+       intnum_delete($2);
+       intnum_delete($4);
+       xfree($5);
+       $$ = (bytecode *)NULL;
+    }
     | directive '\n'   { $$ = (bytecode *)NULL; }
     | error '\n'       {
        Error(_("label or instruction expected at start of line"));
index af3c34acbd7bce2a5128ac527fc2eeadb567d206..66d913c785400f6509be42047f42962392203194 100644 (file)
@@ -84,7 +84,7 @@ static bytecode *nasm_parser_temp_bc;
 
 %token <intn> INTNUM
 %token <flt> FLTNUM
-%token <str_val> DIRECTIVE_NAME STRING
+%token <str_val> DIRECTIVE_NAME STRING FILENAME
 %token <int_info> BYTE WORD DWORD QWORD TWORD DQWORD
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
@@ -101,6 +101,7 @@ static bytecode *nasm_parser_temp_bc;
 %token <int_info> REG_ES REG_CS REG_SS REG_DS REG_FS REG_GS
 %token LEFT_OP RIGHT_OP SIGNDIV SIGNMOD START_SECTION_ID
 %token <str_val> ID LOCAL_ID SPECIAL_ID
+%token LINE
 
 /* instruction tokens (dynamically generated) */
 /* @TOKENS@ */
@@ -144,12 +145,22 @@ input: /* empty */
                                               $2);
        if (nasm_parser_temp_bc)
            nasm_parser_prev_bc = nasm_parser_temp_bc;
-       line_number++;
+       line_number += line_number_inc;
     }
 ;
 
 line: '\n'             { $$ = (bytecode *)NULL; }
     | lineexp '\n'
+    | LINE INTNUM '+' INTNUM FILENAME '\n' {
+       line_number = intnum_get_uint($2);
+       line_number_inc = intnum_get_uint($4);
+       line_number -= line_number_inc; /* as we'll add it back in */
+       switch_filename($5);
+       intnum_delete($2);
+       intnum_delete($4);
+       xfree($5);
+       $$ = (bytecode *)NULL;
+    }
     | directive '\n'   { $$ = (bytecode *)NULL; }
     | error '\n'       {
        Error(_("label or instruction expected at start of line"));
index bcaf5aa908506db4956352be25ab997636951712..d3524673d948d0f45f518cc318554d1c590cc6e7 100644 (file)
@@ -60,12 +60,14 @@ static size_t strbuf_size = 0;
 /* last "base" label for local (.) labels */
 char *nasm_parser_locallabel_base = (char *)NULL;
 
+static int linechg_numcount;
+
 %}
 %option noyywrap
 %option nounput
 %option case-insensitive
 
-%x DIRECTIVE
+%x DIRECTIVE LINECHG LINECHG2
 %s DIRECTIVE2
 
 DIGIT    [0-9]
@@ -150,6 +152,27 @@ WS       [ \t\r]
     return STRING;
 }
 
+    /* %line linenum+lineinc filename */
+^%line                 { BEGIN LINECHG; linechg_numcount = 0; return LINE; }
+<LINECHG>{DIGIT}+      {
+    linechg_numcount++;
+    yylval.intn = intnum_new_dec(yytext);
+    return INTNUM;
+}
+<LINECHG>\n            { BEGIN INITIAL; return '\n'; }
+<LINECHG>[+]           { return yytext[0]; }
+<LINECHG>{WS}+         {
+    if (linechg_numcount == 2)
+       BEGIN LINECHG2;
+}
+<LINECHG2>\n           { BEGIN INITIAL; return '\n'; }
+<LINECHG2>\r           ;
+<LINECHG2>[^\r\n]+     {
+    BEGIN LINECHG;
+    yylval.str_val = xstrdup(yytext);
+    return FILENAME;
+}
+
     /* directive: [name value] */
 ^{WS}*"["          { BEGIN DIRECTIVE; return '['; }
 <DIRECTIVE>"]"     { BEGIN INITIAL; return ']'; }
index 10d87f5f476a85220c89471e661e94cc99244685..bcdd65e32c1ba3706e14245d0673be7c579596de 100644 (file)
@@ -35,6 +35,7 @@
 
 /*@null@*/ /*@dependent@*/ const char *in_filename = (const char *)NULL;
 unsigned int line_number = 1;
+unsigned int line_number_inc = 1;
 unsigned int asm_options = 0;
 
 int indent_level = 0;
index 4ae8532c5f77375acd459d8ce1a8185d9b03a7e5..be2fcf4359549b32f8788d8e34cf7777266c709b 100644 (file)
@@ -30,6 +30,13 @@ extern /*@null@*/ objfmt *cur_objfmt;
 
 /*@null@*/ /*@dependent@*/ extern const char *in_filename;
 extern unsigned int line_number;
+
+/* Amount to increase line_number by after each line.  Should be 0 or 1, set by
+ * %line (in NASM syntax).  Initialized to 1 at startup.
+ * (0 is for 1-line macros that expand to multiple lines).
+ */
+extern unsigned int line_number_inc;
+
 extern unsigned int asm_options;
 
 extern int indent_level;
index 10d87f5f476a85220c89471e661e94cc99244685..bcdd65e32c1ba3706e14245d0673be7c579596de 100644 (file)
@@ -35,6 +35,7 @@
 
 /*@null@*/ /*@dependent@*/ const char *in_filename = (const char *)NULL;
 unsigned int line_number = 1;
+unsigned int line_number_inc = 1;
 unsigned int asm_options = 0;
 
 int indent_level = 0;
index 4ae8532c5f77375acd459d8ce1a8185d9b03a7e5..be2fcf4359549b32f8788d8e34cf7777266c709b 100644 (file)
@@ -30,6 +30,13 @@ extern /*@null@*/ objfmt *cur_objfmt;
 
 /*@null@*/ /*@dependent@*/ extern const char *in_filename;
 extern unsigned int line_number;
+
+/* Amount to increase line_number by after each line.  Should be 0 or 1, set by
+ * %line (in NASM syntax).  Initialized to 1 at startup.
+ * (0 is for 1-line macros that expand to multiple lines).
+ */
+extern unsigned int line_number_inc;
+
 extern unsigned int asm_options;
 
 extern int indent_level;
index af3c34acbd7bce2a5128ac527fc2eeadb567d206..66d913c785400f6509be42047f42962392203194 100644 (file)
@@ -84,7 +84,7 @@ static bytecode *nasm_parser_temp_bc;
 
 %token <intn> INTNUM
 %token <flt> FLTNUM
-%token <str_val> DIRECTIVE_NAME STRING
+%token <str_val> DIRECTIVE_NAME STRING FILENAME
 %token <int_info> BYTE WORD DWORD QWORD TWORD DQWORD
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
@@ -101,6 +101,7 @@ static bytecode *nasm_parser_temp_bc;
 %token <int_info> REG_ES REG_CS REG_SS REG_DS REG_FS REG_GS
 %token LEFT_OP RIGHT_OP SIGNDIV SIGNMOD START_SECTION_ID
 %token <str_val> ID LOCAL_ID SPECIAL_ID
+%token LINE
 
 /* instruction tokens (dynamically generated) */
 /* @TOKENS@ */
@@ -144,12 +145,22 @@ input: /* empty */
                                               $2);
        if (nasm_parser_temp_bc)
            nasm_parser_prev_bc = nasm_parser_temp_bc;
-       line_number++;
+       line_number += line_number_inc;
     }
 ;
 
 line: '\n'             { $$ = (bytecode *)NULL; }
     | lineexp '\n'
+    | LINE INTNUM '+' INTNUM FILENAME '\n' {
+       line_number = intnum_get_uint($2);
+       line_number_inc = intnum_get_uint($4);
+       line_number -= line_number_inc; /* as we'll add it back in */
+       switch_filename($5);
+       intnum_delete($2);
+       intnum_delete($4);
+       xfree($5);
+       $$ = (bytecode *)NULL;
+    }
     | directive '\n'   { $$ = (bytecode *)NULL; }
     | error '\n'       {
        Error(_("label or instruction expected at start of line"));
index af3c34acbd7bce2a5128ac527fc2eeadb567d206..66d913c785400f6509be42047f42962392203194 100644 (file)
@@ -84,7 +84,7 @@ static bytecode *nasm_parser_temp_bc;
 
 %token <intn> INTNUM
 %token <flt> FLTNUM
-%token <str_val> DIRECTIVE_NAME STRING
+%token <str_val> DIRECTIVE_NAME STRING FILENAME
 %token <int_info> BYTE WORD DWORD QWORD TWORD DQWORD
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
@@ -101,6 +101,7 @@ static bytecode *nasm_parser_temp_bc;
 %token <int_info> REG_ES REG_CS REG_SS REG_DS REG_FS REG_GS
 %token LEFT_OP RIGHT_OP SIGNDIV SIGNMOD START_SECTION_ID
 %token <str_val> ID LOCAL_ID SPECIAL_ID
+%token LINE
 
 /* instruction tokens (dynamically generated) */
 /* @TOKENS@ */
@@ -144,12 +145,22 @@ input: /* empty */
                                               $2);
        if (nasm_parser_temp_bc)
            nasm_parser_prev_bc = nasm_parser_temp_bc;
-       line_number++;
+       line_number += line_number_inc;
     }
 ;
 
 line: '\n'             { $$ = (bytecode *)NULL; }
     | lineexp '\n'
+    | LINE INTNUM '+' INTNUM FILENAME '\n' {
+       line_number = intnum_get_uint($2);
+       line_number_inc = intnum_get_uint($4);
+       line_number -= line_number_inc; /* as we'll add it back in */
+       switch_filename($5);
+       intnum_delete($2);
+       intnum_delete($4);
+       xfree($5);
+       $$ = (bytecode *)NULL;
+    }
     | directive '\n'   { $$ = (bytecode *)NULL; }
     | error '\n'       {
        Error(_("label or instruction expected at start of line"));
index bcaf5aa908506db4956352be25ab997636951712..d3524673d948d0f45f518cc318554d1c590cc6e7 100644 (file)
@@ -60,12 +60,14 @@ static size_t strbuf_size = 0;
 /* last "base" label for local (.) labels */
 char *nasm_parser_locallabel_base = (char *)NULL;
 
+static int linechg_numcount;
+
 %}
 %option noyywrap
 %option nounput
 %option case-insensitive
 
-%x DIRECTIVE
+%x DIRECTIVE LINECHG LINECHG2
 %s DIRECTIVE2
 
 DIGIT    [0-9]
@@ -150,6 +152,27 @@ WS       [ \t\r]
     return STRING;
 }
 
+    /* %line linenum+lineinc filename */
+^%line                 { BEGIN LINECHG; linechg_numcount = 0; return LINE; }
+<LINECHG>{DIGIT}+      {
+    linechg_numcount++;
+    yylval.intn = intnum_new_dec(yytext);
+    return INTNUM;
+}
+<LINECHG>\n            { BEGIN INITIAL; return '\n'; }
+<LINECHG>[+]           { return yytext[0]; }
+<LINECHG>{WS}+         {
+    if (linechg_numcount == 2)
+       BEGIN LINECHG2;
+}
+<LINECHG2>\n           { BEGIN INITIAL; return '\n'; }
+<LINECHG2>\r           ;
+<LINECHG2>[^\r\n]+     {
+    BEGIN LINECHG;
+    yylval.str_val = xstrdup(yytext);
+    return FILENAME;
+}
+
     /* directive: [name value] */
 ^{WS}*"["          { BEGIN DIRECTIVE; return '['; }
 <DIRECTIVE>"]"     { BEGIN INITIAL; return ']'; }