-/* $Id: yasm.c,v 1.11 2001/09/15 07:16:59 peter Exp $
+/* $Id: yasm.c,v 1.12 2001/09/16 04:49:46 peter Exp $
* Program entry point, command line parsing
*
* Copyright (C) 2001 Peter Johnson
#include "preproc.h"
#include "parser.h"
-RCSID("$Id: yasm.c,v 1.11 2001/09/15 07:16:59 peter Exp $");
+RCSID("$Id: yasm.c,v 1.12 2001/09/16 04:49:46 peter Exp $");
char *filename = (char *)NULL;
unsigned int line_number = 1;
filename = strdup("<STDIN>");
}
- nasm_parser.doparse(&raw_preproc, &dbg_objfmt, in);
+ nasm_parser.doparse(&nasm_parser, &dbg_objfmt, in);
if (filename)
free(filename);
-/* $Id: bytecode.h,v 1.17 2001/08/19 05:41:01 peter Exp $
+/* $Id: bytecode.h,v 1.18 2001/09/16 04:49:46 peter Exp $
* Bytecode utility functions header file
*
* Copyright (C) 2001 Peter Johnson
jmprel_opcode_sel op_sel;
} targetval;
+typedef STAILQ_HEAD(bytecodehead_s, bytecode_s) bytecodehead;
+
typedef struct bytecode_s {
STAILQ_ENTRY(bytecode_s) link;
dataval *dataval_new_float(double float_val);
dataval *dataval_new_string(char *str_val);
-dataval *dataval_append(dataval *list, dataval *item);
-
void dataval_print(datavalhead *head);
#endif
-/* $Id: parser.h,v 1.3 2001/09/15 07:16:59 peter Exp $
+/* $Id: parser.h,v 1.4 2001/09/16 04:49:46 peter Exp $
* Parser module interface header file
*
* Copyright (C) 2001 Peter Johnson
*/
preproc **preprocs;
- /* Default preprocessor (set even if there's only one available to use) */
- preproc *default_pp;
+ /* Current preprocessor (set to the default at compile time) */
+ preproc *current_pp;
/* Main entrance point for the parser.
*
* The parser needs access to both the object format module (for format-
- * specific directives and segment names), and the selected preprocessor
- * (which should naturally be in the preprocs list above).
+ * specific directives and segment names), and the preprocessor
+ * (it uses current_pp as set either at compile-time or by parser_setpp).
*
* This function also takes the FILE * to the initial starting file, but
* not the filename (which is in a global variable and is not
*
* This function returns the starting section of a linked list of sections
* (whatever was in the file).
- *
- * Note that calling this has many side effects in the output format
- * module: sections and variables are declared, etc.
*/
- section *(*doparse) (preproc *pp, objfmt *of, FILE *f);
+ sectionhead *(*doparse) (struct parser_s *p, objfmt *of, FILE *f);
} parser;
+/* Generic functions for all parsers - implemented in src/parser.c */
+
+/* Sets current_pp within p by searching the preprocs list for a preproc
+ * matching pp_keyword. Returns nonzero if no match was found.
+ */
+int parser_setpp(parser *p, const char *pp_keyword);
+
+/* Lists preprocessors available for p. Calls printfunc with the name
+ * and keyword of each available preprocessor.
+ */
+void parser_listpp(parser *p,
+ void (*printfunc) (const char *name, const char *keyword));
+
+/* Finds a parser based on its keyword. Returns NULL if no match was found.
+ */
+parser *find_parser(const char *keyword);
+
+/* Lists all available parsers. Calls printfunc with the name and keyword
+ * of each available parser.
+ */
+void list_parsers(void (*printfunc) (const char *name, const char *keyword));
+
/* Available parsers */
extern parser nasm_parser;
-/* $Id: section.h,v 1.5 2001/08/19 03:52:58 peter Exp $
+/* $Id: section.h,v 1.6 2001/09/16 04:49:46 peter Exp $
* Section header file
*
* Copyright (C) 2001 Peter Johnson
#ifndef YASM_SECTION_H
#define YASM_SECTION_H
+typedef STAILQ_HEAD(sectionhead_s, section_s) sectionhead;
+
typedef struct section_s {
- struct section_s *next;
+ STAILQ_ENTRY(section_s) link;
enum { SECTION, ABSOLUTE } type;
unsigned long start;
} data;
- bytecode *bc; /* the bytecodes for the section's contents */
+ bytecodehead bc; /* the bytecodes for the section's contents */
} section;
#endif
-/* $Id: nasm-parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $
+/* $Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
#include "preproc.h"
#include "parser.h"
-RCSID("$Id: nasm-parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $");
+RCSID("$Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
extern FILE *nasm_parser_in;
extern int nasm_parser_debug;
int (*nasm_parser_yyinput) (char *buf, int max_size);
-static section *
-doparse(preproc *pp, objfmt *of, FILE *f)
+static sectionhead *
+nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
{
- pp->initialize(of, f);
+ p->current_pp->initialize(of, f);
nasm_parser_in = f;
- nasm_parser_yyinput = pp->input;
+ nasm_parser_yyinput = p->current_pp->input;
/* only temporary */
nasm_parser_debug = 1;
}
/* Define valid preprocessors to use with this parser */
-static preproc *preprocs[] = {
+static preproc *nasm_parser_preprocs[] = {
&raw_preproc,
NULL
};
parser nasm_parser = {
"NASM-compatible parser",
"nasm",
- preprocs,
+ nasm_parser_preprocs,
&raw_preproc,
- doparse
+ nasm_parser_doparse
};
-/* $Id: parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $
+/* $Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
#include "preproc.h"
#include "parser.h"
-RCSID("$Id: parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $");
+RCSID("$Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
extern FILE *nasm_parser_in;
extern int nasm_parser_debug;
int (*nasm_parser_yyinput) (char *buf, int max_size);
-static section *
-doparse(preproc *pp, objfmt *of, FILE *f)
+static sectionhead *
+nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
{
- pp->initialize(of, f);
+ p->current_pp->initialize(of, f);
nasm_parser_in = f;
- nasm_parser_yyinput = pp->input;
+ nasm_parser_yyinput = p->current_pp->input;
/* only temporary */
nasm_parser_debug = 1;
}
/* Define valid preprocessors to use with this parser */
-static preproc *preprocs[] = {
+static preproc *nasm_parser_preprocs[] = {
&raw_preproc,
NULL
};
parser nasm_parser = {
"NASM-compatible parser",
"nasm",
- preprocs,
+ nasm_parser_preprocs,
&raw_preproc,
- doparse
+ nasm_parser_doparse
};
section.h \
objfmt.h \
preproc.h \
+ parser.c \
parser.h
yasm_LDADD = \
-/* $Id: bytecode.h,v 1.17 2001/08/19 05:41:01 peter Exp $
+/* $Id: bytecode.h,v 1.18 2001/09/16 04:49:46 peter Exp $
* Bytecode utility functions header file
*
* Copyright (C) 2001 Peter Johnson
jmprel_opcode_sel op_sel;
} targetval;
+typedef STAILQ_HEAD(bytecodehead_s, bytecode_s) bytecodehead;
+
typedef struct bytecode_s {
STAILQ_ENTRY(bytecode_s) link;
dataval *dataval_new_float(double float_val);
dataval *dataval_new_string(char *str_val);
-dataval *dataval_append(dataval *list, dataval *item);
-
void dataval_print(datavalhead *head);
#endif
-/* $Id: main.c,v 1.11 2001/09/15 07:16:59 peter Exp $
+/* $Id: main.c,v 1.12 2001/09/16 04:49:46 peter Exp $
* Program entry point, command line parsing
*
* Copyright (C) 2001 Peter Johnson
#include "preproc.h"
#include "parser.h"
-RCSID("$Id: main.c,v 1.11 2001/09/15 07:16:59 peter Exp $");
+RCSID("$Id: main.c,v 1.12 2001/09/16 04:49:46 peter Exp $");
char *filename = (char *)NULL;
unsigned int line_number = 1;
filename = strdup("<STDIN>");
}
- nasm_parser.doparse(&raw_preproc, &dbg_objfmt, in);
+ nasm_parser.doparse(&nasm_parser, &dbg_objfmt, in);
if (filename)
free(filename);
--- /dev/null
+/* $Id: parser.c,v 1.1 2001/09/16 04:49:46 peter Exp $
+ * Generic functions for all parsers
+ *
+ * Copyright (C) 2001 Peter Johnson
+ *
+ * This file is part of YASM.
+ *
+ * YASM is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * YASM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "util.h"
+
+#include <stdio.h>
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+#include "globals.h"
+#include "errwarn.h"
+#include "expr.h"
+
+#include "bytecode.h"
+#include "section.h"
+#include "objfmt.h"
+#include "preproc.h"
+#include "parser.h"
+
+RCSID("$Id: parser.c,v 1.1 2001/09/16 04:49:46 peter Exp $");
+
+/* NULL-terminated list of all available parsers.
+ * Someday change this if we dynamically load parsers at runtime.
+ * Could improve this a little by generating automatically at build-time.
+ */
+static parser *parsers[] = {
+ &nasm_parser,
+ NULL
+};
+
+int
+parser_setpp(parser *p, const char *pp_keyword)
+{
+ int i;
+
+ /* We're just doing a linear search, as preprocs should be short */
+ for (i = 0; p->preprocs[i]; i++) {
+ if (strcmp(p->preprocs[i]->keyword, pp_keyword) == 0) {
+ p->current_pp = p->preprocs[i];
+ return 0;
+ }
+ }
+
+ /* no match found */
+ return 1;
+}
+
+void
+parser_listpp(parser *p,
+ void (*printfunc) (const char *name, const char *keyword))
+{
+ int i;
+
+ for (i = 0; p->preprocs[i]; i++) {
+ printfunc(p->preprocs[i]->name, p->preprocs[i]->keyword);
+ }
+}
+
+parser *
+find_parser(const char *keyword)
+{
+ int i;
+
+ /* We're just doing a linear search, as there aren't many parsers */
+ for (i = 0; parsers[i]; i++) {
+ if (strcmp(parsers[i]->keyword, keyword) == 0)
+ return parsers[i];
+ }
+
+ /* no match found */
+ return NULL;
+}
+
+void
+list_parsers(void (*printfunc) (const char *name, const char *keyword))
+{
+ int i;
+
+ for (i = 0; parsers[i]; i++) {
+ printfunc(parsers[i]->name, parsers[i]->keyword);
+ }
+}
-/* $Id: parser.h,v 1.3 2001/09/15 07:16:59 peter Exp $
+/* $Id: parser.h,v 1.4 2001/09/16 04:49:46 peter Exp $
* Parser module interface header file
*
* Copyright (C) 2001 Peter Johnson
*/
preproc **preprocs;
- /* Default preprocessor (set even if there's only one available to use) */
- preproc *default_pp;
+ /* Current preprocessor (set to the default at compile time) */
+ preproc *current_pp;
/* Main entrance point for the parser.
*
* The parser needs access to both the object format module (for format-
- * specific directives and segment names), and the selected preprocessor
- * (which should naturally be in the preprocs list above).
+ * specific directives and segment names), and the preprocessor
+ * (it uses current_pp as set either at compile-time or by parser_setpp).
*
* This function also takes the FILE * to the initial starting file, but
* not the filename (which is in a global variable and is not
*
* This function returns the starting section of a linked list of sections
* (whatever was in the file).
- *
- * Note that calling this has many side effects in the output format
- * module: sections and variables are declared, etc.
*/
- section *(*doparse) (preproc *pp, objfmt *of, FILE *f);
+ sectionhead *(*doparse) (struct parser_s *p, objfmt *of, FILE *f);
} parser;
+/* Generic functions for all parsers - implemented in src/parser.c */
+
+/* Sets current_pp within p by searching the preprocs list for a preproc
+ * matching pp_keyword. Returns nonzero if no match was found.
+ */
+int parser_setpp(parser *p, const char *pp_keyword);
+
+/* Lists preprocessors available for p. Calls printfunc with the name
+ * and keyword of each available preprocessor.
+ */
+void parser_listpp(parser *p,
+ void (*printfunc) (const char *name, const char *keyword));
+
+/* Finds a parser based on its keyword. Returns NULL if no match was found.
+ */
+parser *find_parser(const char *keyword);
+
+/* Lists all available parsers. Calls printfunc with the name and keyword
+ * of each available parser.
+ */
+void list_parsers(void (*printfunc) (const char *name, const char *keyword));
+
/* Available parsers */
extern parser nasm_parser;
-/* $Id: nasm-parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $
+/* $Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
#include "preproc.h"
#include "parser.h"
-RCSID("$Id: nasm-parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $");
+RCSID("$Id: nasm-parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
extern FILE *nasm_parser_in;
extern int nasm_parser_debug;
int (*nasm_parser_yyinput) (char *buf, int max_size);
-static section *
-doparse(preproc *pp, objfmt *of, FILE *f)
+static sectionhead *
+nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
{
- pp->initialize(of, f);
+ p->current_pp->initialize(of, f);
nasm_parser_in = f;
- nasm_parser_yyinput = pp->input;
+ nasm_parser_yyinput = p->current_pp->input;
/* only temporary */
nasm_parser_debug = 1;
}
/* Define valid preprocessors to use with this parser */
-static preproc *preprocs[] = {
+static preproc *nasm_parser_preprocs[] = {
&raw_preproc,
NULL
};
parser nasm_parser = {
"NASM-compatible parser",
"nasm",
- preprocs,
+ nasm_parser_preprocs,
&raw_preproc,
- doparse
+ nasm_parser_doparse
};
-/* $Id: parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $
+/* $Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
#include "preproc.h"
#include "parser.h"
-RCSID("$Id: parser.c,v 1.7 2001/09/15 07:16:59 peter Exp $");
+RCSID("$Id: parser.c,v 1.8 2001/09/16 04:49:46 peter Exp $");
extern FILE *nasm_parser_in;
extern int nasm_parser_debug;
int (*nasm_parser_yyinput) (char *buf, int max_size);
-static section *
-doparse(preproc *pp, objfmt *of, FILE *f)
+static sectionhead *
+nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
{
- pp->initialize(of, f);
+ p->current_pp->initialize(of, f);
nasm_parser_in = f;
- nasm_parser_yyinput = pp->input;
+ nasm_parser_yyinput = p->current_pp->input;
/* only temporary */
nasm_parser_debug = 1;
}
/* Define valid preprocessors to use with this parser */
-static preproc *preprocs[] = {
+static preproc *nasm_parser_preprocs[] = {
&raw_preproc,
NULL
};
parser nasm_parser = {
"NASM-compatible parser",
"nasm",
- preprocs,
+ nasm_parser_preprocs,
&raw_preproc,
- doparse
+ nasm_parser_doparse
};
-/* $Id: section.h,v 1.5 2001/08/19 03:52:58 peter Exp $
+/* $Id: section.h,v 1.6 2001/09/16 04:49:46 peter Exp $
* Section header file
*
* Copyright (C) 2001 Peter Johnson
#ifndef YASM_SECTION_H
#define YASM_SECTION_H
+typedef STAILQ_HEAD(sectionhead_s, section_s) sectionhead;
+
typedef struct section_s {
- struct section_s *next;
+ STAILQ_ENTRY(section_s) link;
enum { SECTION, ABSOLUTE } type;
unsigned long start;
} data;
- bytecode *bc; /* the bytecodes for the section's contents */
+ bytecodehead bc; /* the bytecodes for the section's contents */
} section;
#endif