ReadContextFromAlpsFile:
PUBLIC PROC[fileName:
ROPE]
RETURNS [context: Context] = {
symTab: SymTab.Ref ← CDExpr.CombineTabs[
winner: CDExpr.ReadFile[fileName],
loser: CDExpr.ReadFile[Rope.Cat[FS.GetDefaultWDir[], "AlpsDefaultParameters.alps"]]]; -- turn a xxx.alps file into a symtab
found: BOOL; rope: ROPE; ref: REF; int: INT; bool: BOOL;
context ← NEW[ContextRec];
Output["\nInterpreting parameters from description file ", fileName, " ...\n"];
[found, context.tileset] ← CDExpr.FetchRope[symTab, "TileSet"];
IF ~found THEN {Output["TileSet must be supplied!\n"]; ERROR};
[found, ref] ← CDExpr.FetchRef[symTab, "TruthTableFile"];
IF found
THEN {
-- Input, Output and eventually Latches names
[found, ref] ← CDExpr.FetchRef[symTab, "Inputs"];
IF ~found THEN {Output["Name of inputs must be supplied!\n"]; ERROR};
context.inputNames ← RefToListOfRopes[ref];
[found, ref] ← CDExpr.FetchRef[symTab, "Outputs"];
IF ~found THEN {Output["Name of outputs must be supplied!\n"]; ERROR};
context.outputNames ← RefToListOfRopes[ref];
-- Reading truth table
[found, rope] ← CDExpr.FetchRope[symTab, "TruthTableFile"];
IF ~found THEN {Output["TruthTableFile must be supplied!\n"]; ERROR};
Output["Reading TruthTable in ", rope, " ...\n"];
context.table ← AlpsBool.ReadPLAFile[rope, context.inputNames, context.outputNames];
Output["... TruthTable in ", rope, " read!\n"];
FOR list:
LIST
OF
ROPE ← context.inputNames, list.rest
WHILE list#
NIL
DO
latch: ROPE ← list.first;
input: AlpsBool.VarNb ← 0;
output: AlpsBool.OutputRef ← NIL;
FOR i: AlpsBool.VarNb
IN [1 .. context.table.size)
DO
IF Rope.Equal[context.table[i].name, latch] THEN {input ← i; EXIT};
ENDLOOP;
IF input=0 THEN ERROR;
FOR outs:
LIST
OF AlpsBool.OutputRef ← context.table.outputs, outs.rest
WHILE outs#
NIL
DO
IF Rope.Equal[outs.first.name, latch] THEN {output ← outs.first; EXIT};
ENDLOOP;
IF output#
NIL
THEN {
Output["Latch (both input and output): ", latch, "\n"];
output.type ← latch; output.fedBackInput ← input; context.table[input].fromOutput ← output;
};
ENDLOOP;
} ELSE {
[found, ref] ← CDExpr.FetchRef[symTab, "AlpsTable"];
IF ~found THEN {Output["Either TruthTableFile or AlpsTable must be supplied\n"]; ERROR};
Output["Getting equations from AlpsTable\n"];
context.table ← NARROW[ref, REF AlpsBool.TableOfVariables]^;
};
Reading layout control parameters
[found, int] ← CDExpr.FetchInt[symTab, "DistanceBetweenGlue"];
IF found THEN context.distanceBetweenGlue ← int ELSE {Output["DistanceBetweenGlue must be INT"]; ERROR};
[found, int] ← CDExpr.FetchInt[symTab, "DistanceBetweenContacts"];
IF found THEN context.distanceBetweenContacts ← int ELSE {Output["DistanceBetweenContacts must be INT"]; ERROR};
[found, bool] ← CDExpr.FetchBool[symTab, "Optimize"];
IF found THEN context.optimize ← bool ELSE {Output["Optimize must be BOOL"]; ERROR};
[found, bool] ← CDExpr.FetchBool[symTab, "Debug"];
IF found THEN context.debug ← bool ELSE {Output["Debug must be BOOL"]; ERROR};
};
AlpsCellFromContext:
PUBLIC
PROC [context: Context, design:
CD.Design]
RETURNS [obj:
CD.ObPtr] = {
Including if necessary tileset
IF CDDirectory.Fetch[design, context.tileset].found
THEN Output[context.tileset, " already present in design\n"]
ELSE
BEGIN
to: CD.Design ← design;
Check:
PROC [design:
CD.Design]
RETURNS [ok:
BOOL] =
BEGIN
ok ← design.technology=to.technology;
IF ~ok THEN Output["Technology mismatch: includee is ", design.technology.name, "\n"];
END;
from: CD.Design ← CDIO.ReadDesign[context.tileset, Check];
Output["Design ", context.tileset, " read and included in the design"];
[] ← CDExtras.MergeIn[design: to, from: from, name: context.tileset];
END;
Printing info
BEGIN
input, aux, output, latch: INT;
[input, aux, output, latch] ← AlpsBool.NbOfVars[context.table];
Output[" Input: ", Convert.RopeFromInt[input], " Aux: ", Convert.RopeFromInt[aux], " Output: ", Rope.Cat[Convert.RopeFromInt[output], " Latch: ", Convert.RopeFromInt[latch], "\n"]];
END;
Removing auxiliary variables
BEGIN
ok: BOOL ← TRUE;
table: AlpsBool.TableOfVariables ← context.table;
Output["Removing auxiliary variables\n"];
WHILE ok
DO
newTable: AlpsBool.TableOfVariables;
Output["Removing ...\n"];
[newTable, ok] ← AlpsHeur.RemoveAuxVar[table, AlpsHeur.AlwaysBetter, 0];
IF ok THEN table ← newTable;
ENDLOOP;
context.table ← table;
END;
Permutations
IF context.optimize
THEN {
context.table ← AlpsHeur.BestPermuteInfinitely[context.table, AlpsHeur.ImproveSizeAndDelay];
};
RePrinting info
BEGIN
input, aux, output, latch: INT;
[input, aux, output, latch] ← AlpsBool.NbOfVars[context.table];
Output[" Input: ", Convert.RopeFromInt[input], " Aux: ", Convert.RopeFromInt[aux], " Output: ", Rope.Cat[Convert.RopeFromInt[output], " Latch: ", Convert.RopeFromInt[latch], "\n"]];
END;
Layout at last
BEGIN
alpsTileContext: AlpsTile.Context ← NEW[AlpsTile.ContextRec ← [design: design, table: context.table, distanceBetweenGlue: context.distanceBetweenGlue, distanceBetweenContacts: context.distanceBetweenContacts, debug: context.debug]];
obj ← AlpsPWGen.TableToLayout[alpsTileContext];
Output["Done!"];
END;
};