-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakeSource.py
More file actions
73 lines (59 loc) · 2.15 KB
/
makeSource.py
File metadata and controls
73 lines (59 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# this file is meant to create a C file in the source directory
# given a filepath
import common as c
import os
import re
import yaml
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
def load_from_yaml(path: str, default=None):
"""Loads an object from a yaml file"""
if default is None:
default = {}
with open(path) as f:
ret = yaml.load(f.read(), Loader)
if ret is None:
ret = default
return ret
import argparse
parser = argparse.ArgumentParser(description="Pass filepath from dol_slices.yml")
parser.add_argument('filepath')
args = parser.parse_args()
dolSlices = load_from_yaml(c.DOL_SLICES)
commandParts = [
# "python "
c.DISASSEMBLER,
c.DOL_YML,
c.DOL_LABELS,
c.DOL_RELOCS,
"asm/" + args.filepath.split('/')[-1].replace(".cpp", ".s"),
f"-s {hex(dolSlices[args.filepath]['.text'][0])} {hex(dolSlices[args.filepath]['.text'][1])}",
f"-m {c.GAME_SYMBOLS}",
f"-o {c.DISASM_OVERRIDES}"
]
executeString = ' '.join(commandParts)
# print(executeString)
c.get_cmd_stdout(executeString)
funcNameRe = re.compile(r"((\.global )(.+))")
funcNameRejectJumpRe = re.compile(r"((\.global (?!(?:jump.+)$))(.+))")
print(c.DOL_SRCDIR + '/' + args.filepath)
if os.path.exists(c.DOL_SRCDIR + '/' + args.filepath) == True:
print("Cannot generate existing file!")
exit()
with open(c.DOL_SRCDIR + '/' + args.filepath, "w+") as fd:
with open("asm/" + args.filepath.split('/')[-1].replace(".cpp", ".s"), "rt+") as srcFd:
asmText = srcFd.readlines()
asmText.remove(".include \"macros.inc\"\n")
asmText.remove(".section .text\n")
regexedText = []
regexedText.append("// Assembly file in " + "asm/" + args.filepath.split('/')[-1].replace(".cpp", ".s"))
foundExtern = False
for line in asmText:
replaceStr = "extern \"C\" void \g<3>(void) {}\n// \g<1>"
newLine = re.sub(funcNameRejectJumpRe, replaceStr, line)
if "extern" not in newLine and newLine != '\n':
newLine = '// ' + newLine
regexedText.append(newLine)
fd.writelines(regexedText)