diff --git a/src/Ophis/CmdLine.py b/src/Ophis/CmdLine.py index 6beb174..5cf80b3 100644 --- a/src/Ophis/CmdLine.py +++ b/src/Ophis/CmdLine.py @@ -19,7 +19,7 @@ print_pass = False print_ir = False print_labels = False -infile = None +infiles = None outfile = None @@ -30,12 +30,15 @@ def parse_args(raw_args): global warn_on_branch_extend global print_summary, print_loaded_files global print_pass, print_ir, print_labels - global infile, outfile + global infiles, outfile parser = optparse.OptionParser( usage="Usage: %prog [options] srcfile outfile", version="Ophis 6502 cross-assembler, version 2.0") + parser.add_option("-o", default=None, dest="outfile", + help="Output filename (default 'ophis.bin')") + ingrp = optparse.OptionGroup(parser, "Input options") ingrp.add_option("-u", "--undoc", action="store_true", default=False, help="Enable 6502 undocumented opcodes") @@ -66,17 +69,13 @@ def parse_args(raw_args): (options, args) = parser.parse_args(raw_args) - if len(args) > 2: - parser.error("Too many files specified") - if len(args) == 1: - parser.error("No output file specified") if len(args) == 0: - parser.error("No files specified") + parser.error("No input files specified") if options.c02 and options.undoc: parser.error("--undoc and --65c02 are mutually exclusive") - infile = args[0] - outfile = args[1] + infiles = args + outfile = options.outfile enable_collapse = options.enable_collapse enable_branch_extend = options.enable_branch_extend enable_undoc_ops = options.undoc diff --git a/src/Ophis/Frontend.py b/src/Ophis/Frontend.py index f8176ce..8bade2e 100644 --- a/src/Ophis/Frontend.py +++ b/src/Ophis/Frontend.py @@ -371,9 +371,12 @@ def parse_file(ppt, filename): return IR.NullNode -def parse(filename): +def parse(filenames): """Top level parsing routine, taking a source file name - and returning an IR list.""" + list and returning an IR list.""" global templabelcount templabelcount = 0 - return parse_file("", filename) + nodes = [parse_file("", f) for f in filenames] + if len(nodes) == 1: + return nodes[0] + return IR.SequenceNode("", nodes) diff --git a/src/Ophis/Main.py b/src/Ophis/Main.py index f66bf08..2513d23 100644 --- a/src/Ophis/Main.py +++ b/src/Ophis/Main.py @@ -18,10 +18,10 @@ import Ophis.CmdLine import Ophis.Opcodes -def run_all(infile, outfile): - "Transforms the source infile to a binary outfile." +def run_all(infiles, outfile): + "Transforms the source infiles to a binary outfile." Err.count = 0 - z = Ophis.Frontend.parse(infile) + z = Ophis.Frontend.parse(infiles) env = Ophis.Environment.Environment() m = Ophis.Passes.ExpandMacros() @@ -57,6 +57,8 @@ def run_all(infile, outfile): try: if outfile == '-': output = sys.stdout + elif outfile is None: + output = file('ophis.bin', 'wb') else: output = file(outfile, 'wb') output.write("".join(map(chr, a.output))) @@ -79,7 +81,7 @@ def run_ophis(args): Ophis.Opcodes.opcodes.update(Ophis.Opcodes.c02extensions) Ophis.CorePragmas.reset() - run_all(Ophis.CmdLine.infile, Ophis.CmdLine.outfile) + run_all(Ophis.CmdLine.infiles, Ophis.CmdLine.outfile) if __name__ == '__main__':