tooling: breaking off my tooling changes in the big batch PR so they can be used (#850)

This commit is contained in:
Tyler Wilding
2021-09-19 21:45:14 -04:00
committed by GitHub
parent 8caf398ac0
commit df92a55749
5 changed files with 128 additions and 29 deletions
+19 -18
View File
@@ -3,38 +3,39 @@ from jak1_file_list import file_list
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--file")
parser.add_argument("--files")
parser.add_argument("--list", type=int)
args = parser.parse_args()
def update_file(file, hack):
def update_json_file(decomp_list):
new_file_contents = []
print("Next file to decompile is - " + file[0])
print("Target is - " + "goal_src/" + file[4] + "/" + file[0] + ".gc")
print("Uses the following CGO / DGO - " + str(file[3]))
print("Decompiling - " + ','.join(decomp_list))
# TODO, update the CGO/DGO
with open("decompiler\config\jak1_ntsc_black_label.jsonc", "r") as config_file:
cfg_lines = config_file.readlines()
for line in cfg_lines:
if "allowed_objects" in line and hack == False:
line = " \"allowed_objects\": [\"" + file[0] + "\"],\n"
elif "allowed_objects" in line and hack == True:
line = " \"allowed_objects\": [\"" + file[1] + "\"],\n"
if "allowed_objects" in line:
line = " \"allowed_objects\": [\"" + ','.join(decomp_list) + "\"],\n"
new_file_contents.append(line)
if len(new_file_contents) > 0:
with open("decompiler\config\jak1_ntsc_black_label.jsonc", "w") as f:
f.writelines(new_file_contents)
print("Allowed objects list updated")
if args.file:
for file in file_list:
if file[0] == args.file:
update_file(file, False)
break
elif file[1] == args.file:
# NOTE - kinda a hack, assumes -ag files always come after
update_file(file, True)
break
if args.files:
input_list = args.files.split(",")
decomp_list = []
for inFile in input_list:
for file in file_list:
if file[0] == inFile:
decomp_list.append(file[0])
break
elif file[1] == inFile:
# NOTE - kinda a hack, assumes -ag files always come after
decomp_list.append(file[1])
break
if len(decomp_list) > 0:
update_json_file(decomp_list)
else:
list_eligible = []
for file in file_list:
+92
View File
@@ -0,0 +1,92 @@
## Given a list of files(comma delimited), decompile it, then place it under the specified placeholder (if it exists)
## if the placeholder doesn't exist, error out
## the placeholder is `;; DECOMP BEGINS`
from jak1_file_list import file_list
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--files")
args = parser.parse_args()
files = args.files.split(",")
throw_error = False
for file in files:
disasm_path = "./decompiler_out/jak1/{}_disasm.gc".format(file)
if not os.path.exists(disasm_path):
print("{} doesn't exist!".format(disasm_path))
throw_error = True
continue
src_path = ""
for f in file_list:
if f[2] != 3:
continue
if f[0] == file:
src_path = f[4]
break
if not os.path.exists("./goal_src/{}".format(src_path)):
print("{} couldn't find in /goal_src!".format(file))
throw_error = True
continue
file_path = "./goal_src/{}/{}.gc".format(src_path, file)
new_lines = []
with open(file_path) as f:
lines = f.readlines()
found_placeholder = False
for line in lines:
if ";; decomp begins" in line.lower():
found_placeholder = True
new_lines.append(line.upper())
break
new_lines.append(line)
if found_placeholder == False:
print("No placeholder found in {}, skipping".format(file_path))
throw_error = True
continue
# finally...update the file
lines_to_ignore = [
";;-*-Lisp-*-",
"(in-package goal)",
";; definition",
";; INFO:",
";; failed to figure",
";; Used lq/sq"
]
def skippable_line(line):
for prefix in lines_to_ignore:
if line.startswith(prefix):
return True
return False
with open(disasm_path) as f:
lines = f.readlines()
in_inspect_method = False
for i, line in enumerate(lines):
# strip inspect methods
if line.startswith("(defmethod inspect") or (line.startswith("(defmethod") and (i + 1 < len(lines) and "inspect" in lines[i+1])):
in_inspect_method = True
continue
if in_inspect_method and line == "\n":
in_inspect_method = False
elif in_inspect_method:
continue
# strip comments we dont care about
if skippable_line(line):
continue
# otherwise, add it to the file
new_lines.append(line)
# write the damn thing
os.remove(file_path)
with open(file_path, "w") as f:
f.writelines(new_lines)
print("Copied - {}!".format(file))
if throw_error:
exit(1)