Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6dde060

Browse filesBrowse files
authored
Merge pull request #23 from misimisi171718/main
QOL changes for developement
2 parents 116e2aa + 13328d6 commit 6dde060
Copy full SHA for 6dde060

File tree

Expand file treeCollapse file tree

8 files changed

+91
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+91
-3
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Usage: v2f [options] <files..>
1717
1818
Options:
1919
-v, --verbose
20+
-d --debug Generate debug information. (A graph of the output circuit.)
2021
-o, --output <file> File to output the compiled blueprint to.
2122
-m, --modules <names...> Verilog modules to output blueprint for. (defaults to all).
2223
-f, --files <files...> List of Verilog files to compile. (only has to be explicitly specified after -m).
Collapse file

‎src/generateCircuitGraph.ts‎

Copy file name to clipboard
+64Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Entity } from "./entities/Entity.js";
2+
import { rm, writeFile } from "fs";
3+
import { Constant } from "./entities/Constant.js";
4+
import { Arithmetic } from "./entities/Arithmetic.js";
5+
import { Decider } from "./entities/Decider.js";
6+
import { Pole } from "./entities/Pole.js";
7+
import { exec } from "child_process";
8+
import { logger } from "./logger.js";
9+
10+
function genLabel(comb:Entity):string {
11+
if(comb instanceof Constant) {
12+
let data = "";
13+
comb.params.forEach((d)=>{
14+
data += d.signal.name+d.count+"\n";
15+
});
16+
return `${comb.id} [label="constant\n${data}",shape="cylinder"]\n`
17+
} else if(comb instanceof Arithmetic) {
18+
let first = comb.params.first_constant ?? comb.params.first_signal.name;
19+
let second = comb.params.second_constant ?? comb.params.second_signal.name;
20+
return `${comb.id} [label="${first} ${comb.params.operation} ${second}\n${comb.params.output_signal.name}",shape="box"]\n`
21+
} else if(comb instanceof Decider) {
22+
let first = comb.params.first_signal.name;
23+
let second = comb.params.constant ?? comb.params.second_signal.name;
24+
let out = comb.params.output_signal.name + (comb.params.copy_count_from_input ? " copy" : "");
25+
return `${comb.id} [label="${first} ${comb.params.comparator} ${second}\n${out}",shape="ellipse"]\n`
26+
} else if(comb instanceof Pole) {
27+
return `${comb.id} [label="pole",shape="diamond"]\n`
28+
}
29+
throw Error("unreachable")
30+
}
31+
32+
33+
export function generateCircuitGraph(combs:Entity[],outFileName:string) {
34+
let gv =
35+
`digraph {
36+
rankdir="LR"`;
37+
for (const comb of combs) {
38+
39+
gv += genLabel(comb);
40+
41+
comb.output?.red?.points?.forEach((e)=>{
42+
if(e.entity === comb)
43+
return;
44+
if(e.type == 2)
45+
return;
46+
gv+=`${comb.id}->${e.entity.id}[color=red]\n`
47+
});
48+
comb.output?.green?.points?.forEach((e)=>{
49+
if(e.entity === comb)
50+
return;
51+
if(e.type == 2)
52+
return;
53+
gv+=`${comb.id}->${e.entity.id}[color=green]\n`
54+
});
55+
}
56+
gv += "}\n";
57+
writeFile("tmp.gv",gv,async(e)=>{
58+
exec(`dot -Tsvg -o ${outFileName} tmp.gv`,(err,stdout,stderr)=>{
59+
if(err)
60+
logger.error("failed to generate graph");
61+
rm("tmp.gv",()=>{});
62+
});
63+
});
64+
}
Collapse file

‎src/main.ts‎

Copy file name to clipboardExpand all lines: src/main.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { genNetlist } from "./yosys.js";
1616
.arguments("<files..>")
1717
.helpOption("-h, --help", "Display this information.")
1818
.option("-v, --verbose")
19+
.option("-d, --debug","Generate debug information. (A graph of the output circuit.)")
1920
.option("-s, --seed <seed>", "Specify a seed for the layout generation.")
2021
.option("-o, --output <file>", "File to output the compiled blueprint to.")
2122
.option("-m, --modules <names...>", "Verilog modules to output blueprint for. (defaults to all).")
Collapse file

‎src/optimization/opt_const.ts‎

Copy file name to clipboardExpand all lines: src/optimization/opt_const.ts
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { Color, each, Entity, isSpecial } from "../entities/Entity.js";
99
import { Network } from "./nets.js";
1010
import { options } from "../options.js";
1111

12+
//returns the number of constant combinators with a given signal on the given network
13+
//return null if there are active writers or in there is an input
1214
function constNetwork(net: Network, s: SignalID) {
1315
if (!net || !net.signals.has(s)) return 0;
1416

@@ -74,6 +76,7 @@ function flipOperator(op: ComparatorString) {
7476
return op;
7577
}
7678

79+
//constant folding
7780
export function opt_const(entities: Entity[]) {
7881
if (options.verbose) logger.log("Running opt_const");
7982

@@ -87,26 +90,28 @@ export function opt_const(entities: Entity[]) {
8790
const rNet = e.input.red;
8891
const gNet = e.input.green;
8992

90-
function del() {
93+
function del() { //delete current entity
9194
e.delete();
9295
entities.splice(entities.indexOf(e), 1);
9396
i--;
9497
deleted++;
9598
}
96-
function delN(s: SignalID) {
99+
function delN(s: SignalID) { //disconnect connection if the signal type is not present
97100
if (rNet && !rNet.signals.has(s)) e.delCon(e.input, Color.Red);
98101
if (gNet && !gNet.signals.has(s)) e.delCon(e.input, Color.Green);
99102
}
100103

101104
// let signals = new Set([...rNet.signals, ...gNet.signals]);
102105

103106
if (e instanceof Constant) {
107+
//delete constant combinator with no output
104108
if (e.params.every(x => x.count == 0)) {
105109
del();
106110
}
107111
} else if (e instanceof Arithmetic) {
108112
// TODO: don't skip each
109113
if (e.params.first_signal && e.params.first_signal !== each) {
114+
//move constant input into combinator for the first signal
110115
let rVal = constNetwork(rNet, e.params.first_signal);
111116
let gVal = constNetwork(gNet, e.params.first_signal);
112117

@@ -120,6 +125,7 @@ export function opt_const(entities: Entity[]) {
120125
}
121126

122127
if (e.params.second_signal && e.params.second_signal !== each) {
128+
//move constant input into combinator for the second signal
123129
let rVal = constNetwork(rNet, e.params.second_signal);
124130
let gVal = constNetwork(gNet, e.params.second_signal);
125131

@@ -133,6 +139,8 @@ export function opt_const(entities: Entity[]) {
133139
}
134140

135141
if (e.params.first_constant !== undefined && e.params.second_constant !== undefined) {
142+
//if combinator has no active parameter then replace it with a constant combinator
143+
//or nothing if the result is zero
136144
if(isSpecial(e.params.output_signal)) {
137145
debugger;
138146
continue;
@@ -158,12 +166,14 @@ export function opt_const(entities: Entity[]) {
158166
}
159167
} else if (e instanceof Decider) {
160168
if (e.params.copy_count_from_input) {
169+
//if copy input count is checked skip al other optimizations
161170
if(isSpecial(e.params.output_signal)) {
162171
// debugger;
163172
} else {
164173
let rVal = constNetwork(rNet, e.params.output_signal);
165174
let gVal = constNetwork(gNet, e.params.output_signal);
166175

176+
//delete if the out put signal doesn't exist on the network
167177
if (rVal !== null && gVal !== null && rVal + gVal == 0) {
168178
del();
169179
}
@@ -177,6 +187,7 @@ export function opt_const(entities: Entity[]) {
177187
let rVal = constNetwork(rNet, e.params.second_signal);
178188
let gVal = constNetwork(gNet, e.params.second_signal);
179189

190+
//move constants inside combinator
180191
if (rVal !== null && gVal !== null) {
181192
e.params.second_signal = undefined;
182193
e.params.constant = rVal + gVal;
@@ -192,6 +203,7 @@ export function opt_const(entities: Entity[]) {
192203
if (rVal === null || gVal === null) continue;
193204

194205
if (e.params.second_signal) {
206+
//if second signal is constant switch them and move it into the combinator
195207
e.params.first_signal = e.params.second_signal;
196208
e.params.second_signal = undefined;
197209
e.params.constant = rVal + gVal;
@@ -203,7 +215,7 @@ export function opt_const(entities: Entity[]) {
203215
debugger;
204216

205217
if (calcConstDecider(e, rVal + gVal)) {
206-
// replace with passthrough
218+
//TODO: replace with passthrough
207219
debugger;
208220
} else {
209221
del();
Collapse file

‎src/optimization/opt_merge.ts‎

Copy file name to clipboardExpand all lines: src/optimization/opt_merge.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function eq(a: Entity, b: Entity) {
2626
return false;
2727
}
2828

29+
//combine combinators that have the have the same input do the same thing and have no output neighbors
2930
export function opt_merge(entities: Entity[]) {
3031
if (options.verbose) logger.log("Running opt_merge");
3132

@@ -35,6 +36,7 @@ export function opt_merge(entities: Entity[]) {
3536
for (const e of entities) {
3637
if (e instanceof Pole) continue;
3738

39+
//collet entities grouped by input networks
3840
let key = `${e.input.red?.id ?? 0}_${e.input.green?.id ?? 0}`;
3941

4042
if (groups.has(key)) {
@@ -62,6 +64,7 @@ export function opt_merge(entities: Entity[]) {
6264
let orNet = other.output.red;
6365
let ogNet = other.output.green;
6466

67+
//check if there are other writers on the output networks
6568
let doMerge = false;
6669
if (!arNet && !orNet) { // only green output
6770
doMerge = !agNet.hasOtherWriters(entity.output) && !ogNet.hasOtherWriters(other.output);
Collapse file

‎src/optimization/opt_transform.ts‎

Copy file name to clipboardExpand all lines: src/optimization/opt_transform.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function opt_transform(entities: Entity[]) {
4848

4949
// TODO: allow for multiple differnt colored outputs when inNet.points.size == 2
5050
if ((!!e.input.red == !!e.input.green) || (!!e.output.red == !!e.output.green)) {
51+
//skip if both input or both outputs are set
5152
filter1++;
5253
continue;
5354
}
@@ -71,6 +72,7 @@ export function opt_transform(entities: Entity[]) {
7172
} else if (!outNet.hasOtherColor()) {
7273
newColor = inNet.color; // outNet can be changed to other color
7374
} else {
75+
//skip if other combinators on the network other color connected have the other color connected
7476
filter3++;
7577
continue;
7678
}
Collapse file

‎src/options.ts‎

Copy file name to clipboardExpand all lines: src/options.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export let options: {
22
verbose: boolean;
3+
debug: boolean;
34
seed?: string;
45
output?: string;
56
modules?: string[];
@@ -8,6 +9,7 @@ export let options: {
89
generator: "annealing" | "matrix";
910
} = {
1011
verbose: false,
12+
debug: false,
1113
seed: Math.random().toString(),
1214
generator: "annealing"
1315
};
Collapse file

‎src/transformer.ts‎

Copy file name to clipboardExpand all lines: src/transformer.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { options } from "./options.js";
1010

1111
import { runAnnealing } from "./layout/annealing.js";
1212
import { createMatrixLayout } from "./layout/netMatrix.js";
13+
import { generateCircuitGraph } from "./generateCircuitGraph.js";
1314

1415
const generators = {
1516
"annealing": runAnnealing,
@@ -56,6 +57,8 @@ export function transform(nodes: Node[]) {
5657
combs[i].id = i + 1;
5758
}
5859

60+
if(options.debug) generateCircuitGraph(combs,"circuit.svg");
61+
5962
generators[options.generator](combs, ports);
6063

6164
// assign entity id's

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.