From 3f107464e35cf63a529358a1c240821b30c35d2b Mon Sep 17 00:00:00 2001 From: Indu Bhagat Date: Fri, 9 Dec 2022 10:23:07 -0800 Subject: sframe: gas: libsframe: define constants and remove magic numbers Define constants in sframe.h for the various limits associated with the range of offsets that can be encoded in the start address of an SFrame FRE. E.g., sframe_frame_row_entry_addr1 is used when start address offset can be encoded as 1-byte unsigned value. Update the code in gas to use these defined constants as it checks for these limits, and remove the usage of magic numbers. ChangeLog: * gas/sframe-opt.c (sframe_estimate_size_before_relax): (sframe_convert_frag): Do not use magic numbers. * libsframe/sframe.c (sframe_calc_fre_type): Likewise. include/ChangeLog: * sframe.h (SFRAME_FRE_TYPE_ADDR1_LIMIT): New constant. (SFRAME_FRE_TYPE_ADDR2_LIMIT): Likewise. (SFRAME_FRE_TYPE_ADDR4_LIMIT): Likewise. --- gas/sframe-opt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gas') diff --git a/gas/sframe-opt.c b/gas/sframe-opt.c index c17fd6b..6901aa8 100644 --- a/gas/sframe-opt.c +++ b/gas/sframe-opt.c @@ -53,9 +53,9 @@ sframe_estimate_size_before_relax (fragS *frag) widthS = exp->X_op_symbol; width = resolve_symbol_value (widthS); - if (width < 0x100) + if (width < SFRAME_FRE_TYPE_ADDR1_LIMIT) ret = 1; - else if (width < 0x10000) + else if (width < SFRAME_FRE_TYPE_ADDR2_LIMIT) ret = 2; else ret = 4; @@ -109,9 +109,9 @@ sframe_convert_frag (fragS *frag) { fsizeS = frag->fr_symbol; fsize = resolve_symbol_value (fsizeS); - if (fsize < 0x100) + if (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT) func_info = SFRAME_FRE_TYPE_ADDR1; - else if (fsize < 0x10000) + else if (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT) func_info = SFRAME_FRE_TYPE_ADDR2; else func_info = SFRAME_FRE_TYPE_ADDR4; @@ -133,11 +133,11 @@ sframe_convert_frag (fragS *frag) switch (frag->fr_subtype & 7) { case 1: - gas_assert (fsize < 0x100); + gas_assert (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT); frag->fr_literal[frag->fr_fix] = diff; break; case 2: - gas_assert (fsize < 0x10000); + gas_assert (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT); md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2); break; case 4: -- cgit v1.1