diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 3dba92fc..8fe3534e 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -227,43 +227,7 @@ symrec_declare(const char *name, SymVisibility vis, void *of_data) } return rec; } -#if 0 -int -symrec_get_int_value(const symrec *sym, unsigned long *ret_val, - int resolve_label) -{ - /* If we already know the value, just return it. */ - if (sym->status & SYM_VALUED) { - switch (sym->type) { - case SYM_CONSTANT_INT: - *ret_val = sym->value.int_val; - break; - case SYM_CONSTANT_FLOAT: - /* FIXME: Line number on this error will be incorrect. */ - if (floatnum_get_int(ret_val, sym->value.flt)) - Error(_("Floating point value cannot fit in 32-bit single precision")); - break; - case SYM_LABEL: - if (!bytecode_get_offset(sym->value.label.sect, - sym->value.label.bc, ret_val)) - InternalError(__LINE__, __FILE__, - _("Label symbol is valued but cannot get offset")); - case SYM_UNKNOWN: - InternalError(__LINE__, __FILE__, - _("Have a valued symbol but of unknown type")); - } - return 1; - } - - /* Try to get offset of unvalued label */ - if (resolve_label && sym->type == SYM_LABEL) - return bytecode_get_offset(sym->value.label.sect, sym->value.label.bc, - ret_val); - /* We can't get the value right now. */ - return 0; -} -#endif const char * symrec_get_name(const symrec *sym) { @@ -284,6 +248,17 @@ symrec_get_equ(const symrec *sym) return (const expr *)NULL; } +int +symrec_get_label(const symrec *sym, symrec_get_label_sectionp *sect, + symrec_get_label_bytecodep *precbc) +{ + if (sym->type != SYM_LABEL) + return 0; + *sect = sym->value.label.sect; + *precbc = sym->value.label.bc; + return 1; +} + unsigned long symrec_get_opt_flags(const symrec *sym) { diff --git a/libyasm/symrec.h b/libyasm/symrec.h index c7d7da1d..432dae92 100644 --- a/libyasm/symrec.h +++ b/libyasm/symrec.h @@ -34,18 +34,16 @@ /*@dependent@*/ symrec *symrec_declare(const char *name, SymVisibility vis, /*@only@*/ /*@null@*/ void *of_data); -/* Get the numeric 32-bit value of a symbol if possible. - * Return value is IF POSSIBLE, not the value. - * If resolve_label is true, tries to get offset of labels, otherwise it - * returns not possible. - */ -int symrec_get_int_value(const symrec *sym, unsigned long *ret_val, - int resolve_label); - /*@observer@*/ const char *symrec_get_name(const symrec *sym); SymVisibility symrec_get_visibility(const symrec *sym); /*@observer@*/ /*@null@*/ const expr *symrec_get_equ(const symrec *sym); +/* Returns 0 if not a label or if EXTERN/COMMON (not defined in the file) */ +typedef /*@dependent@*/ section *symrec_get_label_sectionp; +typedef /*@dependent@*/ /*@null@*/ bytecode *symrec_get_label_bytecodep; +int symrec_get_label(const symrec *sym, + /*@out@*/ symrec_get_label_sectionp *sect, + /*@out@*/ symrec_get_label_bytecodep *precbc); /* Get and set optimizer flags */ unsigned long symrec_get_opt_flags(const symrec *sym); diff --git a/src/symrec.c b/src/symrec.c index 3dba92fc..8fe3534e 100644 --- a/src/symrec.c +++ b/src/symrec.c @@ -227,43 +227,7 @@ symrec_declare(const char *name, SymVisibility vis, void *of_data) } return rec; } -#if 0 -int -symrec_get_int_value(const symrec *sym, unsigned long *ret_val, - int resolve_label) -{ - /* If we already know the value, just return it. */ - if (sym->status & SYM_VALUED) { - switch (sym->type) { - case SYM_CONSTANT_INT: - *ret_val = sym->value.int_val; - break; - case SYM_CONSTANT_FLOAT: - /* FIXME: Line number on this error will be incorrect. */ - if (floatnum_get_int(ret_val, sym->value.flt)) - Error(_("Floating point value cannot fit in 32-bit single precision")); - break; - case SYM_LABEL: - if (!bytecode_get_offset(sym->value.label.sect, - sym->value.label.bc, ret_val)) - InternalError(__LINE__, __FILE__, - _("Label symbol is valued but cannot get offset")); - case SYM_UNKNOWN: - InternalError(__LINE__, __FILE__, - _("Have a valued symbol but of unknown type")); - } - return 1; - } - - /* Try to get offset of unvalued label */ - if (resolve_label && sym->type == SYM_LABEL) - return bytecode_get_offset(sym->value.label.sect, sym->value.label.bc, - ret_val); - /* We can't get the value right now. */ - return 0; -} -#endif const char * symrec_get_name(const symrec *sym) { @@ -284,6 +248,17 @@ symrec_get_equ(const symrec *sym) return (const expr *)NULL; } +int +symrec_get_label(const symrec *sym, symrec_get_label_sectionp *sect, + symrec_get_label_bytecodep *precbc) +{ + if (sym->type != SYM_LABEL) + return 0; + *sect = sym->value.label.sect; + *precbc = sym->value.label.bc; + return 1; +} + unsigned long symrec_get_opt_flags(const symrec *sym) { diff --git a/src/symrec.h b/src/symrec.h index c7d7da1d..432dae92 100644 --- a/src/symrec.h +++ b/src/symrec.h @@ -34,18 +34,16 @@ /*@dependent@*/ symrec *symrec_declare(const char *name, SymVisibility vis, /*@only@*/ /*@null@*/ void *of_data); -/* Get the numeric 32-bit value of a symbol if possible. - * Return value is IF POSSIBLE, not the value. - * If resolve_label is true, tries to get offset of labels, otherwise it - * returns not possible. - */ -int symrec_get_int_value(const symrec *sym, unsigned long *ret_val, - int resolve_label); - /*@observer@*/ const char *symrec_get_name(const symrec *sym); SymVisibility symrec_get_visibility(const symrec *sym); /*@observer@*/ /*@null@*/ const expr *symrec_get_equ(const symrec *sym); +/* Returns 0 if not a label or if EXTERN/COMMON (not defined in the file) */ +typedef /*@dependent@*/ section *symrec_get_label_sectionp; +typedef /*@dependent@*/ /*@null@*/ bytecode *symrec_get_label_bytecodep; +int symrec_get_label(const symrec *sym, + /*@out@*/ symrec_get_label_sectionp *sect, + /*@out@*/ symrec_get_label_bytecodep *precbc); /* Get and set optimizer flags */ unsigned long symrec_get_opt_flags(const symrec *sym);