]> granicus.if.org Git - yasm/commitdiff
Change how bytecode and section lists are allocated. When YASM_INTERNAL is not
authorPeter Johnson <peter@tortall.net>
Sun, 4 May 2003 22:15:09 +0000 (22:15 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 4 May 2003 22:15:09 +0000 (22:15 -0000)
defined, the structures for the list heads are not defined, so the existing
yasm_bcs_initialize() and yasm_sections_initialize() were impossible to use.
Instead, rename these functions to yasm_bcs_new() and yasm_sections_new() and
make them allocate the space internally.  Update yasm_bcs_delete() and
yasm_sections_delete() to free the internally-allocated space.

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

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

index 23048bde82cc98ac929103df675114d3b676f2d1..8806030d8b6e470753d31ce9b0ba1c6e3517c3f4 100644 (file)
@@ -26,7 +26,7 @@
  */
 #define YASM_LIB_INTERNAL
 #include "util.h"
-/*@unused@*/ RCSID("$IdPath$");
+/*@unused@*/ RCSID("$IdPath: yasm/libyasm/bytecode.c,v 1.93 2003/03/31 05:36:29 peter Exp $");
 
 #include "file.h"
 
@@ -865,6 +865,7 @@ yasm_bcs_delete(yasm_bytecodehead *headp)
        cur = next;
     }
     STAILQ_INIT(headp);
+    yasm_xfree(headp);
 }
 
 yasm_bytecode *
@@ -985,12 +986,13 @@ yasm_dvs_print(FILE *f, int indent_level, const yasm_datavalhead *head)
     }
 }
 
-/* Non-macro yasm_bcs_initialize() for non-YASM_INTERNAL users. */
-#undef yasm_bcs_initialize
-void
-yasm_bcs_initialize(yasm_bytecodehead *headp)
+yasm_bytecodehead *
+yasm_bcs_new(void)
 {
+    yasm_bytecodehead *headp;
+    headp = yasm_xmalloc(sizeof(yasm_bytecodehead));
     STAILQ_INIT(headp);
+    return headp;
 }
 
 /* Non-macro yasm_bcs_first() for non-YASM_INTERNAL users. */
index f6bd42beea925d09534f3a53a8e42697522642b1..396df834dcf8a907d68d3b84b9a15c9c11c29a8c 100644 (file)
@@ -2,7 +2,7 @@
  * \file bytecode.h
  * \brief YASM bytecode interface.
  *
- * $IdPath: yasm/libyasm/bytecode.h,v 1.71 2003/03/31 08:22:05 peter Exp $
+ * $IdPath: yasm/libyasm/bytecode.h,v 1.72 2003/05/04 08:40:35 peter Exp $
  *
  *  Copyright (C) 2001  Peter Johnson
  *
@@ -265,13 +265,10 @@ yasm_bc_resolve_flags yasm_bc_resolve(yasm_bytecode *bc, int save,
      /*@null@*/ yasm_output_bc_objfmt_data_func output_bc_objfmt_data)
     /*@sets *buf@*/;
 
-/** Initialize list of bytecodes.
- * \param headp                bytecode list
+/** Create list of bytecodes.
+ * \return Newly allocated bytecode list.
  */
-void yasm_bcs_initialize(yasm_bytecodehead *headp);
-#ifdef YASM_INTERNAL
-#define        yasm_bcs_initialize(headp)      STAILQ_INIT(headp)
-#endif
+/*@only@*/ yasm_bytecodehead *yasm_bcs_new(void);
 
 /** Get the first bytecode in a list of bytecodes.
  * \param headp                bytecode list
@@ -291,7 +288,7 @@ void yasm_bcs_initialize(yasm_bytecodehead *headp);
 /** Delete (free allocated memory for) a list of bytecodes.
  * \param headp                bytecode list
  */
-void yasm_bcs_delete(yasm_bytecodehead *headp);
+void yasm_bcs_delete(/*@only@*/ yasm_bytecodehead *headp);
 
 /** Add bytecode to the end of a list of bytecodes.
  * \note Does not make a copy of bc; so don't pass this function static or
index 2b18d63a0393b9c863bd67d69b11802ce96e5ea9..04400ab32dbc30e631b583b8e45cc656f924b66e 100644 (file)
@@ -1,4 +1,4 @@
-/* $IdPath$
+/* $IdPath: yasm/libyasm/parser.h,v 1.21 2003/03/13 06:54:19 peter Exp $
  * Parser module interface header file
  *
  *  Copyright (C) 2001  Peter Johnson
@@ -58,7 +58,7 @@ struct yasm_parser {
      * This function returns the starting section of a linked list of sections
      * (whatever was in the file).
      */
-    yasm_sectionhead *(*do_parse)
+    /*@only@*/ yasm_sectionhead *(*do_parse)
        (yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of, yasm_linemgr *lm,
         FILE *f, const char *in_filename, int save_input);
 };
index 583b8826430fdd9f5a143eea07baf5be4b6d2866..0e4e4cce06596f3339a565f6a367c08af398854d 100644 (file)
@@ -26,7 +26,7 @@
  */
 #define YASM_LIB_INTERNAL
 #include "util.h"
-/*@unused@*/ RCSID("$IdPath: yasm/libyasm/section.c,v 1.35 2003/03/15 05:07:48 peter Exp $");
+/*@unused@*/ RCSID("$IdPath: yasm/libyasm/section.c,v 1.36 2003/05/04 20:31:57 peter Exp $");
 
 #include "errwarn.h"
 #include "intnum.h"
@@ -59,30 +59,34 @@ struct yasm_section {
 
     int res_only;              /* allow only resb family of bytecodes? */
 
-    yasm_bytecodehead bc;      /* the bytecodes for the section's contents */
+    /* the bytecodes for the section's contents */
+    /*@only@*/ yasm_bytecodehead *bc;
 };
 
+/*@reldef@*/ STAILQ_HEAD(yasm_sectionhead, yasm_section);
+
 static void yasm_section_delete(/*@only@*/ yasm_section *sect);
 
 /*@-compdestroy@*/
-yasm_section *
-yasm_sections_initialize(yasm_sectionhead *headp, yasm_objfmt *of)
+yasm_sectionhead *
+yasm_sections_new(yasm_section **def, yasm_objfmt *of)
 {
-    yasm_section *s;
+    yasm_sectionhead *headp;
     yasm_valparamhead vps;
     yasm_valparam *vp;
 
     /* Initialize linked list */
+    headp = yasm_xmalloc(sizeof(yasm_sectionhead));
     STAILQ_INIT(headp);
 
     /* Add an initial "default" section */
     vp = yasm_vp_new(yasm__xstrdup(of->default_section_name), NULL);
     yasm_vps_initialize(&vps);
     yasm_vps_append(&vps, vp);
-    s = of->sections_switch(headp, &vps, NULL, 0);
+    *def = of->sections_switch(headp, &vps, NULL, 0);
     yasm_vps_delete(&vps);
 
-    return s;
+    return headp;
 }
 /*@=compdestroy@*/
 
@@ -117,7 +121,7 @@ yasm_sections_switch_general(yasm_sectionhead *headp, const char *name,
     s->data.general.of_data = NULL;
     s->start = yasm_expr_new_ident(yasm_expr_int(yasm_intnum_new_uint(start)),
                                   lindex);
-    yasm_bcs_initialize(&s->bc);
+    s->bc = yasm_bcs_new();
 
     s->opt_flags = 0;
     s->res_only = res_only;
@@ -138,7 +142,7 @@ yasm_sections_switch_absolute(yasm_sectionhead *headp, yasm_expr *start)
 
     s->type = SECTION_ABSOLUTE;
     s->start = start;
-    yasm_bcs_initialize(&s->bc);
+    s->bc = yasm_bcs_new();
 
     s->opt_flags = 0;
     s->res_only = 1;
@@ -214,6 +218,7 @@ yasm_sections_delete(yasm_sectionhead *headp)
        cur = next;
     }
     STAILQ_INIT(headp);
+    yasm_xfree(headp);
 }
 
 void
@@ -259,7 +264,7 @@ yasm_sections_find_general(yasm_sectionhead *headp, const char *name)
 yasm_bytecodehead *
 yasm_section_get_bytecodes(yasm_section *sect)
 {
-    return &sect->bc;
+    return sect->bc;
 }
 
 const char *
@@ -304,7 +309,7 @@ yasm_section_delete(yasm_section *sect)
        }
     }
     yasm_expr_delete(sect->start);
-    yasm_bcs_delete(&sect->bc);
+    yasm_bcs_delete(sect->bc);
     yasm_xfree(sect);
 }
 
@@ -345,6 +350,6 @@ yasm_section_print(FILE *f, int indent_level, const yasm_section *sect,
 
     if (print_bcs) {
        fprintf(f, "%*sBytecodes:\n", indent_level, "");
-       yasm_bcs_print(f, indent_level+1, &sect->bc);
+       yasm_bcs_print(f, indent_level+1, sect->bc);
     }
 }
index aa27229f6af3af8293315760e5c1ed498a71ee90..a029a639abcec33efd54b2e489bdfc71a8080eba 100644 (file)
@@ -2,7 +2,7 @@
  * \file section.h
  * \brief YASM section interface.
  *
- * $IdPath: yasm/libyasm/section.h,v 1.37 2003/05/04 20:28:28 peter Exp $
+ * $IdPath: yasm/libyasm/section.h,v 1.38 2003/05/04 20:31:57 peter Exp $
  *
  *  Copyright (C) 2001  Peter Johnson
  *
 #ifndef YASM_SECTION_H
 #define YASM_SECTION_H
 
-#ifdef YASM_INTERNAL
-/*@reldef@*/ STAILQ_HEAD(yasm_sectionhead, yasm_section);
-#endif
-
 /** Create a new section list.  A default section is created as the
  * first section.
- * \param headp            pre-allocated section list head
+ * \param def      returned; default section
  * \param of       object format in use
- * \return Default section.
+ * \return Newly allocated section list.
  */
-/*@dependent@*/ yasm_section *yasm_sections_initialize(yasm_sectionhead *headp,
-                                                      yasm_objfmt *of);
+/*@only@*/ yasm_sectionhead *yasm_sections_new
+    (/*@out@*/ /*@dependent@*/ yasm_section **def, yasm_objfmt *of);
 
 /** Create a new, or continue an existing, general section.  The section is
  * added to a section list if there's not already a section by that name.
@@ -105,7 +101,7 @@ void yasm_section_set_of_data(yasm_section *sect, yasm_objfmt *of,
  * section list and all bytecodes within those sections are also deleted.
  * \param headp            section list
  */
-void yasm_sections_delete(yasm_sectionhead *headp);
+void yasm_sections_delete(/*@only@*/ yasm_sectionhead *headp);
 
 /** Print a section list.  For debugging purposes.
  * \param f            file
index 475d67e5597195e9e132c3611648cee03fd2645a..1ac2a7aff2032e3dd8deaa47eb06ed614cf120e2 100644 (file)
@@ -28,7 +28,7 @@
 #define YASM_LIB_INTERNAL
 #define YASM_EXPR_INTERNAL
 #include <libyasm.h>
-RCSID("$IdPath$");
+RCSID("$IdPath: yasm/modules/parsers/nasm/nasm-bison.y,v 1.92 2003/03/31 05:36:30 peter Exp $");
 
 #ifdef STDC_HEADERS
 # include <math.h>
@@ -584,7 +584,7 @@ nasm_parser_directive(const char *name, yasm_valparamhead *valparams,
     } else if (yasm__strcasecmp(name, "section") == 0 ||
               yasm__strcasecmp(name, "segment") == 0) {
        yasm_section *new_section =
-           nasm_parser_objfmt->sections_switch(&nasm_parser_sections,
+           nasm_parser_objfmt->sections_switch(nasm_parser_sections,
                                                valparams, objext_valparams,
                                                lindex);
        if (new_section) {
@@ -598,12 +598,12 @@ nasm_parser_directive(const char *name, yasm_valparamhead *valparams,
        vp = yasm_vps_first(valparams);
        if (vp->val)
            nasm_parser_cur_section =
-               yasm_sections_switch_absolute(&nasm_parser_sections,
+               yasm_sections_switch_absolute(nasm_parser_sections,
                    p_expr_new_ident(yasm_expr_sym(
                        yasm_symrec_use(vp->val, lindex))));
        else if (vp->param) {
            nasm_parser_cur_section =
-               yasm_sections_switch_absolute(&nasm_parser_sections,
+               yasm_sections_switch_absolute(nasm_parser_sections,
                                              vp->param);
            vp->param = NULL;
        }
@@ -626,11 +626,11 @@ nasm_parser_directive(const char *name, yasm_valparamhead *valparams,
        }
     } else if (!nasm_parser_arch->parse_directive(name, valparams,
                                                  objext_valparams,
-                                                 &nasm_parser_sections,
+                                                 nasm_parser_sections,
                                                  lindex)) {
        ;
     } else if (nasm_parser_objfmt->directive(name, valparams, objext_valparams,
-                                            &nasm_parser_sections, lindex)) {
+                                            nasm_parser_sections, lindex)) {
        yasm__error(lindex, N_("unrecognized directive [%s]"), name);
     }
 
index d8cbf2c4c8b9061bf2e509c67b1d86def1c1a089..1b5035e395a726abd36d0f6426d73f8028e5cbc4 100644 (file)
@@ -26,7 +26,7 @@
  */
 #define YASM_LIB_INTERNAL
 #include <libyasm.h>
-/*@unused@*/ RCSID("$IdPath$");
+/*@unused@*/ RCSID("$IdPath: yasm/modules/parsers/nasm/nasm-parser.c,v 1.33 2003/04/01 07:26:33 peter Exp $");
 
 #include "nasm-parser.h"
 
@@ -34,7 +34,7 @@
 FILE *nasm_parser_in = NULL;
 size_t (*nasm_parser_input) (char *buf, size_t max_size);
 
-yasm_sectionhead nasm_parser_sections;
+/*@only@*/ yasm_sectionhead *nasm_parser_sections;
 /*@dependent@*/ yasm_section *nasm_parser_cur_section;
 
 /* last "base" label for local (.) labels */
@@ -47,7 +47,7 @@ size_t nasm_parser_locallabel_base_len = 0;
 
 int nasm_parser_save_input;
 
-static /*@dependent@*/ yasm_sectionhead *
+static /*@only@*/ yasm_sectionhead *
 nasm_parser_do_parse(yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of,
                     yasm_linemgr *lm, FILE *f, const char *in_filename,
                     int save_input)
@@ -62,8 +62,7 @@ nasm_parser_do_parse(yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of,
     nasm_parser_save_input = save_input;
 
     /* Initialize section list */
-    nasm_parser_cur_section =
-       yasm_sections_initialize(&nasm_parser_sections, of);
+    nasm_parser_sections = yasm_sections_new(&nasm_parser_cur_section, of);
 
     /* yacc debugging, needs YYDEBUG set in bison.y.in to work */
     /* nasm_parser_debug = 1; */
@@ -76,7 +75,7 @@ nasm_parser_do_parse(yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of,
     if (nasm_parser_locallabel_base)
        yasm_xfree(nasm_parser_locallabel_base);
 
-    return &nasm_parser_sections;
+    return nasm_parser_sections;
 }
 
 /* Define valid preprocessors to use with this parser */
index 68ddcdbcbbe6c6de9df9e266e20056f1c0db7c96..592ead03e7e505c66289d26e4e448008e47b368d 100644 (file)
@@ -1,4 +1,4 @@
-/* $IdPath$
+/* $IdPath: yasm/modules/parsers/nasm/nasm-parser.h,v 1.6 2003/03/13 06:54:19 peter Exp $
  * NASM-compatible parser header file
  *
  *  Copyright (C) 2002  Peter Johnson
@@ -36,7 +36,7 @@ extern FILE *nasm_parser_in;
 extern int nasm_parser_debug;
 extern size_t (*nasm_parser_input) (char *buf, size_t max_size);
 
-extern yasm_sectionhead nasm_parser_sections;
+extern yasm_sectionhead *nasm_parser_sections;
 extern /*@dependent@*/ yasm_section *nasm_parser_cur_section;
 
 extern char *nasm_parser_locallabel_base;