Updated argument handling

This commit is contained in:
Kyler 2024-02-23 00:32:23 -07:00
parent 7164a70f81
commit a7d026190e
1 changed files with 8 additions and 13 deletions

View File

@ -383,27 +383,22 @@ def immediate(line: str, line_number: int) -> Instruction | Immediate:
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='ytd12LA', description='ytd 12-bit Computer Linker and Assembler',
description='ytd 12-bit Linker and Assembler',
# epilog='Text at the bottom of help',
) )
parser.add_argument('input_file') parser.add_argument('input_file', type=argparse.FileType('r'))
parser.add_argument('-o', '--output_file') parser.add_argument('-o', '--output_file', type=argparse.FileType('wb'))
parser.add_argument('-l', '--labels_file') parser.add_argument('-l', '--labels_file', type=argparse.FileType('w'))
args = parser.parse_args() args = parser.parse_args()
with open(args.input_file) as ifile: program = Program(args.input_file.read())
program = Program(ifile.read())
if args.output_file: if args.output_file:
with open(args.output_file, 'wb') as ofile: args.output_file.write(bytes(program))
ofile.write(bytes(program))
if args.labels_file: if args.labels_file:
with open(args.labels_file, 'w') as lfile: for label, location in program.labels().items():
for label, location in program.labels().items(): args.labels_file.write(f"{hex(location)}, {label}\n")
lfile.write(f"{hex(location)}, {label}\n")
if __name__ == '__main__': if __name__ == '__main__':
main() main()