From ad2c7b3e3fc570be20a8c29dd2f464e587324e36 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 13 Sep 2004 02:44:00 +0000 Subject: [PATCH] * bc-int.h (yasm_bytecode): Add new pointer to array symrecs. This is a 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 | 4 ++++ libyasm/bytecode.c | 24 ++++++++++++++++++++++++ libyasm/bytecode.h | 9 +++++++++ libyasm/symrec.c | 2 ++ 4 files changed, 39 insertions(+) diff --git a/libyasm/bc-int.h b/libyasm/bc-int.h index 993be493..8ea33b10 100644 --- a/libyasm/bc-int.h +++ b/libyasm/bc-int.h @@ -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. diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index b61e4234..d7880cef 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -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); } diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 2718968a..720c19a1 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -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 diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 2d06651d..880a7873 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -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; } -- 2.40.0