MCPcopy Create free account
hub / github.com/doldecomp/mkdd / main

Function main

tools/custom/decomp_switch.py:245–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

243
244
245def main():
246 code_str = ""
247 if len(argv) < 2:
248 code_str = raw_input()
249 else:
250 if argv[1].casefold() == "-h":
251 show_help()
252 return
253
254 with open(argv[1], "r") as f:
255 code_str = f.readlines()
256
257 flow = build_flow(code_str)
258 min_iter = int(input("Min value (inclusive) for switch statement:"))
259 max_iter = int(input("Max value (inclusive) for switch statement:")) + 1
260
261 # Dictionary format
262 # cases = dict[str, Result]
263 cases = dict()
264
265 for i in range(min_iter, max_iter):
266 case = traverse_flow(flow, i)
267 if not case.dest in cases:
268 cases[case.dest] = list()
269 cases[case.dest].append(Result(case.branch, i))
270
271 print("====================================================")
272 print("Switch analysis:")
273 print("====================================================")
274 print("(Labels are sorted by their order in the asm,")
275 print("so they should be in the original order.)")
276 print("====================================================")
277 print("Asterisk symbol (*) represents BEQ cases,")
278 print("or cases guaranteed to be explicitly specified.")
279 print("====================================================")
280 print("This can help you pick out explicit cases from the default cases.")
281 print("====================================================")
282
283 cases_list = [case for case in cases]
284 for case in sorted(cases_list, key=custom_key):
285 print(f"Label: {case}")
286 values = [str(x) for x in cases[case]]
287 print(f" - Cases: {', '.join(values)}")
288
289
290main()

Callers 1

decomp_switch.pyFile · 0.70

Calls 7

raw_inputFunction · 0.85
show_helpFunction · 0.85
openFunction · 0.85
build_flowFunction · 0.85
traverse_flowFunction · 0.85
ResultClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected