filename = strdup("<STDIN>");
}
- nasm_parser.doparse(&nasm_parser, &dbg_objfmt, in);
+ nasm_parser.do_parse(&nasm_parser, &dbg_objfmt, in);
if (filename)
free(filename);
printf("Offset=%lx BITS=%u\n", bc->offset, bc->mode_bits);
}
+void
+bytecodes_append(bytecodehead *headp, bytecode *bc)
+{
+ if (bc) {
+ if (bc->type != BC_EMPTY)
+ STAILQ_INSERT_TAIL(headp, bc, link);
+ else
+ free(bc);
+ }
+}
+
dataval *
dataval_new_expr(expr *exp)
{
void bytecode_print(bytecode *bc);
+/* void bytecodes_initialize(bytecodehead *headp); */
+#define bytecodes_initialize(headp) STAILQ_INIT(headp)
+
+/* Adds bc to the list of bytecodes headp.
+ * NOTE: Does not make a copy of bc; so don't pass this function
+ * static or local variables, and discard the bc pointer after calling
+ * this function.
+ */
+void bytecodes_append(bytecodehead *headp, bytecode *bc);
+
dataval *dataval_new_expr(struct expr_s *exp);
dataval *dataval_new_float(double float_val);
dataval *dataval_new_string(char *str_val);
* use)
*/
/* struct debugfmt_s *default_df;*/
+
+ /* Get the default (starting) section name. */
+ const char *(*get_default_section_name) (void);
+
+ /* Is the specified section name valid?
+ * Return is a boolean value.
+ */
+ int (*is_valid_section) (const char *name);
} objfmt;
/* Available object formats */
* This function returns the starting section of a linked list of sections
* (whatever was in the file).
*/
- sectionhead *(*doparse) (struct parser_s *p, objfmt *of, FILE *f);
+ sectionhead *(*do_parse) (struct parser_s *p, objfmt *of, FILE *f);
} parser;
/* Generic functions for all parsers - implemented in src/parser.c */
--- /dev/null
+/* $IdPath$
+ * Section utility functions
+ *
+ * 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 <libintl.h>
+#define _(String) gettext(String)
+#ifdef gettext_noop
+#define N_(String) gettext_noop(String)
+#else
+#define N_(String) (String)
+#endif
+
+#include "globals.h"
+#include "errwarn.h"
+#include "expr.h"
+
+#include "bytecode.h"
+#include "section.h"
+#include "objfmt.h"
+
+RCSID("$IdPath$");
+
+section *
+sections_initialize(sectionhead *headp, objfmt *of)
+{
+ section *s;
+
+ /* Initialize linked list */
+ STAILQ_INIT(headp);
+
+ /* Add an initial "default" section to the list */
+ s = calloc(1, sizeof(section));
+ if (!s)
+ Fatal(FATAL_NOMEM);
+ STAILQ_INSERT_TAIL(headp, s, link);
+
+ /* Initialize default section */
+ s->type = SECTION_GENERAL;
+ s->name = strdup(of->get_default_section_name());
+ bytecodes_initialize(&s->bc);
+
+ return s;
+}
+
+section *
+sections_switch(sectionhead *headp, objfmt *of, const char *name)
+{
+ section *s, *sp;
+
+ /* Search through current sections to see if we already have one with
+ * that name.
+ */
+ s = (section *)NULL;
+ STAILQ_FOREACH(sp, headp, link) {
+ if (strcmp(sp->name, name) == 0)
+ s = sp;
+ }
+
+ if (s)
+ return s;
+
+ /* No: we have to allocate and create a new one. */
+
+ /* But first check with objfmt to see if the name is valid.
+ * If it isn't, error and just return the default (first) section.
+ */
+ if (!of->is_valid_section(name)) {
+ Error(_("Invalid section name: %s"), name);
+ return STAILQ_FIRST(headp);
+ }
+
+ /* Okay, the name is valid; now allocate and initialize */
+ s = calloc(1, sizeof(section));
+ if (!s)
+ Fatal(FATAL_NOMEM);
+ STAILQ_INSERT_TAIL(headp, s, link);
+
+ s->type = SECTION_GENERAL;
+ s->name = strdup(name);
+ bytecodes_initialize(&s->bc);
+
+ return s;
+}
#ifndef YASM_SECTION_H
#define YASM_SECTION_H
+struct objfmt_s;
+
typedef STAILQ_HEAD(sectionhead_s, section_s) sectionhead;
typedef struct section_s {
STAILQ_ENTRY(section_s) link;
- enum { SECTION_DEFAULT, SECTION_GENERAL, SECTION_ABSOLUTE } type;
+ enum { SECTION_GENERAL, SECTION_ABSOLUTE } type;
- char *name;
- unsigned int id;
+ char *name; /* strdup()'ed name (given by user) */
union {
- /* SECTION_DEFAULT data */
/* SECTION_GENERAL data */
/* SECTION_ABSOLUTE data */
unsigned long start;
bytecodehead bc; /* the bytecodes for the section's contents */
} section;
+section *sections_initialize(sectionhead *headp, struct objfmt_s *of);
+
+section *sections_switch(sectionhead *headp, struct objfmt_s *of,
+ const char *name);
+
#endif
#include "util.h"
+#include <stdio.h>
+
#include "objfmt.h"
RCSID("$IdPath$");
+static const char *
+dbg_objfmt_get_default_section_name(void)
+{
+ fprintf(stderr, "-dbg_objfmt_get_default_section_name()\n");
+ return ".text";
+}
+
+static int
+dbg_objfmt_is_valid_section(const char *name)
+{
+ fprintf(stderr, "-dbg_objfmt_is_valid_section(\"%s\")\n", name);
+ return 1;
+}
+
/* Define objfmt structure -- see objfmt.h for details */
objfmt dbg_objfmt = {
"Trace of all info passed to object format module",
- "dbg"
+ "dbg",
+ dbg_objfmt_get_default_section_name,
+ dbg_objfmt_is_valid_section
};
#include "util.h"
+#include <stdio.h>
+
#include "objfmt.h"
RCSID("$IdPath$");
+static const char *
+dbg_objfmt_get_default_section_name(void)
+{
+ fprintf(stderr, "-dbg_objfmt_get_default_section_name()\n");
+ return ".text";
+}
+
+static int
+dbg_objfmt_is_valid_section(const char *name)
+{
+ fprintf(stderr, "-dbg_objfmt_is_valid_section(\"%s\")\n", name);
+ return 1;
+}
+
/* Define objfmt structure -- see objfmt.h for details */
objfmt dbg_objfmt = {
"Trace of all info passed to object format module",
- "dbg"
+ "dbg",
+ dbg_objfmt_get_default_section_name,
+ dbg_objfmt_is_valid_section
};
#ifdef STDC_HEADERS
# include <stdlib.h>
+# include <string.h>
# include <math.h>
#endif
#include "bytecode.h"
#include "section.h"
+#include "objfmt.h"
RCSID("$IdPath$");
static unsigned long ConvertCharConstToInt(char *);
void nasm_parser_error(char *);
+extern objfmt *nasm_parser_objfmt;
+extern sectionhead nasm_parser_sections;
extern section *nasm_parser_cur_section;
%}
| input line {
OutputError();
OutputWarning();
- if ($2) {
- if ($2->type != BC_EMPTY) {
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
- } else {
- free($2);
- }
- }
+ bytecodes_append(&nasm_parser_cur_section->bc, $2);
line_number++;
}
;
/* directives */
directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
- printf("Directive: Name='%s' Value='%s'\n", $2, $3);
+ if (strcasecmp($2, "section") == 0)
+ nasm_parser_cur_section = sections_switch(&nasm_parser_sections,
+ nasm_parser_objfmt, $3);
+ else
+ printf("Directive: Name='%s' Value='%s'\n", $2, $3);
}
| '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
Error(_("missing `%c'"), ']');
#ifdef STDC_HEADERS
# include <stdlib.h>
+# include <string.h>
# include <math.h>
#endif
#include "bytecode.h"
#include "section.h"
+#include "objfmt.h"
RCSID("$IdPath$");
static unsigned long ConvertCharConstToInt(char *);
void nasm_parser_error(char *);
+extern objfmt *nasm_parser_objfmt;
+extern sectionhead nasm_parser_sections;
extern section *nasm_parser_cur_section;
%}
| input line {
OutputError();
OutputWarning();
- if ($2) {
- if ($2->type != BC_EMPTY) {
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
- } else {
- free($2);
- }
- }
+ bytecodes_append(&nasm_parser_cur_section->bc, $2);
line_number++;
}
;
/* directives */
directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
- printf("Directive: Name='%s' Value='%s'\n", $2, $3);
+ if (strcasecmp($2, "section") == 0)
+ nasm_parser_cur_section = sections_switch(&nasm_parser_sections,
+ nasm_parser_objfmt, $3);
+ else
+ printf("Directive: Name='%s' Value='%s'\n", $2, $3);
}
| '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
Error(_("missing `%c'"), ']');
int (*nasm_parser_yyinput) (char *buf, int max_size);
+objfmt *nasm_parser_objfmt;
sectionhead nasm_parser_sections;
section *nasm_parser_cur_section;
static sectionhead *
-nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
+nasm_parser_do_parse(parser *p, objfmt *of, FILE *f)
{
p->current_pp->initialize(of, f);
nasm_parser_in = f;
nasm_parser_yyinput = p->current_pp->input;
- /* Initialize linked list */
- STAILQ_INIT(&nasm_parser_sections);
+ nasm_parser_objfmt = of;
- /* 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);
+ /* Initialize section list */
+ nasm_parser_cur_section = sections_initialize(&nasm_parser_sections, of);
/* only temporary */
nasm_parser_debug = 0;
"nasm",
nasm_parser_preprocs,
&raw_preproc,
- nasm_parser_doparse
+ nasm_parser_do_parse
};
int (*nasm_parser_yyinput) (char *buf, int max_size);
+objfmt *nasm_parser_objfmt;
sectionhead nasm_parser_sections;
section *nasm_parser_cur_section;
static sectionhead *
-nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
+nasm_parser_do_parse(parser *p, objfmt *of, FILE *f)
{
p->current_pp->initialize(of, f);
nasm_parser_in = f;
nasm_parser_yyinput = p->current_pp->input;
- /* Initialize linked list */
- STAILQ_INIT(&nasm_parser_sections);
+ nasm_parser_objfmt = of;
- /* 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);
+ /* Initialize section list */
+ nasm_parser_cur_section = sections_initialize(&nasm_parser_sections, of);
/* only temporary */
nasm_parser_debug = 0;
"nasm",
nasm_parser_preprocs,
&raw_preproc,
- nasm_parser_doparse
+ nasm_parser_do_parse
};
globals.c \
globals.h \
util.h \
+ section.c \
section.h \
objfmt.h \
preproc.h \
printf("Offset=%lx BITS=%u\n", bc->offset, bc->mode_bits);
}
+void
+bytecodes_append(bytecodehead *headp, bytecode *bc)
+{
+ if (bc) {
+ if (bc->type != BC_EMPTY)
+ STAILQ_INSERT_TAIL(headp, bc, link);
+ else
+ free(bc);
+ }
+}
+
dataval *
dataval_new_expr(expr *exp)
{
void bytecode_print(bytecode *bc);
+/* void bytecodes_initialize(bytecodehead *headp); */
+#define bytecodes_initialize(headp) STAILQ_INIT(headp)
+
+/* Adds bc to the list of bytecodes headp.
+ * NOTE: Does not make a copy of bc; so don't pass this function
+ * static or local variables, and discard the bc pointer after calling
+ * this function.
+ */
+void bytecodes_append(bytecodehead *headp, bytecode *bc);
+
dataval *dataval_new_expr(struct expr_s *exp);
dataval *dataval_new_float(double float_val);
dataval *dataval_new_string(char *str_val);
filename = strdup("<STDIN>");
}
- nasm_parser.doparse(&nasm_parser, &dbg_objfmt, in);
+ nasm_parser.do_parse(&nasm_parser, &dbg_objfmt, in);
if (filename)
free(filename);
* use)
*/
/* struct debugfmt_s *default_df;*/
+
+ /* Get the default (starting) section name. */
+ const char *(*get_default_section_name) (void);
+
+ /* Is the specified section name valid?
+ * Return is a boolean value.
+ */
+ int (*is_valid_section) (const char *name);
} objfmt;
/* Available object formats */
#include "util.h"
+#include <stdio.h>
+
#include "objfmt.h"
RCSID("$IdPath$");
+static const char *
+dbg_objfmt_get_default_section_name(void)
+{
+ fprintf(stderr, "-dbg_objfmt_get_default_section_name()\n");
+ return ".text";
+}
+
+static int
+dbg_objfmt_is_valid_section(const char *name)
+{
+ fprintf(stderr, "-dbg_objfmt_is_valid_section(\"%s\")\n", name);
+ return 1;
+}
+
/* Define objfmt structure -- see objfmt.h for details */
objfmt dbg_objfmt = {
"Trace of all info passed to object format module",
- "dbg"
+ "dbg",
+ dbg_objfmt_get_default_section_name,
+ dbg_objfmt_is_valid_section
};
#include "util.h"
+#include <stdio.h>
+
#include "objfmt.h"
RCSID("$IdPath$");
+static const char *
+dbg_objfmt_get_default_section_name(void)
+{
+ fprintf(stderr, "-dbg_objfmt_get_default_section_name()\n");
+ return ".text";
+}
+
+static int
+dbg_objfmt_is_valid_section(const char *name)
+{
+ fprintf(stderr, "-dbg_objfmt_is_valid_section(\"%s\")\n", name);
+ return 1;
+}
+
/* Define objfmt structure -- see objfmt.h for details */
objfmt dbg_objfmt = {
"Trace of all info passed to object format module",
- "dbg"
+ "dbg",
+ dbg_objfmt_get_default_section_name,
+ dbg_objfmt_is_valid_section
};
* This function returns the starting section of a linked list of sections
* (whatever was in the file).
*/
- sectionhead *(*doparse) (struct parser_s *p, objfmt *of, FILE *f);
+ sectionhead *(*do_parse) (struct parser_s *p, objfmt *of, FILE *f);
} parser;
/* Generic functions for all parsers - implemented in src/parser.c */
#ifdef STDC_HEADERS
# include <stdlib.h>
+# include <string.h>
# include <math.h>
#endif
#include "bytecode.h"
#include "section.h"
+#include "objfmt.h"
RCSID("$IdPath$");
static unsigned long ConvertCharConstToInt(char *);
void nasm_parser_error(char *);
+extern objfmt *nasm_parser_objfmt;
+extern sectionhead nasm_parser_sections;
extern section *nasm_parser_cur_section;
%}
| input line {
OutputError();
OutputWarning();
- if ($2) {
- if ($2->type != BC_EMPTY) {
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
- } else {
- free($2);
- }
- }
+ bytecodes_append(&nasm_parser_cur_section->bc, $2);
line_number++;
}
;
/* directives */
directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
- printf("Directive: Name='%s' Value='%s'\n", $2, $3);
+ if (strcasecmp($2, "section") == 0)
+ nasm_parser_cur_section = sections_switch(&nasm_parser_sections,
+ nasm_parser_objfmt, $3);
+ else
+ printf("Directive: Name='%s' Value='%s'\n", $2, $3);
}
| '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
Error(_("missing `%c'"), ']');
#ifdef STDC_HEADERS
# include <stdlib.h>
+# include <string.h>
# include <math.h>
#endif
#include "bytecode.h"
#include "section.h"
+#include "objfmt.h"
RCSID("$IdPath$");
static unsigned long ConvertCharConstToInt(char *);
void nasm_parser_error(char *);
+extern objfmt *nasm_parser_objfmt;
+extern sectionhead nasm_parser_sections;
extern section *nasm_parser_cur_section;
%}
| input line {
OutputError();
OutputWarning();
- if ($2) {
- if ($2->type != BC_EMPTY) {
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
- } else {
- free($2);
- }
- }
+ bytecodes_append(&nasm_parser_cur_section->bc, $2);
line_number++;
}
;
/* directives */
directive: '[' DIRECTIVE_NAME DIRECTIVE_VAL ']' {
- printf("Directive: Name='%s' Value='%s'\n", $2, $3);
+ if (strcasecmp($2, "section") == 0)
+ nasm_parser_cur_section = sections_switch(&nasm_parser_sections,
+ nasm_parser_objfmt, $3);
+ else
+ printf("Directive: Name='%s' Value='%s'\n", $2, $3);
}
| '[' DIRECTIVE_NAME DIRECTIVE_VAL error {
Error(_("missing `%c'"), ']');
int (*nasm_parser_yyinput) (char *buf, int max_size);
+objfmt *nasm_parser_objfmt;
sectionhead nasm_parser_sections;
section *nasm_parser_cur_section;
static sectionhead *
-nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
+nasm_parser_do_parse(parser *p, objfmt *of, FILE *f)
{
p->current_pp->initialize(of, f);
nasm_parser_in = f;
nasm_parser_yyinput = p->current_pp->input;
- /* Initialize linked list */
- STAILQ_INIT(&nasm_parser_sections);
+ nasm_parser_objfmt = of;
- /* 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);
+ /* Initialize section list */
+ nasm_parser_cur_section = sections_initialize(&nasm_parser_sections, of);
/* only temporary */
nasm_parser_debug = 0;
"nasm",
nasm_parser_preprocs,
&raw_preproc,
- nasm_parser_doparse
+ nasm_parser_do_parse
};
int (*nasm_parser_yyinput) (char *buf, int max_size);
+objfmt *nasm_parser_objfmt;
sectionhead nasm_parser_sections;
section *nasm_parser_cur_section;
static sectionhead *
-nasm_parser_doparse(parser *p, objfmt *of, FILE *f)
+nasm_parser_do_parse(parser *p, objfmt *of, FILE *f)
{
p->current_pp->initialize(of, f);
nasm_parser_in = f;
nasm_parser_yyinput = p->current_pp->input;
- /* Initialize linked list */
- STAILQ_INIT(&nasm_parser_sections);
+ nasm_parser_objfmt = of;
- /* 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);
+ /* Initialize section list */
+ nasm_parser_cur_section = sections_initialize(&nasm_parser_sections, of);
/* only temporary */
nasm_parser_debug = 0;
"nasm",
nasm_parser_preprocs,
&raw_preproc,
- nasm_parser_doparse
+ nasm_parser_do_parse
};
--- /dev/null
+/* $IdPath$
+ * Section utility functions
+ *
+ * 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 <libintl.h>
+#define _(String) gettext(String)
+#ifdef gettext_noop
+#define N_(String) gettext_noop(String)
+#else
+#define N_(String) (String)
+#endif
+
+#include "globals.h"
+#include "errwarn.h"
+#include "expr.h"
+
+#include "bytecode.h"
+#include "section.h"
+#include "objfmt.h"
+
+RCSID("$IdPath$");
+
+section *
+sections_initialize(sectionhead *headp, objfmt *of)
+{
+ section *s;
+
+ /* Initialize linked list */
+ STAILQ_INIT(headp);
+
+ /* Add an initial "default" section to the list */
+ s = calloc(1, sizeof(section));
+ if (!s)
+ Fatal(FATAL_NOMEM);
+ STAILQ_INSERT_TAIL(headp, s, link);
+
+ /* Initialize default section */
+ s->type = SECTION_GENERAL;
+ s->name = strdup(of->get_default_section_name());
+ bytecodes_initialize(&s->bc);
+
+ return s;
+}
+
+section *
+sections_switch(sectionhead *headp, objfmt *of, const char *name)
+{
+ section *s, *sp;
+
+ /* Search through current sections to see if we already have one with
+ * that name.
+ */
+ s = (section *)NULL;
+ STAILQ_FOREACH(sp, headp, link) {
+ if (strcmp(sp->name, name) == 0)
+ s = sp;
+ }
+
+ if (s)
+ return s;
+
+ /* No: we have to allocate and create a new one. */
+
+ /* But first check with objfmt to see if the name is valid.
+ * If it isn't, error and just return the default (first) section.
+ */
+ if (!of->is_valid_section(name)) {
+ Error(_("Invalid section name: %s"), name);
+ return STAILQ_FIRST(headp);
+ }
+
+ /* Okay, the name is valid; now allocate and initialize */
+ s = calloc(1, sizeof(section));
+ if (!s)
+ Fatal(FATAL_NOMEM);
+ STAILQ_INSERT_TAIL(headp, s, link);
+
+ s->type = SECTION_GENERAL;
+ s->name = strdup(name);
+ bytecodes_initialize(&s->bc);
+
+ return s;
+}
#ifndef YASM_SECTION_H
#define YASM_SECTION_H
+struct objfmt_s;
+
typedef STAILQ_HEAD(sectionhead_s, section_s) sectionhead;
typedef struct section_s {
STAILQ_ENTRY(section_s) link;
- enum { SECTION_DEFAULT, SECTION_GENERAL, SECTION_ABSOLUTE } type;
+ enum { SECTION_GENERAL, SECTION_ABSOLUTE } type;
- char *name;
- unsigned int id;
+ char *name; /* strdup()'ed name (given by user) */
union {
- /* SECTION_DEFAULT data */
/* SECTION_GENERAL data */
/* SECTION_ABSOLUTE data */
unsigned long start;
bytecodehead bc; /* the bytecodes for the section's contents */
} section;
+section *sections_initialize(sectionhead *headp, struct objfmt_s *of);
+
+section *sections_switch(sectionhead *headp, struct objfmt_s *of,
+ const char *name);
+
#endif