]> granicus.if.org Git - yasm/commitdiff
Start building of sections and bytecodes in parser.
authorPeter Johnson <peter@tortall.net>
Sun, 16 Sep 2001 18:53:47 +0000 (18:53 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 16 Sep 2001 18:53:47 +0000 (18:53 -0000)
Still need to add section switching (currently never switches away from
default section).

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

libyasm/section.h
modules/parsers/nasm/bison.y.in
modules/parsers/nasm/nasm-bison.y
modules/parsers/nasm/nasm-parser.c
modules/parsers/nasm/parser.c
src/parsers/nasm/bison.y.in
src/parsers/nasm/nasm-bison.y
src/parsers/nasm/nasm-parser.c
src/parsers/nasm/parser.c
src/section.h

index 43efd819ffabc7ff0fef344b9ec98bbd87214daf..0dd0b45ba90dd091cfbb1bfa002236ea43de8bde 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: section.h,v 1.6 2001/09/16 04:49:46 peter Exp $
+/* $Id: section.h,v 1.7 2001/09/16 18:53:47 peter Exp $
  * Section header file
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -27,14 +27,15 @@ typedef STAILQ_HEAD(sectionhead_s, section_s) sectionhead;
 typedef struct section_s {
     STAILQ_ENTRY(section_s) link;
 
-    enum { SECTIONABSOLUTE } type;
+    enum { SECTION_DEFAULT, SECTION_GENERAL, SECTION_ABSOLUTE } type;
 
     char *name;
     unsigned int id;
 
     union {
-       /* SECTION data */
-       /* ABSOLUTE data */
+       /* SECTION_DEFAULT data */
+       /* SECTION_GENERAL data */
+       /* SECTION_ABSOLUTE data */
        unsigned long start;
     } data;
 
index c1cab314668c8fe8b7fc8d151db6f8ad74efb320..641b19131d0a069211312a0a1f472673aea8d78a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $
+/* $Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson, Michael Urman
@@ -40,8 +40,9 @@
 #include "symrec.h"
 
 #include "bytecode.h"
+#include "section.h"
 
-RCSID("$Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $");
+RCSID("$Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $");
 
 #define YYDEBUG 1
 
@@ -50,6 +51,10 @@ extern int nasm_parser_lex(void);
 static unsigned long ConvertCharConstToInt(char *);
 void nasm_parser_error(char *);
 
+extern section *nasm_parser_cur_section;
+
+static bytecode *new_bc;
+
 %}
 
 %union {
@@ -121,11 +126,22 @@ void nasm_parser_error(char *);
 
 %%
 input: /* empty */
-    | input line { OutputError(); OutputWarning(); line_number++; }
+    | input line {
+       OutputError();
+       OutputWarning();
+       if ($2.type != BC_EMPTY) {
+           new_bc = malloc(sizeof(bytecode));
+           if(!new_bc)
+               Fatal(FATAL_NOMEM);
+           memcpy(new_bc, &$2, sizeof(bytecode));
+           STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+       }
+       line_number++;
+    }
 ;
 
 line: '\n'     { $$.type = BC_EMPTY; }
-    | exp '\n' { DebugPrintBC(&$1); $$ = $1; }
+    | exp '\n'
     | directive '\n' { $$.type = BC_EMPTY; }
     | error '\n' {
        Error(_("label or instruction expected at start of line"));
index 84720ffb600c5e6f768a7137db5849d4765d01f2..655924e037cbb52715ee788d220185076775c2f5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $
+/* $Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson, Michael Urman
@@ -40,8 +40,9 @@
 #include "symrec.h"
 
 #include "bytecode.h"
+#include "section.h"
 
-RCSID("$Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $");
+RCSID("$Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $");
 
 #define YYDEBUG 1
 
@@ -50,6 +51,10 @@ extern int nasm_parser_lex(void);
 static unsigned long ConvertCharConstToInt(char *);
 void nasm_parser_error(char *);
 
+extern section *nasm_parser_cur_section;
+
+static bytecode *new_bc;
+
 %}
 
 %union {
@@ -121,11 +126,22 @@ void nasm_parser_error(char *);
 
 %%
 input: /* empty */
-    | input line { OutputError(); OutputWarning(); line_number++; }
+    | input line {
+       OutputError();
+       OutputWarning();
+       if ($2.type != BC_EMPTY) {
+           new_bc = malloc(sizeof(bytecode));
+           if(!new_bc)
+               Fatal(FATAL_NOMEM);
+           memcpy(new_bc, &$2, sizeof(bytecode));
+           STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+       }
+       line_number++;
+    }
 ;
 
 line: '\n'     { $$.type = BC_EMPTY; }
-    | exp '\n' { DebugPrintBC(&$1); $$ = $1; }
+    | exp '\n'
     | directive '\n' { $$.type = BC_EMPTY; }
     | error '\n' {
        Error(_("label or instruction expected at start of line"));
index 9981e046cfff3c5aeacd014d327f3e72ed99675b..836965ecedf27507b92c11e0f4ac4664a59660f0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
+/* $Id: nasm-parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $
  * NASM-compatible parser
  *
  *  Copyright (C) 2001  Peter Johnson
 
 #include <stdio.h>
 
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
+#include "errwarn.h"
+
 #include "bytecode.h"
 #include "section.h"
 #include "objfmt.h"
 #include "preproc.h"
 #include "parser.h"
 
-RCSID("$Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
+RCSID("$Id: nasm-parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $");
 
 extern FILE *nasm_parser_in;
 extern int nasm_parser_debug;
@@ -42,6 +48,9 @@ extern int nasm_parser_parse(void);
 
 int (*nasm_parser_yyinput) (char *buf, int max_size);
 
+sectionhead nasm_parser_sections;
+section *nasm_parser_cur_section;
+
 static sectionhead *
 nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
 {
@@ -49,12 +58,25 @@ nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
     nasm_parser_in = f;
     nasm_parser_yyinput = p->current_pp->input;
 
+    /* Initialize linked list */
+    STAILQ_INIT(&nasm_parser_sections);
+
+    /* Add an initial "default" section to the list */
+    nasm_parser_cur_section = calloc(1, sizeof(section));
+    if (!nasm_parser_cur_section)
+       Fatal(FATAL_NOMEM);
+    STAILQ_INSERT_TAIL(&nasm_parser_sections, nasm_parser_cur_section, link);
+
+    /* Initialize default section */
+    nasm_parser_cur_section->type = SECTION_DEFAULT;
+    STAILQ_INIT(&nasm_parser_cur_section->bc);
+
     /* only temporary */
-    nasm_parser_debug = 1;
+    nasm_parser_debug = 0;
 
     nasm_parser_parse();
 
-    return NULL;
+    return &nasm_parser_sections;
 }
 
 /* Define valid preprocessors to use with this parser */
index 449279c65994f34ed5de0f471d3cdb99570cc9c4..b2edcb8ccfeb79359d69103c7de0e52829e6160c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
+/* $Id: parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $
  * NASM-compatible parser
  *
  *  Copyright (C) 2001  Peter Johnson
 
 #include <stdio.h>
 
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
+#include "errwarn.h"
+
 #include "bytecode.h"
 #include "section.h"
 #include "objfmt.h"
 #include "preproc.h"
 #include "parser.h"
 
-RCSID("$Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
+RCSID("$Id: parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $");
 
 extern FILE *nasm_parser_in;
 extern int nasm_parser_debug;
@@ -42,6 +48,9 @@ extern int nasm_parser_parse(void);
 
 int (*nasm_parser_yyinput) (char *buf, int max_size);
 
+sectionhead nasm_parser_sections;
+section *nasm_parser_cur_section;
+
 static sectionhead *
 nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
 {
@@ -49,12 +58,25 @@ nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
     nasm_parser_in = f;
     nasm_parser_yyinput = p->current_pp->input;
 
+    /* Initialize linked list */
+    STAILQ_INIT(&nasm_parser_sections);
+
+    /* Add an initial "default" section to the list */
+    nasm_parser_cur_section = calloc(1, sizeof(section));
+    if (!nasm_parser_cur_section)
+       Fatal(FATAL_NOMEM);
+    STAILQ_INSERT_TAIL(&nasm_parser_sections, nasm_parser_cur_section, link);
+
+    /* Initialize default section */
+    nasm_parser_cur_section->type = SECTION_DEFAULT;
+    STAILQ_INIT(&nasm_parser_cur_section->bc);
+
     /* only temporary */
-    nasm_parser_debug = 1;
+    nasm_parser_debug = 0;
 
     nasm_parser_parse();
 
-    return NULL;
+    return &nasm_parser_sections;
 }
 
 /* Define valid preprocessors to use with this parser */
index c1cab314668c8fe8b7fc8d151db6f8ad74efb320..641b19131d0a069211312a0a1f472673aea8d78a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $
+/* $Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson, Michael Urman
@@ -40,8 +40,9 @@
 #include "symrec.h"
 
 #include "bytecode.h"
+#include "section.h"
 
-RCSID("$Id: bison.y.in,v 1.28 2001/08/30 03:45:26 peter Exp $");
+RCSID("$Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $");
 
 #define YYDEBUG 1
 
@@ -50,6 +51,10 @@ extern int nasm_parser_lex(void);
 static unsigned long ConvertCharConstToInt(char *);
 void nasm_parser_error(char *);
 
+extern section *nasm_parser_cur_section;
+
+static bytecode *new_bc;
+
 %}
 
 %union {
@@ -121,11 +126,22 @@ void nasm_parser_error(char *);
 
 %%
 input: /* empty */
-    | input line { OutputError(); OutputWarning(); line_number++; }
+    | input line {
+       OutputError();
+       OutputWarning();
+       if ($2.type != BC_EMPTY) {
+           new_bc = malloc(sizeof(bytecode));
+           if(!new_bc)
+               Fatal(FATAL_NOMEM);
+           memcpy(new_bc, &$2, sizeof(bytecode));
+           STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+       }
+       line_number++;
+    }
 ;
 
 line: '\n'     { $$.type = BC_EMPTY; }
-    | exp '\n' { DebugPrintBC(&$1); $$ = $1; }
+    | exp '\n'
     | directive '\n' { $$.type = BC_EMPTY; }
     | error '\n' {
        Error(_("label or instruction expected at start of line"));
index 84720ffb600c5e6f768a7137db5849d4765d01f2..655924e037cbb52715ee788d220185076775c2f5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $
+/* $Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $
  * Main bison parser
  *
  *  Copyright (C) 2001  Peter Johnson, Michael Urman
@@ -40,8 +40,9 @@
 #include "symrec.h"
 
 #include "bytecode.h"
+#include "section.h"
 
-RCSID("$Id: nasm-bison.y,v 1.28 2001/08/30 03:45:26 peter Exp $");
+RCSID("$Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $");
 
 #define YYDEBUG 1
 
@@ -50,6 +51,10 @@ extern int nasm_parser_lex(void);
 static unsigned long ConvertCharConstToInt(char *);
 void nasm_parser_error(char *);
 
+extern section *nasm_parser_cur_section;
+
+static bytecode *new_bc;
+
 %}
 
 %union {
@@ -121,11 +126,22 @@ void nasm_parser_error(char *);
 
 %%
 input: /* empty */
-    | input line { OutputError(); OutputWarning(); line_number++; }
+    | input line {
+       OutputError();
+       OutputWarning();
+       if ($2.type != BC_EMPTY) {
+           new_bc = malloc(sizeof(bytecode));
+           if(!new_bc)
+               Fatal(FATAL_NOMEM);
+           memcpy(new_bc, &$2, sizeof(bytecode));
+           STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+       }
+       line_number++;
+    }
 ;
 
 line: '\n'     { $$.type = BC_EMPTY; }
-    | exp '\n' { DebugPrintBC(&$1); $$ = $1; }
+    | exp '\n'
     | directive '\n' { $$.type = BC_EMPTY; }
     | error '\n' {
        Error(_("label or instruction expected at start of line"));
index 9981e046cfff3c5aeacd014d327f3e72ed99675b..836965ecedf27507b92c11e0f4ac4664a59660f0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
+/* $Id: nasm-parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $
  * NASM-compatible parser
  *
  *  Copyright (C) 2001  Peter Johnson
 
 #include <stdio.h>
 
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
+#include "errwarn.h"
+
 #include "bytecode.h"
 #include "section.h"
 #include "objfmt.h"
 #include "preproc.h"
 #include "parser.h"
 
-RCSID("$Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
+RCSID("$Id: nasm-parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $");
 
 extern FILE *nasm_parser_in;
 extern int nasm_parser_debug;
@@ -42,6 +48,9 @@ extern int nasm_parser_parse(void);
 
 int (*nasm_parser_yyinput) (char *buf, int max_size);
 
+sectionhead nasm_parser_sections;
+section *nasm_parser_cur_section;
+
 static sectionhead *
 nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
 {
@@ -49,12 +58,25 @@ nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
     nasm_parser_in = f;
     nasm_parser_yyinput = p->current_pp->input;
 
+    /* Initialize linked list */
+    STAILQ_INIT(&nasm_parser_sections);
+
+    /* Add an initial "default" section to the list */
+    nasm_parser_cur_section = calloc(1, sizeof(section));
+    if (!nasm_parser_cur_section)
+       Fatal(FATAL_NOMEM);
+    STAILQ_INSERT_TAIL(&nasm_parser_sections, nasm_parser_cur_section, link);
+
+    /* Initialize default section */
+    nasm_parser_cur_section->type = SECTION_DEFAULT;
+    STAILQ_INIT(&nasm_parser_cur_section->bc);
+
     /* only temporary */
-    nasm_parser_debug = 1;
+    nasm_parser_debug = 0;
 
     nasm_parser_parse();
 
-    return NULL;
+    return &nasm_parser_sections;
 }
 
 /* Define valid preprocessors to use with this parser */
index 449279c65994f34ed5de0f471d3cdb99570cc9c4..b2edcb8ccfeb79359d69103c7de0e52829e6160c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
+/* $Id: parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $
  * NASM-compatible parser
  *
  *  Copyright (C) 2001  Peter Johnson
 
 #include <stdio.h>
 
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
+#include "errwarn.h"
+
 #include "bytecode.h"
 #include "section.h"
 #include "objfmt.h"
 #include "preproc.h"
 #include "parser.h"
 
-RCSID("$Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
+RCSID("$Id: parser.c,v 1.9 2001/09/16 18:53:47 peter Exp $");
 
 extern FILE *nasm_parser_in;
 extern int nasm_parser_debug;
@@ -42,6 +48,9 @@ extern int nasm_parser_parse(void);
 
 int (*nasm_parser_yyinput) (char *buf, int max_size);
 
+sectionhead nasm_parser_sections;
+section *nasm_parser_cur_section;
+
 static sectionhead *
 nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
 {
@@ -49,12 +58,25 @@ nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
     nasm_parser_in = f;
     nasm_parser_yyinput = p->current_pp->input;
 
+    /* Initialize linked list */
+    STAILQ_INIT(&nasm_parser_sections);
+
+    /* Add an initial "default" section to the list */
+    nasm_parser_cur_section = calloc(1, sizeof(section));
+    if (!nasm_parser_cur_section)
+       Fatal(FATAL_NOMEM);
+    STAILQ_INSERT_TAIL(&nasm_parser_sections, nasm_parser_cur_section, link);
+
+    /* Initialize default section */
+    nasm_parser_cur_section->type = SECTION_DEFAULT;
+    STAILQ_INIT(&nasm_parser_cur_section->bc);
+
     /* only temporary */
-    nasm_parser_debug = 1;
+    nasm_parser_debug = 0;
 
     nasm_parser_parse();
 
-    return NULL;
+    return &nasm_parser_sections;
 }
 
 /* Define valid preprocessors to use with this parser */
index 43efd819ffabc7ff0fef344b9ec98bbd87214daf..0dd0b45ba90dd091cfbb1bfa002236ea43de8bde 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: section.h,v 1.6 2001/09/16 04:49:46 peter Exp $
+/* $Id: section.h,v 1.7 2001/09/16 18:53:47 peter Exp $
  * Section header file
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -27,14 +27,15 @@ typedef STAILQ_HEAD(sectionhead_s, section_s) sectionhead;
 typedef struct section_s {
     STAILQ_ENTRY(section_s) link;
 
-    enum { SECTIONABSOLUTE } type;
+    enum { SECTION_DEFAULT, SECTION_GENERAL, SECTION_ABSOLUTE } type;
 
     char *name;
     unsigned int id;
 
     union {
-       /* SECTION data */
-       /* ABSOLUTE data */
+       /* SECTION_DEFAULT data */
+       /* SECTION_GENERAL data */
+       /* SECTION_ABSOLUTE data */
        unsigned long start;
     } data;