Beispiel #1
0
def main(args):
    """
    Runs the assembler with the specified arguments.

    :param args: the command-line arguments
    """
    program = Program()
    program.process(args.filename)
    name = program.name or args.name

    if args.symbols:
        program.print_symbol_table()

    if args.print:
        program.print_statements()

    if args.bin_file:
        binary_file = BinaryFile()
        binary_file.open_host_file(args.bin_file)
        binary_file.save_file(None, program.get_binary_array())
        binary_file.close_host_file()

    if args.cas_file:
        if not name:
            print("No name for the program specified, not creating cassette file")
            return
        try:
            binary_file = CassetteFile(program.origin, program.origin)
            binary_file.open_host_file(args.cas_file, append=args.append)
            binary_file.save_file(name, program.get_binary_array())
            binary_file.close_host_file()
        except ValueError as error:
            print("Unable to save cassette file:")
            print(error)
 def test_print_symbol_table_corect(self, print_mock):
     statement = Statement("POLCAT EQU $FFEE")
     program = Program()
     program.save_symbol(0, statement)
     program.print_symbol_table()
     self.assertEqual([call("-- Symbol Table --"),
                       call("$FFEE POLCAT")], print_mock.mock_calls)
Beispiel #3
0
def main(args):
    """
    Runs the assembler with the specified arguments.

    :param args: the command-line arguments
    """
    program = Program(width=args.width)
    program.process(args.filename)
    coco_file = CoCoFile(name=program.name or args.name,
                         load_addr=program.origin,
                         exec_addr=program.origin,
                         data=program.get_binary_array())

    if args.symbols:
        program.print_symbol_table()

    if args.print:
        program.print_statements()

    if args.bin_file:
        try:
            binary_file = BinaryFile()
            binary_file.open_host_file_for_write(args.bin_file,
                                                 append=args.append)
            binary_file.save_to_host_file(coco_file)
            binary_file.close_host_file()
        except ValueError as error:
            print("Unable to save binary file:")
            print(error)

    if args.cas_file:
        if not coco_file.name:
            print(
                "No name for the program specified, not creating cassette file"
            )
            return
        try:
            cas_file = CassetteFile()
            cas_file.open_host_file_for_write(args.cas_file,
                                              append=args.append)
            cas_file.save_to_host_file(coco_file)
            cas_file.close_host_file()
        except ValueError as error:
            print("Unable to save cassette file:")
            print(error)
Beispiel #4
0
 def test_print_empty_symbol_table_corect(self, print_mock):
     program = Program()
     program.print_symbol_table()
     self.assertEqual([call("-- Symbol Table --")], print_mock.mock_calls)