ABI FPR names (#767)

* Add o32 to disassembler and update macro.inc

* Add a variable for asm processor to makefile
and improve objdump flags

* Update diff settings

* git subrepo pull --force tools/asm-differ

subrepo:
  subdir:   "tools/asm-differ"
  merged:   "1236288d1"
upstream:
  origin:   "https://github.com/simonlindholm/asm-differ"
  branch:   "main"
  commit:   "1236288d1"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* Remove * import and implement option

* Fix some stuff in the makefile

* Update asm-processor

* Review

* Fix old var name
This commit is contained in:
EllipticEllipsis
2022-03-31 18:22:19 +01:00
committed by GitHub
parent 54a4d1eb12
commit 15dfaf0862
12 changed files with 513 additions and 280 deletions
+62 -39
View File
@@ -783,6 +783,13 @@ def parse_source(f, opt, framepointer, mips1, input_enc, output_enc, out_depende
else:
min_instr_count = 2
skip_instr_count = 1
elif opt == 'O0':
if framepointer:
min_instr_count = 8
skip_instr_count = 8
else:
min_instr_count = 4
skip_instr_count = 4
elif opt == 'g':
if framepointer:
min_instr_count = 7
@@ -792,7 +799,7 @@ def parse_source(f, opt, framepointer, mips1, input_enc, output_enc, out_depende
skip_instr_count = 4
else:
if opt != 'g3':
raise Failure("must pass one of -g, -O1, -O2, -O2 -g3")
raise Failure("must pass one of -g, -O0, -O1, -O2, -O2 -g3")
if framepointer:
min_instr_count = 4
skip_instr_count = 4
@@ -813,6 +820,7 @@ def parse_source(f, opt, framepointer, mips1, input_enc, output_enc, out_depende
]
is_cutscene_data = False
is_early_include = False
for line_no, raw_line in enumerate(f, 1):
raw_line = raw_line.rstrip()
@@ -832,44 +840,51 @@ def parse_source(f, opt, framepointer, mips1, input_enc, output_enc, out_depende
global_asm = None
else:
global_asm.process_line(raw_line, output_enc)
elif line in ['GLOBAL_ASM(', '#pragma GLOBAL_ASM(']:
global_asm = GlobalAsmBlock("GLOBAL_ASM block at line " + str(line_no))
start_index = len(output_lines)
elif ((line.startswith('GLOBAL_ASM("') or line.startswith('#pragma GLOBAL_ASM("'))
and line.endswith('")')):
fname = line[line.index('(') + 2 : -2]
out_dependencies.append(fname)
global_asm = GlobalAsmBlock(fname)
with open(fname, encoding=input_enc) as f:
for line2 in f:
global_asm.process_line(line2.rstrip(), output_enc)
src, fn = global_asm.finish(state)
output_lines[-1] = ''.join(src)
asm_functions.append(fn)
global_asm = None
elif line == '#pragma asmproc recurse':
# C includes qualified as
# #pragma asmproc recurse
# #include "file.c"
# will be processed recursively when encountered
is_early_include = True
elif is_early_include:
# Previous line was a #pragma asmproc recurse
is_early_include = False
if not line.startswith("#include "):
raise Failure("#pragma asmproc recurse must be followed by an #include ")
fpath = os.path.dirname(f.name)
fname = os.path.join(fpath, line[line.index(' ') + 2 : -1])
out_dependencies.append(fname)
include_src = StringIO()
with open(fname, encoding=input_enc) as include_file:
parse_source(include_file, opt, framepointer, mips1, input_enc, output_enc, out_dependencies, include_src)
include_src.write('#line ' + str(line_no + 1) + ' "' + f.name + '"')
output_lines[-1] = include_src.getvalue()
include_src.close()
else:
if line in ['GLOBAL_ASM(', '#pragma GLOBAL_ASM(']:
global_asm = GlobalAsmBlock("GLOBAL_ASM block at line " + str(line_no))
start_index = len(output_lines)
elif ((line.startswith('GLOBAL_ASM("') or line.startswith('#pragma GLOBAL_ASM("'))
and line.endswith('")')):
fname = line[line.index('(') + 2 : -2]
out_dependencies.append(fname)
global_asm = GlobalAsmBlock(fname)
with open(fname, encoding=input_enc) as f:
for line2 in f:
global_asm.process_line(line2.rstrip(), output_enc)
src, fn = global_asm.finish(state)
output_lines[-1] = ''.join(src)
asm_functions.append(fn)
global_asm = None
elif line.startswith('#include "') and line.endswith('" EARLY'):
# C includes qualified with EARLY (i.e. #include "file.c" EARLY) will be
# processed recursively when encountered
fpath = os.path.dirname(f.name)
fname = os.path.join(fpath, line[line.index(' ') + 2 : -7])
out_dependencies.append(fname)
include_src = StringIO()
with open(fname, encoding=input_enc) as include_file:
parse_source(include_file, opt, framepointer, mips1, input_enc, output_enc, out_dependencies, include_src)
include_src.write('#line ' + str(line_no + 1) + ' "' + f.name + '"')
output_lines[-1] = include_src.getvalue()
include_src.close()
else:
# This is a hack to replace all floating-point numbers in an array of a particular type
# (in this case CutsceneData) with their corresponding IEEE-754 hexadecimal representation
if cutscene_data_regexpr.search(line) is not None:
is_cutscene_data = True
elif line.endswith("};"):
is_cutscene_data = False
if is_cutscene_data:
raw_line = re.sub(float_regexpr, repl_float_hex, raw_line)
output_lines[-1] = raw_line
# This is a hack to replace all floating-point numbers in an array of a particular type
# (in this case CutsceneData) with their corresponding IEEE-754 hexadecimal representation
if cutscene_data_regexpr.search(line) is not None:
is_cutscene_data = True
elif line.endswith("};"):
is_cutscene_data = False
if is_cutscene_data:
raw_line = re.sub(float_regexpr, repl_float_hex, raw_line)
output_lines[-1] = raw_line
if print_source:
if isinstance(print_source, StringIO):
@@ -877,7 +892,14 @@ def parse_source(f, opt, framepointer, mips1, input_enc, output_enc, out_depende
print_source.write(line + '\n')
else:
for line in output_lines:
print_source.write(line.encode(output_enc) + b'\n')
try:
line_encoded = line.encode(output_enc)
except UnicodeEncodeError:
print("Failed to encode a line to", output_enc)
print("The line:", line)
print("The line, utf-8-encoded:", line.encode("utf-8"))
raise
print_source.write(line_encoded + b'\n')
print_source.flush()
if print_source != sys.stdout.buffer:
print_source.close()
@@ -1239,6 +1261,7 @@ def run_wrapped(argv, outfile, functions):
parser.add_argument('-mips1', dest='mips1', action='store_true')
parser.add_argument('-g3', dest='g3', action='store_true')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-O0', dest='opt', action='store_const', const='O0')
group.add_argument('-O1', dest='opt', action='store_const', const='O1')
group.add_argument('-O2', dest='opt', action='store_const', const='O2')
group.add_argument('-g', dest='opt', action='store_const', const='g')
+43 -13
View File
@@ -10,30 +10,49 @@ dir_path = os.path.dirname(os.path.realpath(__file__))
prelude = os.path.join(dir_path, "prelude.inc")
all_args = sys.argv[1:]
sep1 = all_args.index('--')
sep2 = all_args.index('--', sep1+1)
sep0 = [index for index, arg in enumerate(all_args) if not arg.startswith("-")][0]
sep1 = all_args.index("--")
sep2 = all_args.index("--", sep1 + 1)
compiler = all_args[:sep1]
asmproc_flags = all_args[:sep0]
compiler = all_args[sep0:sep1]
assembler = all_args[sep1+1:sep2]
assembler_sh = ' '.join(shlex.quote(x) for x in assembler)
assembler = all_args[sep1 + 1 : sep2]
assembler_sh = " ".join(shlex.quote(x) for x in assembler)
compile_args = all_args[sep2+1:]
compile_args = all_args[sep2 + 1 :]
in_file = compile_args[-1]
out_ind = compile_args.index('-o')
out_ind = compile_args.index("-o")
out_file = compile_args[out_ind + 1]
del compile_args[-1]
del compile_args[out_ind + 1]
del compile_args[out_ind]
in_dir = os.path.split(os.path.realpath(in_file))[0]
opt_flags = [x for x in compile_args if x in ['-g3', '-g', '-O1', '-O2', '-framepointer']]
opt_flags = [
x for x in compile_args if x in ["-g3", "-g", "-O0", "-O1", "-O2", "-framepointer"]
]
if "-mips2" not in compile_args:
opt_flags.append("-mips1")
preprocessed_file = tempfile.NamedTemporaryFile(prefix='preprocessed', suffix='.c', delete=False)
asmproc_flags += opt_flags + [in_file]
# Drop .mdebug and .gptab sections from resulting binaries. This makes
# resulting .o files much smaller and speeds up builds, but loses line
# number debug data.
# asmproc_flags += ["--drop-mdebug-gptab"]
# Convert encoding before compiling.
# asmproc_flags += ["--input-enc", "utf-8", "--output-enc", "euc-jp"]
preprocessed_file = tempfile.NamedTemporaryFile(
prefix="preprocessed", suffix=".c", delete=False
)
try:
asmproc_flags = opt_flags + [in_file, '--input-enc', 'utf-8', '--output-enc', 'euc-jp']
compile_cmdline = compiler + compile_args + ['-I', in_dir, '-o', out_file, preprocessed_file.name]
compile_cmdline = (
compiler + compile_args + ["-I", in_dir, "-o", out_file, preprocessed_file.name]
)
functions, deps = asm_processor.run(asmproc_flags, outfile=preprocessed_file)
try:
@@ -41,13 +60,24 @@ try:
except subprocess.CalledProcessError as e:
print("Failed to compile file " + in_file + ". Command line:")
print()
print(' '.join(shlex.quote(x) for x in compile_cmdline))
print(" ".join(shlex.quote(x) for x in compile_cmdline))
print()
sys.exit(55)
# To keep the preprocessed file:
# os._exit(1)
asm_processor.run(asmproc_flags + ['--post-process', out_file, '--assembler', assembler_sh, '--asm-prelude', prelude], functions=functions)
asm_processor.run(
asmproc_flags
+ [
"--post-process",
out_file,
"--assembler",
assembler_sh,
"--asm-prelude",
prelude,
],
functions=functions,
)
deps_file = out_file[:-2] + ".asmproc.d"
if deps:
+39 -1
View File
@@ -1,5 +1,43 @@
.set noat
.set noreorder
.set gp=64
.include "macro.inc"
.macro glabel label
.global \label
\label:
.endm
# Float register aliases (o32 ABI, odd ones are rarely used)
.set $fv0, $f0
.set $fv0f, $f1
.set $fv1, $f2
.set $fv1f, $f3
.set $ft0, $f4
.set $ft0f, $f5
.set $ft1, $f6
.set $ft1f, $f7
.set $ft2, $f8
.set $ft2f, $f9
.set $ft3, $f10
.set $ft3f, $f11
.set $fa0, $f12
.set $fa0f, $f13
.set $fa1, $f14
.set $fa1f, $f15
.set $ft4, $f16
.set $ft4f, $f17
.set $ft5, $f18
.set $ft5f, $f19
.set $fs0, $f20
.set $fs0f, $f21
.set $fs1, $f22
.set $fs1f, $f23
.set $fs2, $f24
.set $fs2f, $f25
.set $fs3, $f26
.set $fs3f, $f27
.set $fs4, $f28
.set $fs4f, $f29
.set $fs5, $f30
.set $fs5f, $f31