From c0bf2e98b77ac4a16712052c5cbc8b0d262a789e Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Mon, 24 Mar 2014 12:32:17 +0000 Subject: [PATCH] A very, *very* poor-man's version of label<->address dump. Ugh! --- src/Ophis/CmdLine.py | 6 +++++- src/Ophis/Environment.py | 5 +++++ src/Ophis/Passes.py | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Ophis/CmdLine.py b/src/Ophis/CmdLine.py index 3b85a5a..f3b8586 100644 --- a/src/Ophis/CmdLine.py +++ b/src/Ophis/CmdLine.py @@ -22,6 +22,7 @@ print_labels = False infiles = None outfile = None listfile = None +mapfile = None def parse_args(raw_args): @@ -31,7 +32,7 @@ def parse_args(raw_args): global warn_on_branch_extend global print_summary, print_loaded_files global print_pass, print_ir, print_labels - global infiles, outfile, listfile + global infiles, outfile, listfile, mapfile parser = optparse.OptionParser( usage="Usage: %prog [options] srcfile [srcfile ...]", @@ -41,6 +42,8 @@ def parse_args(raw_args): help="Output filename (default 'ophis.bin')") parser.add_option("-l", default=None, dest="listfile", help="Listing filename (not created by default)") + parser.add_option("-m", default=None, dest="mapfile", + help="Label-address map filename (not created by default)") ingrp = optparse.OptionGroup(parser, "Input options") ingrp.add_option("-u", "--undoc", action="store_true", default=False, @@ -83,6 +86,7 @@ def parse_args(raw_args): infiles = args outfile = options.outfile listfile = options.listfile + mapfile = options.mapfile enable_branch_extend = options.enable_branch_extend enable_undoc_ops = options.undoc enable_65c02_exts = options.c02 diff --git a/src/Ophis/Environment.py b/src/Ophis/Environment.py index 7d7546d..7563d96 100644 --- a/src/Ophis/Environment.py +++ b/src/Ophis/Environment.py @@ -88,3 +88,8 @@ class Environment(object): if len(self.stack) == 1: Err.log("Unmatched .scend") self.stack.pop(0) + + def dump_mapfile(self, f): + for d in self.dicts: + for k in d: + f.write("{0:<30} ${1:04X}\n".format(k, d[k])) diff --git a/src/Ophis/Passes.py b/src/Ophis/Passes.py index bb1623d..4ecce5b 100644 --- a/src/Ophis/Passes.py +++ b/src/Ophis/Passes.py @@ -755,8 +755,16 @@ class Assembler(Pass): else: self.listing = Listing.NullLister() + def go(self, node, env): + # record env, as we need it in postPass + self.env = env + super(Assembler, self).go(node, env) + def postPass(self): self.listing.dump() + if Cmd.mapfile is not None: + with open(Cmd.mapfile, 'w') as f: + self.env.dump_mapfile(f) if Cmd.print_summary and Err.count == 0: print>>sys.stderr, "Assembly complete: %s bytes output " \ "(%s code, %s data, %s filler)" \