-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauto_updater_2.py
89 lines (79 loc) · 2.37 KB
/
auto_updater_2.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import sys, os, subprocess, re
from lib.getNewFunc import getNewFunc
K64_DIR = "../NK4E/"
CONTEXT_FILE = "~/notkirby/ctx.c"
M2C_LINE_PATTERN = r"#ifdef\s+MIPS_TO_C"
NM_LINE_PATTERN = r"#ifdef\s+NON_MATCHING"
M2C_ELSE_PATTERN = r"#else\n"
M2C_G_ASM_PATTERN = r"GLOBAL_ASM"
# M2C_G_ASM_PATTERN = r"GLOBAL_ASM\s*\(\s*\"(.*?)\"\s*\)."
M2C_END_PATTERN = r"#endif"
class m2cFunc:
def __init__(self):
self.ifdef_line = 0
self.else_line = 0
self.global_asm_file = 0
def GetNonMatchingFunctions(files, rpatterns):
functions = []
for file in files:
with open(file) as f:
lineNum = 1
for line in f:
for x in rpatterns:
if len(re.findall(x, line, re.DOTALL)) != 0:
functions+=[lineNum - 1]
lineNum+=1
return functions
ifdefs = GetNonMatchingFunctions([sys.argv[1]], [M2C_LINE_PATTERN, NM_LINE_PATTERN])
elses = GetNonMatchingFunctions([sys.argv[1]], [M2C_ELSE_PATTERN])
g_asm = GetNonMatchingFunctions([sys.argv[1]], [M2C_G_ASM_PATTERN])
print(g_asm)
ends = GetNonMatchingFunctions([sys.argv[1]], [M2C_END_PATTERN])
ff = open(sys.argv[1])
fl = ff.readlines()
ff.close()
isNewFunc = 0
isOldFunc = 0
endifLine = 0
gotNewFunc = 0
indices = []
nF = ""
lineNum = 0
for line in fl:
if endifLine == 1:
isNewFunc = 0
endifLine = 0
isOldFunc = 0
for x in range(len(ifdefs)):
if lineNum == ifdefs[x]:
if "MIPS_TO_C" in fl[ifdefs[x]]:
isNewFunc = 1
else:
isOldFunc = 1
elif lineNum == ends[x]:
endifLine = 1
# if isOldFunc == 1:
# print("#endif")
elif lineNum == g_asm[x]:
nf = line.replace("(\""," ").replace("\")"," ").split()[1]
if isOldFunc == 0 and isNewFunc == 1:
gotNewFunc = 1
if gotNewFunc == 1:
print(K64_DIR+nf)
nf2 = getNewFunc(K64_DIR+nf)
nF += "#ifdef MIPS_TO_C\n"
nF += nf2
nF += "#else\n"
nF += "GLOBAL_ASM(\""+nf+"\")\n"
# nF += "INCLUDE_ASM(\""+nf+"\")\n"
nF += "#endif\n"
gotNewFunc = 0
if isNewFunc == 0 and endifLine == 0:
nF += line
elif isOldFunc == 1:
nF += line
# print(isNewFunc, isOldFunc, "#bruh")
lineNum += 1;
f = open(sys.argv[1], "w+")
f.write(nF)
f.close()