Allow support for multiple input files.

To account for this change, output files are now prefixed with the
-o option, and if none is specified, it defaults to 'ophis.bin'.
This commit is contained in:
Michael Martin 2012-06-03 18:32:25 -07:00
parent 809bf51239
commit 17f68399ef
3 changed files with 20 additions and 16 deletions

View File

@ -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

View File

@ -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("<Top Level>", filename)
nodes = [parse_file("<Top Level>", f) for f in filenames]
if len(nodes) == 1:
return nodes[0]
return IR.SequenceNode("<Top level>", nodes)

View File

@ -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__':