2017-12-21 21:16:46 +00:00
|
|
|
"""
|
2017-12-25 15:00:25 +00:00
|
|
|
Programming Language for 6502/6510 microprocessors, codename 'Sick'
|
2017-12-21 21:16:46 +00:00
|
|
|
This is the main program that drives the rest.
|
|
|
|
|
2018-01-08 02:31:23 +00:00
|
|
|
Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
2017-12-21 21:16:46 +00:00
|
|
|
"""
|
|
|
|
|
2017-12-25 01:07:17 +00:00
|
|
|
import time
|
2017-12-21 21:16:46 +00:00
|
|
|
import os
|
|
|
|
import argparse
|
2017-12-27 22:45:22 +00:00
|
|
|
import subprocess
|
2018-01-09 01:40:32 +00:00
|
|
|
from .compile import PlyParser
|
|
|
|
from .optimize import optimize
|
|
|
|
from .generateasm import AssemblyGenerator, Assembler64Tass
|
|
|
|
from .plylex import print_bold
|
2017-12-21 21:16:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
description = "Compiler for IL65 language, code name 'Sick'"
|
|
|
|
ap = argparse.ArgumentParser(description=description)
|
|
|
|
ap.add_argument("-o", "--output", help="output directory")
|
2017-12-27 22:45:22 +00:00
|
|
|
ap.add_argument("-no", "--nooptimize", action="store_true", help="do not optimize the parse tree")
|
|
|
|
ap.add_argument("-sv", "--startvice", action="store_true", help="autostart vice x64 emulator after compilation")
|
2017-12-21 21:16:46 +00:00
|
|
|
ap.add_argument("sourcefile", help="the source .ill/.il65 file to compile")
|
|
|
|
args = ap.parse_args()
|
|
|
|
assembly_filename = os.path.splitext(args.sourcefile)[0] + ".asm"
|
|
|
|
program_filename = os.path.splitext(args.sourcefile)[0] + ".prg"
|
|
|
|
if args.output:
|
|
|
|
os.makedirs(args.output, mode=0o700, exist_ok=True)
|
|
|
|
assembly_filename = os.path.join(args.output, os.path.split(assembly_filename)[1])
|
|
|
|
program_filename = os.path.join(args.output, os.path.split(program_filename)[1])
|
|
|
|
|
|
|
|
print("\n" + description)
|
|
|
|
|
2017-12-25 01:07:17 +00:00
|
|
|
start = time.perf_counter()
|
2018-01-09 01:40:32 +00:00
|
|
|
print("\nParsing program source code.")
|
|
|
|
parser = PlyParser()
|
|
|
|
parsed_module = parser.parse_file(args.sourcefile)
|
|
|
|
if parsed_module:
|
2017-12-27 22:45:22 +00:00
|
|
|
if args.nooptimize:
|
2018-01-09 01:40:32 +00:00
|
|
|
print_bold("not optimizing the parse tree!")
|
2017-12-21 22:05:35 +00:00
|
|
|
else:
|
2018-01-09 23:44:11 +00:00
|
|
|
print("\nOptimizing code.")
|
2018-01-09 01:40:32 +00:00
|
|
|
optimize(parsed_module)
|
|
|
|
print("\nGenerating assembly code.")
|
|
|
|
cg = AssemblyGenerator(parsed_module)
|
|
|
|
cg.generate(assembly_filename)
|
|
|
|
assembler = Assembler64Tass(parsed_module.format)
|
2017-12-21 21:16:46 +00:00
|
|
|
assembler.assemble(assembly_filename, program_filename)
|
2017-12-27 22:45:22 +00:00
|
|
|
mon_command_file = assembler.generate_breakpoint_list(program_filename)
|
2017-12-25 01:07:17 +00:00
|
|
|
duration_total = time.perf_counter() - start
|
|
|
|
print("Compile duration: {:.2f} seconds".format(duration_total))
|
2018-01-13 01:13:32 +00:00
|
|
|
size = os.path.getsize(program_filename)
|
|
|
|
print("Output size: {:d} bytes".format(size))
|
2018-01-09 01:40:32 +00:00
|
|
|
print_bold("Output file: " + program_filename)
|
2017-12-21 21:16:46 +00:00
|
|
|
print()
|
2017-12-27 22:45:22 +00:00
|
|
|
if args.startvice:
|
|
|
|
print("Autostart vice emulator...")
|
2017-12-28 03:20:59 +00:00
|
|
|
cmdline = ["x64", "-remotemonitor", "-moncommands", mon_command_file,
|
|
|
|
"-autostartprgmode", "1", "-autostart-warp", "-autostart", program_filename]
|
2017-12-27 22:45:22 +00:00
|
|
|
with open(os.devnull, "wb") as shutup:
|
2017-12-28 03:20:59 +00:00
|
|
|
subprocess.call(cmdline, stdout=shutup)
|