[llvm] 6caee48 - [Utils][LoongArch](5/6) Add a --bits-endian option to extract-section.py
Renato Golin via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 10 02:24:02 PST 2022
Author: Lu Weining
Date: 2022-02-10T10:23:34Z
New Revision: 6caee4890971fc4dea2a76028967484b620513f6
URL: https://github.com/llvm/llvm-project/commit/6caee4890971fc4dea2a76028967484b620513f6
DIFF: https://github.com/llvm/llvm-project/commit/6caee4890971fc4dea2a76028967484b620513f6.diff
LOG: [Utils][LoongArch](5/6) Add a --bits-endian option to extract-section.py
This is a split patch of D115862 which adds a --bits-endian option to
extract-section to make it possible to print bits in specified endianness.
It means that we can print instruction encoding of some targets like LoongArch
as bits[0] to bits[31] from right to left by specifing --bits-endian little.
Differential revision: https://reviews.llvm.org/D116100
Added:
Modified:
llvm/utils/extract-section.py
Removed:
################################################################################
diff --git a/llvm/utils/extract-section.py b/llvm/utils/extract-section.py
index 0c96b52fc522..c8838b490016 100755
--- a/llvm/utils/extract-section.py
+++ b/llvm/utils/extract-section.py
@@ -59,6 +59,9 @@ def get_raw_section_dump(readobj_path, section_name, input_file):
help='Print out in bits')
arg_parser.add_argument('--byte-indicator', action='store_true',
help='Whether to print a \'.\' every 8 bits in bits printing mode')
+ arg_parser.add_argument('--bits-endian', metavar='<little/big>', type=str,
+ choices=['little', 'big'],
+ help='Print out bits in specified endianness (little or big); defaults to big')
format_group.add_argument('-h', dest='format', action='store_const', const='hex',
help='Print out in hexadecimal')
arg_parser.add_argument('--hex-width', metavar='<# of bytes>', type=int,
@@ -66,7 +69,7 @@ def get_raw_section_dump(readobj_path, section_name, input_file):
arg_parser.add_argument('--help', action='help')
arg_parser.set_defaults(format='bits', tool_path='llvm-readobj', input_file='-',
- byte_indicator=False, hex_width=4)
+ byte_indicator=False, hex_width=4, bits_endian='big')
args = arg_parser.parse_args()
raw_section = get_raw_section_dump(args.tool_path, args.section, args.input_file)
@@ -82,7 +85,10 @@ def get_raw_section_dump(readobj_path, section_name, input_file):
val = int(part, 16)
if args.format == 'bits':
# divided into bytes first
- for byte in [(val >> off) & 0xFF for off in (24,16,8,0)]:
+ offsets = (24, 16, 8, 0)
+ if args.bits_endian == 'little':
+ offsets = (0, 8, 16, 24)
+ for byte in [(val >> off) & 0xFF for off in offsets]:
for bit in [(byte >> off) & 1 for off in range(7, -1, -1)]:
results.append(str(bit))
if args.byte_indicator:
More information about the llvm-commits
mailing list