<s> import empty <EOL> from opcodes import * <EOL> from memory_map import mem_map <EOL> from branching_flags import * <EOL> bench_dir = "<STR_LIT>" <EOL> bench_file = "<STR_LIT>" <EOL> bench_name = bench_dir + "<STR_LIT:/>" + bench_file <EOL> SIMD_bench_name = bench_dir + "<STR_LIT:/>" + "<STR_LIT>" + bench_file <EOL> empty = empty . assemble_all ( ) <EOL> def assemble_PC ( ) : <EOL> PC = empty [ "<STR_LIT>" ] <EOL> PC . file_name = bench_name <EOL> return PC <EOL> def assemble_A ( ) : <EOL> A = empty [ "<STR_LIT:A>" ] <EOL> A . file_name = bench_name <EOL> A . P ( "<STR_LIT>" , mem_map [ "<STR_LIT:A>" ] [ "<STR_LIT>" ] ) <EOL> A . A ( <NUM_LIT:0> ) <EOL> A . L ( <NUM_LIT:0> ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( - <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:1> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( - <NUM_LIT:2> ) <EOL> A . L ( <NUM_LIT:0> ) , A . N ( "<STR_LIT>" ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> A . L ( <NUM_LIT:0> ) <EOL> A . L ( <NUM_LIT:0> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( - <NUM_LIT:1> ) <EOL> A . L ( <NUM_LIT:0> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:0> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:0> ) , A . N ( "<STR_LIT>" ) <EOL> A . L ( <NUM_LIT:0> ) , A . N ( "<STR_LIT>" ) <EOL> return A <EOL> def assemble_B ( ) : <EOL> B = empty [ "<STR_LIT:B>" ] <EOL> B . file_name = bench_name <EOL> B . P ( "<STR_LIT>" , mem_map [ "<STR_LIT:B>" ] [ "<STR_LIT>" ] ) <EOL> B . P ( "<STR_LIT>" , mem_map [ "<STR_LIT:B>" ] [ "<STR_LIT>" ] , write_addr = mem_map [ "<STR_LIT:H>" ] [ "<STR_LIT>" ] ) <EOL> B . A ( <NUM_LIT:0> ) <EOL> B . L ( <NUM_LIT:0> ) <EOL> B . L ( <NUM_LIT:0> ) , B . N ( "<STR_LIT>" ) <EOL> B . L ( <NUM_LIT> ) , B . N ( "<STR_LIT>" ) <EOL> B . L ( - <NUM_LIT:2> ) <EOL> B . L ( <NUM_LIT:0> ) , B . N ( "<STR_LIT>" ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> B . L ( <NUM_LIT:0> ) <EOL> B . L ( <NUM_LIT> ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> B . L ( <NUM_LIT:0> ) <EOL> B . L ( <NUM_LIT> ) <EOL> B . L ( <NUM_LIT> ) <EOL> B . L ( <NUM_LIT> ) <EOL> B . L ( <NUM_LIT> ) <EOL> B . L ( <NUM_LIT:64> ) <EOL> B . L ( <NUM_LIT:32> ) <EOL> B . L ( <NUM_LIT:16> ) <EOL> B . L ( <NUM_LIT:8> ) <EOL> B . L ( <NUM_LIT:4> ) <EOL> B . L ( <NUM_LIT:2> ) <EOL> B . L ( <NUM_LIT:1> ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> B . L ( <NUM_LIT:0> ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> B . L ( <NUM_LIT:1> ) <EOL> B . L ( - <NUM_LIT:1> ) <EOL> B . L ( <NUM_LIT:0> ) , B . N ( "<STR_LIT>" ) <EOL> B . L ( <NUM_LIT:0> ) , B . N ( "<STR_LIT>" ) <EOL> return B <EOL> def assemble_I ( PC , A , B ) : <EOL> I = empty [ "<STR_LIT:I>" ] <EOL> I . file_name = bench_name <EOL> I . A ( <NUM_LIT:1> ) <EOL> base_addr = mem_map [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> I . P ( "<STR_LIT>" , None , write_addr = base_addr ) <EOL> I . P ( "<STR_LIT>" , None , write_addr = base_addr + <NUM_LIT:1> ) <EOL> I . P ( "<STR_LIT>" , None , write_addr = base_addr + <NUM_LIT:2> ) <EOL> I . P ( "<STR_LIT>" , None , write_addr = base_addr + <NUM_LIT:3> ) <EOL> base_addr = mem_map [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> I . P ( "<STR_LIT>" , None , write_addr = base_addr ) <EOL> I . P ( "<STR_LIT>" , None , write_addr = base_addr + <NUM_LIT:1> ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> I . I ( ADD , "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" ) , I . N ( "<STR_LIT>" ) <EOL> I . I ( ADD , "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> I . I ( ADD , "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , I . N ( "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( MLS , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( ADD , "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> I . I ( ADD , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) , I . JNZ ( "<STR_LIT>" , None , "<STR_LIT>" ) <EOL> I . NOP ( ) , I . N ( "<STR_LIT:end>" ) , I . JMP ( "<STR_LIT:end>" , "<STR_LIT>" ) <EOL> I . resolve_forward_jumps ( ) <EOL> read_PO = ( mem_map [ "<STR_LIT:B>" ] [ "<STR_LIT>" ] - mem_map [ "<STR_LIT:B>" ] [ "<STR_LIT>" ] + B . R ( "<STR_LIT>" ) ) & <NUM_LIT> <EOL> write_PO = ( mem_map [ "<STR_LIT:H>" ] [ "<STR_LIT>" ] + mem_map [ "<STR_LIT:H>" ] [ "<STR_LIT>" ] - mem_map [ "<STR_LIT:H>" ] [ "<STR_LIT>" ] + A . W ( "<STR_LIT>" ) ) & <NUM_LIT> <EOL> PO = ( <NUM_LIT:1> << <NUM_LIT> ) | ( <NUM_LIT:1> << <NUM_LIT:32> ) | ( write_PO << <NUM_LIT:20> ) | read_PO <EOL> B . A ( B . R ( "<STR_LIT>" ) ) <EOL> B . L ( PO ) <EOL> return I <EOL> def assemble_XDO ( ) : <EOL> ADO , BDO , DDO = empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] <EOL> ADO . file_name = bench_name <EOL> BDO . file_name = bench_name <EOL> DDO . file_name = bench_name <EOL> return ADO , BDO , DDO <EOL> def assemble_XPO ( ) : <EOL> APO , BPO , DPO = empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] <EOL> APO . file_name = bench_name <EOL> BPO . file_name = bench_name <EOL> DPO . file_name = bench_name <EOL> return APO , BPO , DPO <EOL> def assemble_XIN ( ) : <EOL> AIN , BIN , DIN = empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] <EOL> AIN . file_name = bench_name <EOL> BIN . file_name = bench_name <EOL> DIN . file_name = bench_name <EOL> return AIN , BIN , DIN <EOL> def assemble_branches ( ) : <EOL> BO , BD , BC , BP , BPE = empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] , empty [ "<STR_LIT>" ] <EOL> BO . file_name = bench_name <EOL> BD . file_name = bench_name <EOL> BC . file_name = bench_name <EOL> BP . file_name = bench_name <EOL> BPE . file_name = bench_name <EOL> return BO , BD , BC , BP , BPE <EOL> def assemble_all ( ) : <EOL> PC = assemble_PC ( ) <EOL> A = assemble_A ( ) <EOL> B = assemble_B ( ) <EOL> I = assemble_I ( PC , A , B ) <EOL> ADO , BDO , DDO = assemble_XDO ( ) <EOL> APO , BPO , DPO = assemble_XPO ( ) <EOL> AIN , BIN , DIN = assemble_XIN ( ) <EOL> BO , BD , BC , BP , BPE = assemble_branches ( ) <EOL> hailstone = { "<STR_LIT>" : PC , "<STR_LIT:A>" : A , "<STR_LIT:B>" : B , "<STR_LIT:I>" : I , <EOL> "<STR_LIT>" : ADO , "<STR_LIT>" : BDO , "<STR_LIT>" : DDO , <EOL> "<STR_LIT>" : APO , "<STR_LIT>" : BPO , "<STR_LIT>" : DPO , <EOL> "<STR_LIT>" : AIN , "<STR_LIT>" : BIN , "<STR_LIT>" : DIN , <EOL> "<STR_LIT>" : BO , "<STR_LIT>" : BD , "<STR_LIT>" : BC , "<STR_LIT>" : BP , "<STR_LIT>" : BPE } <EOL> return hailstone <EOL> def dump_all ( program ) : <EOL> for memory in program . values ( ) : <EOL> memory . file_dump ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> program = assemble_all ( ) <EOL> dump_all ( program ) </s>
