From 25f519b977b5d520cf5af24a7f45ef05a793e741 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Mon, 21 Jul 2025 18:47:44 +1000 Subject: [PATCH] In /scripts/fets.py, /scripts/gates.py, /scripts/circuits.py give the output file explicitly rather than using stdout, add some basic progress diagnostics on stdout, in /scripts/circuit.py in latch templates put gates first to speed search --- 8085/Makefile | 6 +- scripts/circuits.py | 168 +++++++++++++++++++++++++++----------------- scripts/fets.py | 51 +++++++++----- scripts/gates.py | 71 ++++++++++++------- 4 files changed, 187 insertions(+), 109 deletions(-) diff --git a/8085/Makefile b/8085/Makefile index 7f815f5..1f8d153 100644 --- a/8085/Makefile +++ b/8085/Makefile @@ -26,13 +26,13 @@ layers_rev.png #vias2.png circuits.txt: gates.txt - ../scripts/circuits.py gates.txt GND,VCC >$@ + ../scripts/circuits.py gates.txt $@ GND,VCC gates.txt: fets.txt - ../scripts/gates.py fets.txt GND,VCC >$@ + ../scripts/gates.py fets.txt $@ GND,VCC fets.txt: nodes.txt - ../scripts/fets.py nodes.txt 1,4,5,6,7 >$@ + ../scripts/fets.py nodes.txt $@ 1,4,5,6,7 node_sizes.txt: nodes.txt ../scripts/node_sizes.py nodes.txt >$@ diff --git a/scripts/circuits.py b/scripts/circuits.py index 287c13b..dece518 100755 --- a/scripts/circuits.py +++ b/scripts/circuits.py @@ -49,10 +49,10 @@ CIRCUITS = [ # 5 = q ( [ - (SYMBOL_TYPE_FET, (1, [0, 3])), - (SYMBOL_TYPE_FET, (2, [3, 5])), (SYMBOL_TYPE_GATE, (4, [[3]])), (SYMBOL_TYPE_GATE, (5, [[4]])), + (SYMBOL_TYPE_FET, (1, [0, 3])), + (SYMBOL_TYPE_FET, (2, [3, 5])), ], [ (SYMBOL_TYPE_TG_LATCH, (0, 1, 2, 5, 4)), @@ -62,10 +62,10 @@ CIRCUITS = [ # special case of SYMBOL_TYPE_TG_LATCH where fb signal is external ( [ - (SYMBOL_TYPE_FET, (1, [0, 3])), - (SYMBOL_TYPE_FET, (2, [3, 5])), (SYMBOL_TYPE_GATE, (4, [[3]])), (SYMBOL_TYPE_GATE, (5, [[4]])), + (SYMBOL_TYPE_FET, (1, [0, 3])), + (SYMBOL_TYPE_FET, (2, [3, 5])), ], [ (SYMBOL_TYPE_TG_LATCH_FB, (0, 1, 2, 5, 4, 3)), @@ -229,15 +229,17 @@ CIRCUITS = [ ), ] -if len(sys.argv) < 3: - print(f'usage: {sys.argv[0]:s} symbols.txt net_gnd,net_vcc') +if len(sys.argv) < 4: + print(f'usage: {sys.argv[0]:s} gates.txt circuits.txt net_gnd,net_vcc') sys.exit(1) -symbols_txt = sys.argv[1] -global_nets = sys.argv[2].split(',') +gates_txt = sys.argv[1] +circuits_txt = sys.argv[2] +global_nets = sys.argv[3].split(',') +print('input') nets = {} symbols = [] -with open(symbols_txt) as fin: +with open(gates_txt) as fin: line = fin.readline() while len(line): fields = line.split() @@ -316,7 +318,10 @@ with open(symbols_txt) as fin: class Match(Exception): pass -for circuit_find, circuit_replace, circuit_internal in CIRCUITS: +print('process') +for i in range(len(CIRCUITS)): + print(i, '/', len(CIRCUITS)) + circuit_find, circuit_replace, circuit_internal = CIRCUITS[i] assert len(circuit_find) circuit_symbols = [-1] * len(circuit_find) circuit_nets = global_nets[::-1] + [None] * len(circuit_internal) @@ -463,18 +468,18 @@ for circuit_find, circuit_replace, circuit_internal in CIRCUITS: t = symbol_template[1] # template nets assert isinstance(t, tuple) - for i in range(len(symbols)): - symbol_actual = symbols[i] + for j in range(len(symbols)): + symbol_actual = symbols[j] at = symbol_actual[0] # actual type a = symbol_actual[2] # actual nets assert isinstance(a, tuple) if tt == at and len(t) == len(a): - #print('trying symbol', 0, i) - circuit_symbols[0] = i + #print('trying symbol', 0, j) + circuit_symbols[0] = j symbol_actual[0] = -1 # delete symbol during search try: match(1, (0, t, a, stack)) - #print('failed symbol', 0, i) + #print('failed symbol', 0, j) symbol_actual[0] = at # reinstate symbol on backtrack circuit_symbols[0] = -1 # not really necessary except Match: @@ -483,57 +488,92 @@ for circuit_find, circuit_replace, circuit_internal in CIRCUITS: # add new symbols for symbol_type, template in circuit_replace: - symbols.append((symbol_type, block, substitute(template))) + symbols.append([symbol_type, block, substitute(template)]) # continue search circuit_symbols = [-1] * len(circuit_find) circuit_nets = global_nets[::-1] + [None] * len(circuit_internal) -for i in range(len(symbols)): - symbol_type = symbols[i][0] - if symbol_type == SYMBOL_TYPE_FET: - [ - _, - block, - (poly_net, diff_nets), - channel, - x, - y, - mass, - r_matrix - ] = symbols[i] - print(symbol_type, block, poly_net, len(diff_nets), channel, x, y, mass) - for i in range(len(diff_nets)): - print(' ' + diff_nets[i], ' '.join([str(j) for j in r_matrix[i]])) - elif symbol_type == SYMBOL_TYPE_GATE: - [_, block, (y_net, expr)] = symbols[i] - print(symbol_type, block, y_net, len(expr)) - for i in expr: - print(' ' + ' '.join(i)) - elif symbol_type == SYMBOL_TYPE_XOR: - [_, block, (y_net, a_nets)] = symbols[i] - print(symbol_type, block, y_net, ' '.join(a_nets)) - elif symbol_type == SYMBOL_TYPE_TG_LATCH: - [_, block, (d_net, le_net, len_net, q_net, qn_net)] = symbols[i] - print(symbol_type, block, d_net, le_net, len_net, q_net, qn_net) - elif symbol_type == SYMBOL_TYPE_TG_LATCH_FB: - [_, block, (d_net, le_net, len_net, q_net, qn_net, fb_net)] = symbols[i] - print(symbol_type, block, d_net, le_net, len_net, q_net, qn_net, fb_net) - elif ( - symbol_type == SYMBOL_TYPE_SUPER or - symbol_type == SYMBOL_TYPE_NOT_SUPER - ): - [_, block, (a_net, y_net)] = symbols[i] - print(symbol_type, block, a_net, y_net) - elif ( - symbol_type == SYMBOL_TYPE_SUPER_OE or - symbol_type == SYMBOL_TYPE_NOT_SUPER_OE - ): - [_, block, (a_net, oen_net, y_net)] = symbols[i] - print(symbol_type, block, a_net, oen_net, y_net) - elif symbol_type == SYMBOL_TYPE_NOR_SUPER: - [_, block, (a_net, b_net, y_net)] = symbols[i] - print(symbol_type, block, a_net, b_net, y_net) - elif symbol_type == SYMBOL_TYPE_NOR_SUPER_HD: - [_, block, (a_net, b_net, y_net, hd_net)] = symbols[i] - print(symbol_type, block, a_net, b_net, y_net, hd_net) +print('output') +with open(circuits_txt, 'w') as fout: + for i in range(len(symbols)): + symbol_type = symbols[i][0] + if symbol_type == SYMBOL_TYPE_FET: + [ + _, + block, + (poly_net, diff_nets), + channel, + x, + y, + mass, + r_matrix + ] = symbols[i] + print( + symbol_type, + block, + poly_net, + len(diff_nets), + channel, + x, + y, + mass, + file = fout + ) + for i in range(len(diff_nets)): + print( + ' ' + diff_nets[i], + ' '.join([str(j) for j in r_matrix[i]]), + file = fout + ) + elif symbol_type == SYMBOL_TYPE_GATE: + [_, block, (y_net, expr)] = symbols[i] + print(symbol_type, block, y_net, len(expr), file = fout) + for i in expr: + print(' ' + ' '.join(i), file = fout) + elif symbol_type == SYMBOL_TYPE_XOR: + [_, block, (y_net, a_nets)] = symbols[i] + print(symbol_type, block, y_net, ' '.join(a_nets), file = fout) + elif symbol_type == SYMBOL_TYPE_TG_LATCH: + [_, block, (d_net, le_net, len_net, q_net, qn_net)] = symbols[i] + print( + symbol_type, + block, + d_net, + le_net, + len_net, + q_net, + qn_net, + file = fout + ) + elif symbol_type == SYMBOL_TYPE_TG_LATCH_FB: + [_, block, (d_net, le_net, len_net, q_net, qn_net, fb_net)] = symbols[i] + print( + symbol_type, + block, + d_net, + le_net, + len_net, + q_net, + qn_net, + fb_net, + file = fout + ) + elif ( + symbol_type == SYMBOL_TYPE_SUPER or + symbol_type == SYMBOL_TYPE_NOT_SUPER + ): + [_, block, (a_net, y_net)] = symbols[i] + print(symbol_type, block, a_net, y_net, file = fout) + elif ( + symbol_type == SYMBOL_TYPE_SUPER_OE or + symbol_type == SYMBOL_TYPE_NOT_SUPER_OE + ): + [_, block, (a_net, oen_net, y_net)] = symbols[i] + print(symbol_type, block, a_net, oen_net, y_net, file = fout) + elif symbol_type == SYMBOL_TYPE_NOR_SUPER: + [_, block, (a_net, b_net, y_net)] = symbols[i] + print(symbol_type, block, a_net, b_net, y_net, file = fout) + elif symbol_type == SYMBOL_TYPE_NOR_SUPER_HD: + [_, block, (a_net, b_net, y_net, hd_net)] = symbols[i] + print(symbol_type, block, a_net, b_net, y_net, hd_net, file = fout) diff --git a/scripts/fets.py b/scripts/fets.py index fc0521e..9bddcd2 100755 --- a/scripts/fets.py +++ b/scripts/fets.py @@ -20,16 +20,18 @@ N_SYMBOL_TYPES = 1 # numpy.uint8 #) -if len(sys.argv) < 3: +if len(sys.argv) < 4: print( - f'usage: {sys.argv[0]:s} nodes.txt blocks_colour,poly_colour,diff_colour,buried_colour,channel_colour' + f'usage: {sys.argv[0]:s} nodes.txt fets.txt blocks_colour,poly_colour,diff_colour,buried_colour,channel_colour' ) sys.exit(1) nodes_txt = sys.argv[1] +fets_txt = sys.argv[2] blocks_colour, poly_colour, diff_colour, buried_colour, channel_colour = \ - [int(i) for i in sys.argv[2].split(',')] + [int(i) for i in sys.argv[3].split(',')] diff_colours = {diff_colour, buried_colour} +print('input') with open(nodes_txt) as fin: line = fin.readline() assert len(line) @@ -161,6 +163,7 @@ def resistor_solver(image): #print('R', 1. / sum_I2, 'squares') return 1. / sum_I2 +print('process') symbols = [] image = numpy.zeros((ys, xs), numpy.uint8) for (channel, (channel_items, channel_reports)) in sorted(channels.items()): @@ -284,16 +287,32 @@ for (channel, (channel_items, channel_reports)) in sorted(channels.items()): ) ) -for ( - symbol_type, - block, - (poly_net, diff_nets), - channel, - x, - y, - mass, - r_matrix -) in symbols: - print(symbol_type, block, poly_net, len(diff_nets), channel, x, y, mass) - for i in range(len(diff_nets)): - print(' ' + diff_nets[i], ' '.join([str(j) for j in r_matrix[i]])) +print('output') +with open(fets_txt, 'w') as fout: + for ( + symbol_type, + block, + (poly_net, diff_nets), + channel, + x, + y, + mass, + r_matrix + ) in symbols: + print( + symbol_type, + block, + poly_net, + len(diff_nets), + channel, + x, + y, + mass, + file = fout + ) + for i in range(len(diff_nets)): + print( + ' ' + diff_nets[i], + ' '.join([str(j) for j in r_matrix[i]]), + file = fout + ) diff --git a/scripts/gates.py b/scripts/gates.py index 50771dc..45fecc3 100755 --- a/scripts/gates.py +++ b/scripts/gates.py @@ -7,15 +7,17 @@ SYMBOL_TYPE_FET = 0 SYMBOL_TYPE_GATE = 1 N_SYMBOL_TYPES = 2 -if len(sys.argv) < 3: - print(f'usage: {sys.argv[0]:s} symbols.txt net_gnd,net_vcc') +if len(sys.argv) < 4: + print(f'usage: {sys.argv[0]:s} fets.txt gates.txt net_gnd,net_vcc') sys.exit(1) -symbols_txt = sys.argv[1] -[net_gnd, net_vcc] = sys.argv[2].split(',') +fets_txt = sys.argv[1] +gates_txt = sys.argv[2] +[net_gnd, net_vcc] = sys.argv[3].split(',') +print('input') nets = {} symbols = [] -with open(symbols_txt) as fin: +with open(fets_txt) as fin: line = fin.readline() while len(line): fields = line.split() @@ -105,6 +107,7 @@ def follow(del_symbols, net, parent_net): finally: nets[net][0] = False +print('process') for i in range(len(symbols)): symbol_type = symbols[i][0] if symbol_type == SYMBOL_TYPE_FET: @@ -139,24 +142,40 @@ for i in range(len(symbols)): symbols[symbol1][0] = -1 symbols.append((SYMBOL_TYPE_GATE, block, (poly_net, expr))) -for i in range(len(symbols)): - symbol_type = symbols[i][0] - if symbol_type == SYMBOL_TYPE_FET: - [ - _, - block, - (poly_net, diff_nets), - channel, - x, - y, - mass, - r_matrix - ] = symbols[i] - print(symbol_type, block, poly_net, len(diff_nets), channel, x, y, mass) - for i in range(len(diff_nets)): - print(' ' + diff_nets[i], ' '.join([str(j) for j in r_matrix[i]])) - elif symbol_type == SYMBOL_TYPE_GATE: - [_, block, (y_net, expr)] = symbols[i] - print(symbol_type, block, y_net, len(expr)) - for i in expr: - print(' ' + ' '.join(i)) +print('output') +with open(gates_txt, 'w') as fout: + for i in range(len(symbols)): + symbol_type = symbols[i][0] + if symbol_type == SYMBOL_TYPE_FET: + [ + _, + block, + (poly_net, diff_nets), + channel, + x, + y, + mass, + r_matrix + ] = symbols[i] + print( + symbol_type, + block, + poly_net, + len(diff_nets), + channel, + x, + y, + mass, + file = fout + ) + for i in range(len(diff_nets)): + print( + ' ' + diff_nets[i], + ' '.join([str(j) for j in r_matrix[i]]), + file = fout + ) + elif symbol_type == SYMBOL_TYPE_GATE: + [_, block, (y_net, expr)] = symbols[i] + print(symbol_type, block, y_net, len(expr), file = fout) + for i in expr: + print(' ' + ' '.join(i), file = fout) -- 2.34.1