From d86f13dbfa430e712896612ad89ea49f4dcb9456 Mon Sep 17 00:00:00 2001 From: Richard Yan Date: Wed, 8 May 2024 15:03:21 -0700 Subject: [PATCH] support dedicated printf buffer output --- generators/radiance | 2 +- sims/parse_printf.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/generators/radiance b/generators/radiance index f698768b..1215bf42 160000 --- a/generators/radiance +++ b/generators/radiance @@ -1 +1 @@ -Subproject commit f698768b390465a23abd93f919d194ab76132d26 +Subproject commit 1215bf42602f3decb4c14466f4f68dbe187c2816 diff --git a/sims/parse_printf.py b/sims/parse_printf.py index f3673960..a8f10335 100644 --- a/sims/parse_printf.py +++ b/sims/parse_printf.py @@ -1,5 +1,7 @@ import sys +PRINT_BUF = 0x4000 / 4 + def parse_log_file(log_file_path): target_string = '' # Initialize the string we'll build from hex values print_buf = [0] * 65536 @@ -23,7 +25,7 @@ def parse_log_file(log_file_path): # print(rs1_data_last_element) for rs1, rs2, byteen in zip(rs1_data_elts, rs2_data_elts, byteen_elts): if '0x3fc0' in rs1: - offset = (int(rs1, 16) - 8192) % 65536 + offset = (int(rs1, 16) - PRINT_BUF) % 65536 if offset < 0 or offset >= 1024: continue else: @@ -58,13 +60,40 @@ def parse_log_file(log_file_path): return target_string # return print_buf +def parse_out_file(out_file_path): + target_string = "" + + with open(out_file_path, 'r') as file: + for line in file: + if 'TRACEWR' in line: + tokens = line.strip().split() + addr, data, mask = int(tokens[2], 16), int(tokens[3], 16), int(tokens[4], 16) + assert((addr >> 16) == 0xff00) + bytes_object = bytes.fromhex(tokens[3]) + masked_bytes_list = [] + assert(len(bytes_object) <= 4) + for i, byte in enumerate(bytes_object[::-1]): + if mask & (1 << i): + masked_bytes_list.append(byte) + reversed_bytes = bytes(masked_bytes_list) + try: + target_string += reversed_bytes.decode('ascii', errors="ignore") + except UnicodeDecodeError: + print(f"Skipping invalid UTF-8 sequence: {hex_value}") + return target_string + + def main(): if len(sys.argv) != 2: print("Usage: python parse_printf.py ") sys.exit(1) log_file_path = sys.argv[1] - parsed_string = print(parse_log_file(log_file_path)) + if log_file_path[-4:] == "log": + print(parse_log_file(log_file_path)) + else: + print(parse_out_file(log_file_path)) + # parsed_string = bytes(parse_log_file(log_file_path)) # try: # print(parsed_string.decode('utf-8', errors="ignore"))