mirror of
https://github.com/zeldaret/oot.git
synced 2024-11-13 04:39:36 +00:00
Small asm-processor optimization (#459)
Co-authored-by: zelda2774 <zelda2774@invalid>
This commit is contained in:
parent
d02153707e
commit
9e5cbcdd57
2 changed files with 17 additions and 10 deletions
|
@ -185,7 +185,7 @@ class Section:
|
|||
if self.sh_entsize != 0:
|
||||
assert self.sh_size % self.sh_entsize == 0
|
||||
if self.sh_type == SHT_NOBITS:
|
||||
self.data = ''
|
||||
self.data = b''
|
||||
else:
|
||||
self.data = data[self.sh_offset:self.sh_offset + self.sh_size]
|
||||
self.index = index
|
||||
|
@ -466,6 +466,9 @@ class GlobalAsmBlock:
|
|||
self.fail(".ascii with no string", real_line)
|
||||
return ret + num_parts if z else ret
|
||||
|
||||
def align2(self):
|
||||
while self.fn_section_sizes[self.cur_section] % 2 != 0:
|
||||
self.fn_section_sizes[self.cur_section] += 1
|
||||
|
||||
def align4(self):
|
||||
while self.fn_section_sizes[self.cur_section] % 4 != 0:
|
||||
|
@ -553,6 +556,9 @@ class GlobalAsmBlock:
|
|||
self.add_sized(self.count_quoted_size(line, z, real_line, output_enc), real_line)
|
||||
elif line.startswith('.byte'):
|
||||
self.add_sized(len(line.split(',')), real_line)
|
||||
elif line.startswith('.half'):
|
||||
self.align2()
|
||||
self.add_sized(2*len(line.split(',')), real_line)
|
||||
elif line.startswith('.'):
|
||||
# .macro, ...
|
||||
self.fail("asm directive not supported", real_line)
|
||||
|
@ -778,7 +784,7 @@ def parse_source(f, opt, framepointer, input_enc, output_enc, print_source=None)
|
|||
output_lines[-1] = ''.join(src)
|
||||
asm_functions.append(fn)
|
||||
global_asm = None
|
||||
elif ((line.startswith('#include "')) and line.endswith('" EARLY')):
|
||||
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)
|
||||
|
@ -1095,7 +1101,7 @@ def fixup_objfile(objfile_name, functions, asm_prelude, assembler, output_enc):
|
|||
except:
|
||||
pass
|
||||
|
||||
def run_wrapped(argv, outfile):
|
||||
def run_wrapped(argv, outfile, functions):
|
||||
parser = argparse.ArgumentParser(description="Pre-process .c files and post-process .o files to enable embedding assembly into C.")
|
||||
parser.add_argument('filename', help="path to .c code")
|
||||
parser.add_argument('--post-process', dest='objfile', help="path to .o file to post-process")
|
||||
|
@ -1118,12 +1124,13 @@ def run_wrapped(argv, outfile):
|
|||
|
||||
if args.objfile is None:
|
||||
with open(args.filename, encoding=args.input_enc) as f:
|
||||
parse_source(f, opt=opt, framepointer=args.framepointer, input_enc=args.input_enc, output_enc=args.output_enc, print_source=outfile)
|
||||
return parse_source(f, opt=opt, framepointer=args.framepointer, input_enc=args.input_enc, output_enc=args.output_enc, print_source=outfile)
|
||||
else:
|
||||
if args.assembler is None:
|
||||
raise Failure("must pass assembler command")
|
||||
with open(args.filename, encoding=args.input_enc) as f:
|
||||
functions = parse_source(f, opt=opt, framepointer=args.framepointer, input_enc=args.input_enc, output_enc=args.output_enc)
|
||||
if functions is None:
|
||||
with open(args.filename, encoding=args.input_enc) as f:
|
||||
functions = parse_source(f, opt=opt, framepointer=args.framepointer, input_enc=args.input_enc, output_enc=args.output_enc)
|
||||
if not functions:
|
||||
return
|
||||
asm_prelude = b''
|
||||
|
@ -1132,9 +1139,9 @@ def run_wrapped(argv, outfile):
|
|||
asm_prelude = f.read()
|
||||
fixup_objfile(args.objfile, functions, asm_prelude, args.assembler, args.output_enc)
|
||||
|
||||
def run(argv, outfile=sys.stdout.buffer):
|
||||
def run(argv, outfile=sys.stdout.buffer, functions=None):
|
||||
try:
|
||||
run_wrapped(argv, outfile)
|
||||
return run_wrapped(argv, outfile, functions)
|
||||
except Failure as e:
|
||||
print("Error:", e, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -35,7 +35,7 @@ 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]
|
||||
|
||||
asm_processor.run(asmproc_flags, outfile=preprocessed_file)
|
||||
functions = asm_processor.run(asmproc_flags, outfile=preprocessed_file)
|
||||
try:
|
||||
subprocess.check_call(compile_cmdline)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
@ -47,6 +47,6 @@ try:
|
|||
# To keep the preprocessed file:
|
||||
# os._exit(1)
|
||||
|
||||
asm_processor.run(asmproc_flags + ['--post-process', out_file, '--assembler', assembler_sh, '--asm-prelude', prelude])
|
||||
asm_processor.run(asmproc_flags + ['--post-process', out_file, '--assembler', assembler_sh, '--asm-prelude', prelude], functions=functions)
|
||||
finally:
|
||||
os.remove(preprocessed_file.name)
|
||||
|
|
Loading…
Reference in a new issue