<> <> <> <> DIRECTORY AlpsBool, AlpsHeur, AlpsPWGen, AlpsTile, CD, CDDirectory, CDExpr, CDExtras, CDIO, Commander, Convert, FS, PW, PWAlps, Rope, SymTab, TerminalIO; PWAlpsImpl: CEDAR PROGRAM IMPORTS AlpsBool, AlpsHeur, AlpsPWGen, CDDirectory, CDExpr, CDExtras, CDIO, Convert, FS, PW, Rope, TerminalIO EXPORTS PWAlps = BEGIN OPEN PWAlps; Input: PROC [text: ROPE] RETURNS [ROPE] = {RETURN [TerminalIO.RequestRope[text]]}; Output: PROC [t1, t2, t3, t4, t5, t6: ROPE _ NIL] = {AlpsBool.Output[t1, t2, t3, t4, t5, t6]}; RefToListOfRopes: PUBLIC PROC [ref: REF] RETURNS [lropes: LIST OF ROPE] = { WITH ref SELECT FROM refListOfRef: REF LIST OF REF => lropes _ ListRefAnyToListOfRope[refListOfRef^]; refRef: REF REF => IF refRef^=NIL THEN RETURN[NIL] ELSE ERROR; ENDCASE => ERROR; }; ListRefAnyToListOfRope: PUBLIC PROC [list: LIST OF REF] RETURNS [LIST OF ROPE] = BEGIN RETURN[IF list=NIL THEN NIL ELSE CONS[NARROW[list.first], ListRefAnyToListOfRope[list.rest]]]; END; 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]^; }; <> [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] = { <> 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; <<>> <> 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; <<>> <> 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; <<>> <> IF context.optimize THEN { context.table _ AlpsHeur.BestPermuteInfinitely[context.table, AlpsHeur.ImproveSizeAndDelay]; }; <<>> <> 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; <> 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; }; MakeAlpsCommand: Commander.CommandProc -- [cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL] -- = { <> }; <<>> <<>> MakeAlpsProc: PW.UserProc = BEGIN context: Context _ ReadContextFromAlpsFile[Input["\nFile describing Alps: "]]; obj: CD.ObPtr _ AlpsCellFromContext[context, design]; RETURN [CDDirectory.Name[obj]]; END; <<-- register this generator with PW>> PW.Register[MakeAlpsProc, "MakeAlps"]; END.