Exemple #1
0
def main():
    if len(sys.argv) < 6:
        print >>sys.stderr, "Usage: %s <instmem.mif> <instmem_size in byte> <datamem.mif> <datamem_size in byte> <xxx.S> [xxx.S] ..." % (sys.argv[0])
        sys.exit(1)
    if sys.argv[1] != '-':
        instmif = MifFile(sys.argv[1])
        instmif.init(int(sys.argv[2]), 1)
    else:
        instmif = None
    if sys.argv[3] != '-':
        datamif = MifFile(sys.argv[3])
        datamif.init(int(sys.argv[4]), 4)
    else:
        datamif = None
    assembler = Assembler()
    for filename in sys.argv[5:]:
        assembler.compile(filename)
    assembler.relocate()
    if instmif != None:
        if assembler.instmem.get_size() > instmif.memory.size:
            print "Inst mem too small, need %dB" % (assembler.instmem.get_size())
            sys.exit(1)
        assembler.instmem.fill(instmif.memory)
        instmif.write_back()
    if datamif != None:
        if assembler.datamem.get_size() > datamif.memory.size:
            print "Data mem too small, need %dB" % (assembler.datamem.get_size())
            sys.exit(1)
        assembler.datamem.fill(datamif.memory)
        datamif.write_back()
Exemple #2
0
def main(architecture):
    # architecture = '148'
    dfg = parser('dotfiles/Architecture_latency_{}.dot'.format(architecture))
    simplified_dfg = parser(
        'dotfiles/Architecture_latency_{}_schematic.dot'.format(architecture))

    fus: List[AGraph] = dfg.subgraphs()

    subgraphs = {}
    for subgraph in fus:
        subgraphs[subgraph.graph_attr['label'].strip()] = subgraph

    for fu in fus:
        ATMI.max_cycle = 0
        assembler = Assembler()

        label = fu.graph_attr['label'].strip()
        # NOTE: handle load FUs
        if 'load' in label or 'store' in label:
            continue

        input_map, max_fu = input_mapper.map_input(fu, subgraphs,
                                                   simplified_dfg)
        rf_alloc_path = 'dotfiles/Architecture_latency_{}_'.format(
            architecture) + label + '_rf_allocation.csv'
        rf_allocs, max_address = rf_alloc_parser(rf_alloc_path)

        assembler.add_assembly(
            op_generator.gen_op_insts(rf_allocs, dfg, fu, input_map))
        assembler.add_assembly(
            alloc_generator.gen_alloc_insts(rf_allocs, dfg, fu, input_map))

        try:
            assembler.compile(max_address, max_fu)
            config = control_signal_generator.gen_config(
                assembler, max_address, max_fu, 1, label)
            vhdl, tot_wait = control_signal_generator.insert_signals(
                assembler.export())

            with open('out/' + label + '.program', 'w') as f:
                f.write('TOTAL_WAIT_NS ' + str(tot_wait) + '\n')
                for line in config:
                    f.write(line + '\n')
                f.write('\n')
                for line in vhdl:
                    f.write(line + '\n')

        except MergeException as merge:
            print("ERROR COMPILING INSTRUCTIONS FOR " + label + " : " +
                  merge.args[0])
Exemple #3
0
def main():
    help = '''
    Usage:
    python main.py tests/fibonacci.asm
    python main.py tests/sub_mul_div.asm nodebug
    注:fibonacci.asm 无限循环求斐波那契数
        sub_mul_div.asm 加减乘除测试
        jmp.asm 跳转命令测试
    可以参考 README.md 中支持的汇编语言自己编写程序来运行。
    '''

    if len(sys.argv) < 2:
        print(help)
        sys.exit("parameter incorrect")

    if len(sys.argv) > 2 and sys.argv[2] == 'nodebug':
        DEBUG = False
    else:
        DEBUG = True

    print("starting...")

    # reg = Register_file(DS_START, CS_START, SS_START, ES_START)
    assembler = Assembler(DS_START, CS_START, SS_START, ES_START)
    exe_file = assembler.compile(sys.argv[1])
    memory = Memory(MEMORY_SIZE, SEGMENT_SIZE)
    memory.load(exe_file)  # load code segment

    # cache = Cache_memory(CACHE_SIZE)
    # cache.space = memory.space[reg.CS:(reg.CS+SEGMENT_SIZE)]

    BIU = bus_interface_unit.bus_interface_unit(INSTRUCTION_QUEUE_SIZE,
                                                exe_file, memory)
    EU = execution_unit.execution_unit(BIU)

    cpu = CPU(BIU, EU)
    print("CPU initialized successfully.")

    while not cpu.check_done():
        cpu.iterate(debug=DEBUG)
    cpu.print_end_state()
Exemple #4
0
program = Assembler()

filename = input("\nEnter the input file name: ")
file_out = input("Enter the output file name: ")

ascii = [
    "Assembling...\n\n"
    "	   .-\"\"-.",
    "	  /[] _ _\\",
    "	 _|_o_LII|_",
    "	/ | ==== | \\ 	BEEP BOOP",
    "	|_| ==== |_|	BLOP BLEEP",
    "	 ||  ||  ||	BOOP!",
    "	 ||LI  o ||",
    "	 ||'----'||",
    "	/__|    |__\\"
]

try:
    file = open(filename)
    code = file.readlines()
    output = program.compile(code)
    output_file = open(file_out, 'w')
    for line in output:
        output_file.write("%s\n" % line)
    for line in ascii:
        print(line)
    print("\nAssembly successful!")
except Exception as e:
    print(str(e))