remove asm, hsfman start, add vars to interpretasm
This commit is contained in:
parent
b60e0eccf6
commit
5a7d9615d3
8 changed files with 6683 additions and 21725 deletions
6525
tools/hsfman-output.txt
Normal file
6525
tools/hsfman-output.txt
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
def rc(s:str)->str: return s.replace(',','')
|
||||
|
||||
|
|
@ -6,6 +7,7 @@ def join(*args)->str: return " ".join(args)
|
|||
|
||||
addrstore = {}
|
||||
cmpstore = []
|
||||
isObj = ""
|
||||
def interpret_cmd(line: list, addr: int)->str:
|
||||
global addrstore, cmpstore
|
||||
ret = ""
|
||||
|
|
@ -27,9 +29,9 @@ def interpret_cmd(line: list, addr: int)->str:
|
|||
elif "w" in line[0]: ret += join("", "(s32/u32)")
|
||||
elif "fs" in line[0]: ret += join("", "(f32)")
|
||||
elif "fd" in line[0]: ret += join("", "(f64)")
|
||||
elif line[0] == "stbx" or line[0] == "sthx" or line[0] == "stfsx":
|
||||
elif line[0] == "stbx" or line[0] == "sthx" or line[0] == "stwx" or line[0] == "stfsx":
|
||||
if "r1" in line[2]: ret = "Stack"
|
||||
else: ret += rc(line[2])
|
||||
else: ret = rc(line[2])
|
||||
|
||||
ret += join(f"[{line[3]}]",
|
||||
"=",
|
||||
|
|
@ -61,7 +63,7 @@ def interpret_cmd(line: list, addr: int)->str:
|
|||
ret = join(rc(line[1]), "=", line[2])
|
||||
|
||||
## Loading
|
||||
elif line[0] == "lbz" or line[0] == "lha" or line[0] == "lhz" or line[0] == "lwz" or line[0] == "lfs" or line[0] == "lfd":
|
||||
elif line[0] == "lbz" or line[0] == "lha" or line[0] == "lhz" or line[0] == "lwz" or line[0] == "lwzu" or line[0] == "lfs" or line[0] == "lfd":
|
||||
ret = join(rc(line[1]), "=")
|
||||
if "r1" in line[2]: ret += join("", "Stack")
|
||||
else: ret += join("", line[2][(line[2].index("(")+1):-1])
|
||||
|
|
@ -73,7 +75,7 @@ def interpret_cmd(line: list, addr: int)->str:
|
|||
elif "w" in line[0]: ret += join("", "(s32/u32)")
|
||||
elif "fs" in line[0]: ret += join("", "(f32)")
|
||||
elif "fd" in line[0]: ret += join("", "(f64)")
|
||||
elif line[0] == "lbzx" or line[0] == "lhax" or line[0] == "lwzx" or line[0] == "lfsx":
|
||||
elif line[0] == "lbzx" or line[0] == "lhax" or line[0] == "lhzx" or line[0] == "lwzx" or line[0] == "lfsx":
|
||||
ret = join(rc(line[1]), "=")
|
||||
if "r1" in line[2]: ret += join("", "Stack")
|
||||
else: ret += join("", rc(line[2]))
|
||||
|
|
@ -126,7 +128,7 @@ def interpret_cmd(line: list, addr: int)->str:
|
|||
ret += join("", line[3])
|
||||
elif "neg" in line[0]:
|
||||
ret = join(rc(line[1]), "=", "-"+line[2])
|
||||
elif line[0] == "slwi" or line[0] == "slawi":
|
||||
elif line[0] == "slw" or line[0] == "slwi" or line[0] == "slawi":
|
||||
ret = join(rc(line[1]), "=", rc(line[2]), "<<", line[3], "(s32/u32)", "(signed)" if line[0] == "slawi" else "")
|
||||
elif line[0] == "srwi" or line[0] == "srawi":
|
||||
ret = join(rc(line[1]), "=", rc(line[2]), ">>", line[3], "(s32/u32)", "(signed)" if line[0] == "srawi" else "")
|
||||
|
|
@ -255,9 +257,9 @@ def interpret_cmd(line: list, addr: int)->str:
|
|||
elif line[0] == "crset":
|
||||
ret = f"set({line[1]})"
|
||||
elif line[0] == "extsh":
|
||||
ret = join("s32", rc(line[1]), "= s16", line[2])
|
||||
ret = join("(s32)", rc(line[1]), "= (s16)", line[2])
|
||||
elif line[0] == "extsb":
|
||||
ret = join("s32", rc(line[1]), "= s8", line[2])
|
||||
ret = join("(s32)", rc(line[1]), "= (s8)", line[2])
|
||||
elif line[0] == "clrlwi":
|
||||
ret = join(rc(line[1]), "=", f"remove({line[2]} {line[3]})")
|
||||
elif line[0] == "rlwinm":
|
||||
|
|
@ -273,8 +275,27 @@ def interpret_cmd(line: list, addr: int)->str:
|
|||
return "unable to interpret: "+str(line)
|
||||
return ret
|
||||
|
||||
def interpret_obj(line: list)->str:
|
||||
global isObj
|
||||
ret = ""
|
||||
|
||||
if line[0] == "\t.4byte":
|
||||
if isObj == True:
|
||||
ret = "{\n"
|
||||
ret += join("\t(s32)", line[1])
|
||||
elif line[0] == "\t.string":
|
||||
ret = join("\t(char[])", " ".join(line[1:]))
|
||||
elif line[0] == "\t.skip":
|
||||
ret = join("\tsizeof =", line[1])
|
||||
elif line[0] == "\t.double":
|
||||
ret = join("\t(f64)", line[1])
|
||||
elif line[0] == "\t.float":
|
||||
ret = join("\t(f32)", line[1])
|
||||
|
||||
return ret
|
||||
|
||||
def interpret_line(line: list)->str:
|
||||
global addrstore
|
||||
global addrstore, isObj
|
||||
line = line.split(" ")
|
||||
line[-1] = line[-1].replace("\n","")
|
||||
ret = ""
|
||||
|
|
@ -283,6 +304,12 @@ def interpret_line(line: list)->str:
|
|||
ret = join(line[2], "function", rc(line[1])+":")
|
||||
elif line[0] == ".endfn":
|
||||
ret = join(line[1], "end\n")
|
||||
elif line[0] == ".obj":
|
||||
ret = rc(line[1])+":"
|
||||
isObj = True
|
||||
elif line[0] == ".endobj" and isObj == True:
|
||||
ret = "}"
|
||||
isObj = False
|
||||
elif ".L" in line[0]:
|
||||
try:
|
||||
ret = join("\n\tfrom", addrstore[hex(int(line[0][3:-1], 16))]+":")
|
||||
|
|
@ -294,27 +321,35 @@ def interpret_line(line: list)->str:
|
|||
ret = join("\t", hex(address), "|",
|
||||
interpret_cmd(line[8:], address)
|
||||
)
|
||||
elif "\t" in line[0]:
|
||||
ret = interpret_obj(line)
|
||||
|
||||
isObj = line[0]
|
||||
print(line, "\n", ret, "\n")
|
||||
return ret
|
||||
|
||||
tempcounter = 150
|
||||
def interpret_file(file)->None:
|
||||
global tempcounter
|
||||
curdir = os.path.dirname(os.path.abspath(__file__))
|
||||
fs = file.split("/")[-1]
|
||||
|
||||
os.system(f"mkdir {curdir}/output")
|
||||
f = open(file)
|
||||
g = open("output.txt", "w")
|
||||
g = open(f"{curdir}/output/{fs[:(fs.index('.'))]}-output.txt", "w")
|
||||
line = f.readline()
|
||||
while line:
|
||||
ret = interpret_line(line)
|
||||
g.write(ret+"\n" if ret != "" else "")
|
||||
line = f.readline()
|
||||
tempcounter -= 1
|
||||
g.close()
|
||||
f.close()
|
||||
|
||||
try:
|
||||
interpret_file(sys.argv[1])
|
||||
except:
|
||||
print("interpretasm.py")
|
||||
print("Usage: python3 interpretasm.py [file]")
|
||||
print("Accepts all files that use the generated asm from ninja")
|
||||
except Exception:
|
||||
if len(sys.argv) == 1:
|
||||
print("interpretasm.py")
|
||||
print("Usage: python3 interpretasm.py [file]")
|
||||
print("Accepts all files that use the generated asm from ninja")
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue