]> granicus.if.org Git - yasm/commitdiff
* bc-int.h (yasm_bytecode): Add new pointer to array symrecs. This is a
authorPeter Johnson <peter@tortall.net>
Mon, 13 Sep 2004 02:44:00 +0000 (02:44 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 13 Sep 2004 02:44:00 +0000 (02:44 -0000)
NULL-terminated array of labels that point to this bytecode (as the bytecode
previous to the label).  NULL if no labels point to this bytecode.

* bytecode.c (yasm_bc_create_common): Initialize symrecs variable to NULL.
* bytecode.c (yasm_bc_destroy): Delete symrecs variable.

* bytecode.h (yasm_bc__add_symrec): Declare new function.
* bytecode.c (yasm_bc__add_symrec): New.

* symrec.c (yasm_symtab_define_label): Call yasm_bc__add_symrec().

This new functionality is needed to make writing certain dbgfmt routines
easier.

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

libyasm/bc-int.h
libyasm/bytecode.c
libyasm/bytecode.h
libyasm/symrec.c

index 993be49354d7342d8682f6938a7b3cc3dd4668fa..8ea33b1097f8dd1af7c8dd2fa436e51cf205b9f8 100644 (file)
@@ -82,6 +82,10 @@ struct yasm_bytecode {
 
     /* storage for optimizer flags */
     unsigned long opt_flags;
+
+    /* NULL-terminated array of labels that point to this bytecode (as the
+     * bytecode previous to the label).  NULL if no labels point here. */
+    /*@null@*/ yasm_symrec **symrecs;
 };
 
 /** Create a bytecode of any specified type.
index b61e4234deaa37c099a7da5746a5a7d1028989cc..d7880cefd33377c61061728fa87c386b5d67e9bf 100644 (file)
@@ -261,6 +261,8 @@ yasm_bc_create_common(const yasm_bytecode_callback *callback, size_t size,
 
     bc->opt_flags = 0;
 
+    bc->symrecs = NULL;
+
     return bc;
 }
 
@@ -677,6 +679,27 @@ yasm_bc_get_section(yasm_bytecode *bc)
     return bc->section;
 }
 
+void
+yasm_bc__add_symrec(yasm_bytecode *bc, yasm_symrec *sym)
+{
+    if (!bc->symrecs) {
+       bc->symrecs = yasm_xmalloc(2*sizeof(yasm_symrec *));
+       bc->symrecs[0] = sym;
+       bc->symrecs[1] = NULL;
+    } else {
+       /* Very inefficient implementation for large numbers of symbols.  But
+        * that would be very unusual, so use the simple algorithm instead.
+        */
+       size_t count = 1;
+       while (bc->symrecs[count])
+           count++;
+       bc->symrecs = yasm_xrealloc(bc->symrecs,
+                                   (count+2)*sizeof(yasm_symrec *));
+       bc->symrecs[count] = sym;
+       bc->symrecs[count+1] = NULL;
+    }
+}
+
 void
 yasm_bc_destroy(yasm_bytecode *bc)
 {
@@ -686,6 +709,7 @@ yasm_bc_destroy(yasm_bytecode *bc)
     if (bc->callback)
        bc->callback->destroy(bc);
     yasm_expr_destroy(bc->multiple);
+    yasm_xfree(bc->symrecs);
     yasm_xfree(bc);
 }
 
index 2718968acd3fab2b5c8746f3a31de9ae660acbeb..720c19a1a0c935853a4e1c643ad14180eb543282 100644 (file)
@@ -159,6 +159,15 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e);
  */
 /*@dependent@*/ /*@null@*/ yasm_section *yasm_bc_get_section
     (yasm_bytecode *bc);
+
+#ifdef YASM_LIB_INTERNAL
+/** Add to the list of symrecs that reference a bytecode.  For symrec use
+ * only.
+ * \param bc   bytecode
+ * \param sym  symbol
+ */
+void yasm_bc__add_symrec(yasm_bytecode *bc, /*@dependent@*/ yasm_symrec *sym);
+#endif
     
 /** Delete (free allocated memory for) a bytecode.
  * \param bc   bytecode (only pointer to it); may be NULL
index 2d06651d5bec19d6fb39cf74777e14d1fb093559..880a7873d8179754c3b776964c30a9f5f9fea46d 100644 (file)
@@ -220,6 +220,8 @@ yasm_symtab_define_label(yasm_symtab *symtab, const char *name,
     yasm_symrec *rec;
     rec = symtab_define(symtab, name, SYM_LABEL, in_table, line);
     rec->value.precbc = precbc;
+    if (precbc)
+       yasm_bc__add_symrec(precbc, rec);
     return rec;
 }