Print Procs
WriteInstance:
PROC [convData: ConvData, rope:
ROPE] ~ {
tNode: TNode ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
IF Rope.Length[rope]<lineLength THEN TiogaFileOps.SetContents[tNode, rope]
ELSE {
index, index2: INT;
UNTIL index2>lineLength
DO
index ← index2;
index2 ← Rope.Index[rope, index+1, sep];
ENDLOOP;
TiogaFileOps.SetContents[tNode, Rope.Substr[rope, 0, index]];
WriteInstance[convData, Rope.Concat["+", Rope.Substr[rope, index+1]]];
};
};
WireId:
PROC [convData: ConvData, wire: FlatWire]
RETURNS [id:
ROPE] ~ {
found: BOOL;
value: HashTable.Value;
[found, value] ← HashTable.Fetch[convData.wTable, wire];
IF found THEN RETURN [NARROW[value, ROPE]];
id ← NextInstanceId[convData];
[] ← HashTable.Insert[convData.wTable, wire, id];
Comment[convData, Rope.Cat[id, ": ", CoreFlat.WirePathRope[convData.rootCell, wire^]]];
};
NextInstanceId:
PROC [convData: ConvData]
RETURNS [id:
ROPE] ~ {
convData.nextId ← convData.nextId+1;
id ← Convert.RopeFromCard[from: convData.nextId, showRadix: FALSE];
id ← Rope.Concat[id, " "];
};
RealToRope:
PROC [r:
REAL, m:
REAL ← 1.0]
RETURNS [rope:
ROPE] ~ {
c: REAL ← 1.0;
r ← r*m;
IF r=0.0 THEN RETURN["0 "];
FOR x:
REAL ←
ABS[r], x*1000.0
UNTIL x>=1.0
DO
c ← c/1000.0;
ENDLOOP;
FOR x:
REAL ←
ABS[r], x/1000.0
UNTIL x<1000.0
DO
c ← c*1000.0;
ENDLOOP;
rope ← Rope.Concat[Convert.RopeFromReal[r/c],
SELECT c
FROM
1e12 => "T ",
1e09 => "G ",
1e06 => "MEG ",
1e03 => "K ",
1e00 => " ",
1e-3 => "M ",
1e-6 => "U ",
1e-9 => "N ",
1e-12 => "P ",
1e-15 => "F ",
ENDCASE => ERROR]; -- Value outside of range...
};
Comment:
PROC [convData: ConvData, comment:
ROPE] ~ {
tNode: TNode ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
TiogaFileOps.SetContents[tNode, Rope.Concat["* ", comment]];
};
Resistor:
PROC [convData: ConvData, n1, n2: FlatWire, value:
REAL, tc1, tc2:
REAL ← 0.0] ~ {
res: ROPE ← Rope.Concat[base: "R", rest: NextInstanceId[convData]];
res ← Rope.Cat[res, WireId[convData, n1], WireId[convData, n2]];
res ← Rope.Concat[res, RealToRope[value, kilo]];
IF tc1#0.0 OR tc2#0.0 THEN res ← Rope.Cat[res, " TC=", RealToRope[tc1], ",", RealToRope[tc2]];
WriteInstance[convData, res];
};
Capacitor:
PROC [convData: ConvData, n1, n2: FlatWire, value:
REAL, incond:
REAL ← 0.0] ~ {
cap: ROPE ← Rope.Concat[base: "C", rest: NextInstanceId[convData]];
cap ← Rope.Cat[cap, WireId[convData, n1], WireId[convData, n2]];
cap ← Rope.Concat[cap, RealToRope[value, pico]];
IF incond#0.0 THEN cap ← Rope.Cat[cap, " IC=", RealToRope[incond]];
WriteInstance[convData, cap]
};
Inductor:
PROC [convData: ConvData, n1, n2: FlatWire, value:
REAL, incond:
REAL ← 0.0] ~ {
ind: ROPE ← Rope.Concat[base: "L", rest: NextInstanceId[convData]];
ind ← Rope.Cat[ind, WireId[convData, n1], WireId[convData, n2]];
ind ← Rope.Concat[ind, RealToRope[value, micro]];
IF incond#0.0 THEN ind ← Rope.Cat[ind, " IC=", RealToRope[incond]];
WriteInstance[convData, ind]
};
CoupledInductors:
PROC [convData: ConvData, n0, n1, n2, n3: FlatWire, l1, l2:
REAL, k:
REAL] ~ {
cind: ROPE ← Rope.Concat[base: "K", rest: NextInstanceId[convData]];
Inductor[convData, n0, n1, l1];
cind ← Rope.Cat[cind, "L", Convert.RopeFromCard[from: convData.nextId, showRadix: FALSE], " "];
Inductor[convData, n2, n3, l2];
cind ← Rope.Cat[cind, "L", Convert.RopeFromCard[from: convData.nextId, showRadix: FALSE], " "];
cind ← Rope.Concat[cind, RealToRope[k]];
WriteInstance[convData, cind]
};
LosslessLine:
PROC [convData: ConvData, n0, n1, n2, n3: FlatWire, z0:
REAL, td:
REAL] ~ {
lline: ROPE ← Rope.Concat[base: "T", rest: NextInstanceId[convData]];
lline ← Rope.Cat[lline, WireId[convData, n0], WireId[convData, n1]];
lline ← Rope.Cat[lline, WireId[convData, n2], WireId[convData, n3]];
lline ← Rope.Cat[lline, "Z0=", RealToRope[z0, kilo], "TD=", RealToRope[td, nano]];
WriteInstance[convData, lline]
};
Vccs:
PROC [convData: ConvData, n0, n1, n2, n3: FlatWire, value:
REAL] ~ {
lsource: ROPE ← Rope.Concat[base: "G", rest: NextInstanceId[convData]];
lsource ← Rope.Cat[lsource, WireId[convData, n0], WireId[convData, n1]];
lsource ← Rope.Cat[lsource, WireId[convData, n2], WireId[convData, n3]];
lsource ← Rope.Concat[lsource, RealToRope[value]];
WriteInstance[convData, lsource]
};
Vcvs:
PROC [convData: ConvData, n0, n1, n2, n3: FlatWire, value:
REAL] ~ {
lsource: ROPE ← Rope.Concat[base: "E", rest: NextInstanceId[convData]];
lsource ← Rope.Cat[lsource, WireId[convData, n0], WireId[convData, n1]];
lsource ← Rope.Cat[lsource, WireId[convData, n2], WireId[convData, n3]];
lsource ← Rope.Concat[lsource, RealToRope[value]];
WriteInstance[convData, lsource]
};
Cccs:
PROC [convData: ConvData, n0, n1, n2, n3: FlatWire, value:
REAL] ~ {
lsource: ROPE ← Rope.Concat[base: "F", rest: NextInstanceId[convData]];
lsource ← Rope.Cat[lsource, WireId[convData, n0], WireId[convData, n1]];
VSource[convData, n2, n3];
lsource ← Rope.Cat[lsource, "V", Convert.RopeFromCard[from: convData.nextId, showRadix: FALSE], " "];
lsource ← Rope.Concat[lsource, RealToRope[value]];
WriteInstance[convData, lsource]
};
Ccvs:
PROC [convData: ConvData, n0, n1, n2, n3: FlatWire, value:
REAL] ~ {
lsource: ROPE ← Rope.Concat[base: "H", rest: NextInstanceId[convData]];
lsource ← Rope.Cat[lsource, WireId[convData, n0], WireId[convData, n1]];
VSource[convData, n2, n3];
lsource ← Rope.Cat[lsource, "V", Convert.RopeFromCard[from: convData.nextId, showRadix: FALSE], " "];
lsource ← Rope.Concat[lsource, RealToRope[value]];
WriteInstance[convData, lsource]
};
Diode:
PROC [convData: ConvData, n1, n2: FlatWire, model:
ROPE, area:
REAL] ~ {
diode: ROPE ← Rope.Concat[base: "D", rest: NextInstanceId[convData]];
diode ← Rope.Cat[diode, WireId[convData, n1], WireId[convData, n2]];
diode ← Rope.Concat[diode, model];
diode ← Rope.Concat[diode, RealToRope[area, pico]];
WriteInstance[convData, diode]
};
VSource:
PROC [convData: ConvData, n1, n2: FlatWire, dc:
REAL ← 0.0] ~ {
vs: ROPE ← Rope.Concat[base: "V", rest: NextInstanceId[convData]];
vs ← Rope.Cat[vs, WireId[convData, n1], WireId[convData, n2]];
IF dc#0.0 THEN vs ← Rope.Cat[vs, " DC ", RealToRope[dc]];
WriteInstance[convData, vs]
};
ISource:
PROC [convData: ConvData, n1, n2: FlatWire, ma:
REAL ← 0.0] ~ {
is: ROPE ← Rope.Concat[base: "I", rest: NextInstanceId[convData]];
is ← Rope.Cat[is, WireId[convData, n1], WireId[convData, n2]];
IF ma#0.0 THEN is ← Rope.Cat[is, " DC ", RealToRope[ma, mili]];
WriteInstance[convData, is]
};
PulseVS:
PROC [convData: ConvData, n1, n2: FlatWire, v1, v2, td, tr, tf, pw, per:
REAL ← 0.0] ~ {
vs: ROPE ← Rope.Concat[base: "V", rest: NextInstanceId[convData]];
vs ← Rope.Cat[vs, WireId[convData, n1], WireId[convData, n2]];
vs ← Rope.Cat[vs, "PULSE(", RealToRope[v1], RealToRope[v2]];
vs ← Rope.Cat[vs, RealToRope[td, nano], RealToRope[tr, nano], RealToRope[tf, nano]];
vs ← Rope.Cat[vs, RealToRope[pw, nano], RealToRope[per, nano], ")"];
WriteInstance[convData, vs]
};
MOSFet:
PROC [convData: ConvData, gate, drain, source, bulk: FlatWire, model:
ROPE, l, w, ad, as:
REAL] ~ {
mos: ROPE ← Rope.Concat[base: "M", rest: NextInstanceId[convData]];
mos ← Rope.Cat[mos, WireId[convData, drain], WireId[convData, gate], WireId[convData, source], WireId[convData, bulk]];
mos ← Rope.Concat[mos, model];
mos ← Rope.Cat[mos, " L=", RealToRope[l, micro], " W=", RealToRope[w, micro]];
IF ad#0.0 OR as#0.0 THEN mos ← Rope.Cat[mos, "AD=", RealToRope[ad, pico], " AS=", RealToRope[as, pico]];
WriteInstance[convData, mos]
};
PutHeader:
PROC [convData: ConvData, outputFile:
ROPE] ~ {
node: TNode;
vddWire, gndWire: FlatWire;
node0: ROPE ← "0 ";
TiogaFileOps.SetStyle[convData.rootNode, "Cedar"];
node ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
Comment[convData, CoreOps.GetCellTypeName[convData.rootCell]];
establish the power through the Circuit, and set Gnd to node # 0
vddWire ← NEW[CoreFlat.FlatWireRec ← CoreFlat.ParseWirePath[convData.rootCell, vddName]];
gndWire ← NEW[CoreFlat.FlatWireRec ← CoreFlat.ParseWirePath[convData.rootCell, gndName]];
[] ← HashTable.Insert[convData.wTable, gndWire, node0];
VSource[convData, vddWire, gndWire, 5.0];
};
PutEnd:
PROC [convData: ConvData, outputFile:
ROPE] ~ {
node: TNode;
IF convData.initList#
NIL
THEN {
node ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
TiogaFileOps.SetContents[node, Rope.Concat[".IC ", convData.initList]];
};
node ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
TiogaFileOps.SetContents[node, Rope.Concat[".PRINT TRAN ", convData.printList]];
node ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
TiogaFileOps.SetContents[node, Rope.Concat[".TRAN ", convData.tranList]];
node ← TiogaFileOps.InsertAsLastChild[convData.rootNode];
TiogaFileOps.SetContents[node, ".END"];
TiogaFileOps.Store[convData.rootNode, outputFile]
};