#!/usr/bin/env python2.7

import argparse

from util.assemble import assemble
from util.hexdump import hexdump


def get_args():
    parser = argparse.ArgumentParser(description='Spym MIPS Assembler. Generates "spym" format binaries.')
    parser.add_argument('file', metavar='FILE', type=str,
                        help='MIPS source file')
    return parser.parse_args()


def main():
    args = get_args()
    fname = args.file
    if fname.endswith('.s'):
        fname = fname[-2:] + '.spym'
    else:
        fname = fname + '.spym'
    # with open(fname, 'w') as f:
    hexdump(assemble(args.file))

if __name__ == '__main__':
    main()

@@ -75,41 +75,8 @@
 ble%0A
-from util.hexdump import hexdump%0A
 %0A%0Ade
@@ -311,222 +311,263 @@
     
-return parser.parse_args()%0A%0A%0Adef main():%0A    args = get_args()%0A    fname = args.file%0A    if fname.endswith('.s'):%0A        fname = fname%5B-2:%5D + '.spym'%0A    else:%0A        fname = fname + '.spym'%0A    # with open(fname
+parser.add_argument('-o', '--output', type=str,%0A                        help='File to write output to. Default is a.out',%0A                        default='a.out')%0A    return parser.parse_args()%0A%0A%0Adef main():%0A    args = get_args()%0A    with open(args.output
 , 'w
@@ -583,15 +583,19 @@
     
-hexdump
+    f.write
 (ass

Write to file instead of hexdump