Files
rocm-systems/bin/att_to_out.py
T

46 lines
1.8 KiB
Python
Raw Normal View History

2023-04-14 17:59:15 -03:00
################################################################################
# Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
################################################################################
import numpy as np
import sys
2023-08-21 15:08:31 +00:00
BYTE_MAP = [str(k) for k in range(10)] + ["a", "b", "c", "d", "e", "f"]
2023-04-14 17:59:15 -03:00
def map8(c):
2023-08-21 15:08:31 +00:00
return BYTE_MAP[(c // 16) % 16] + BYTE_MAP[c % 16]
2023-04-14 17:59:15 -03:00
def map16(c):
2023-08-21 15:08:31 +00:00
return map8(c >> 8) + map8(c)
2023-04-14 17:59:15 -03:00
in_filename = sys.argv[1]
2023-08-21 15:08:31 +00:00
out_filename = in_filename.split(".att")[0] + ".out"
2023-04-14 17:59:15 -03:00
in_bytes = np.fromfile(in_filename, dtype=np.uint16)
2023-10-07 16:34:19 -03:00
offset = 4 if in_bytes[0] >= 0xC000 else 0
out_bytes = [map16(c) + "\n" for c in in_bytes[offset:]]
2023-04-14 17:59:15 -03:00
2023-08-21 15:08:31 +00:00
with open(out_filename, "w") as f:
2023-04-14 17:59:15 -03:00
[f.write(b) for b in out_bytes]