From cac68ac8c2f0c82c15308b43ec8df362286242ca Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Mon, 5 Jun 2023 15:19:58 +0200 Subject: [PATCH] adds helperscript for easier debugging --- .gitignore | 4 +++- makeJitOutputReadable.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 makeJitOutputReadable.py diff --git a/.gitignore b/.gitignore index 3f95c55..00bf7e8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ /analysis_results .vscode *.log -tcc_jit*.c \ No newline at end of file +*tcc_jit*.c +*.disass +*.trc \ No newline at end of file diff --git a/makeJitOutputReadable.py b/makeJitOutputReadable.py new file mode 100644 index 0000000..674b736 --- /dev/null +++ b/makeJitOutputReadable.py @@ -0,0 +1,26 @@ +import re +import os +''' +This script takes all files that get dumped by the tcc backend when using the --dump-ir +option and replaces the Integers of addresses with their hex representation to allow +for easier debugging. +''' +current_dir = os.getcwd() # Get the current directory + +files_with_tcc_jit = [file for file in os.listdir(current_dir) if"jit" in file and not file.startswith("readable")] + +for each in files_with_tcc_jit: + readable_file = f"readable_{each}" + if os.path.exists(readable_file): + os.remove(readable_file) + with open(each, "r") as file: + content = file.read() +for each in files_with_tcc_jit: + with open(each, "r") as file: + content = file.read() + + # Replace numbers ending with "U" by their hex representation + content = re.sub(r'\b(\d+)U\b(?=U)?', lambda m: hex(int(m.group(1))), content) + + with open(f"readable_{each}", "w") as file: + file.write(content) \ No newline at end of file