DPBuilder.mesa
Copyright © 1985-1986 by Xerox Corporation. All rights reversed.
Last Edited by: Ross July 16, 1986 6:33:37 pm PDT
DIRECTORY FS, PW, DPLib, IO, Rope, CDIO, BoolOps, TerminalIO;
DPBuilder: CEDAR PROGRAM
IMPORTS PW, DPLib, CDIO, FS, IO, Rope, BoolOps, TerminalIO =
BEGIN OPEN DPLib;
Generate: PW.UserProc = {
Library for design:
myLib: PW.Design ← PW.OpenDesign["///Users/ross.pa/tamarin/datapath.dale"];
Constant Declarations:
NUMBITS: INT = 32;
Library for cells: see DPLib.mesa and DPLibImpl.mesa
Procedures are used for those blocks which are not simple array calls:
ShiftGen: PROC [] RETURNS [shifter: PW.Object] = {
shifter ← PW.AbutListY[LIST[sh31, sh30, sh29, sh28, sh27, sh26, sh25, sh24, PW.ArrayY[sh823, 16], sh7, sh6, sh5, sh4, sh3, sh2, sh1, sh0]];
shifter ← PW.AbutX[shifter, PW.AbutY[tagstuff31, tagstuff30, PW.ArrayY[tagstuff, NUMBITS-2]]];
RETURN[shifter];
};
CCodeGen: PROC [ccFile: Rope.ROPE] RETURNS [ccArray: PW.Object] = {
BuildCCArray: PROC[in: IO.STREAM] RETURNS [ccArray: PW.Object] = {
pterms: INT ← 0;
r: Rope.ROPE;
ccRow: PW.Object ← NIL;
eof: BOOLFALSE;
ccRowList: LIST OF PW.Object ← NIL;
ccArrayList: LIST OF PW.Object ← NIL;
numccRows: INT ← 0;
DO
r ← IO.GetLineRope[in ! IO.EndOfStream => {eof ← TRUE; CONTINUE}];
IF eof THEN EXIT;
IF Rope.Length[r] < 1 THEN LOOP;
first pterm, count number of inputs and outputs
ccRow ← NIL;
ccRowList ← NIL;
FOR j: INT IN [0..Rope.Length[r]) DO
ch: CHAR ← Rope.Fetch[r, j];
IF PW.ODD[numccRows] THEN {
SELECT ch FROM
'A => {ccRowList ← CONS[ccCellAL, ccRowList]};
'B => {ccRowList ← CONS[ccCellBL, ccRowList]};
'C => {ccRowList ← CONS[ccCellCL, ccRowList]};
'D => {ccRowList ← CONS[ccCellDL, ccRowList]};
'E => {ccRowList ← CONS[ccCellEL, ccRowList]};
'F => {ccRowList ← CONS[ccCellFL, ccRowList]};
'G => {ccRowList ← CONS[ccCellGL, ccRowList]};
'H => {ccRowList ← CONS[ccCellHL, ccRowList]};
'I => {ccRowList ← CONS[ccCellIL, ccRowList]};
'J => {ccRowList ← CONS[ccCellJL, ccRowList]};
ENDCASE => {
TerminalIO.WriteRope["Bad character in the input file ... \n"];
};
} ELSE {
SELECT ch FROM
'A => {ccRowList ← CONS[ccCellAR, ccRowList]};
'B => {ccRowList ← CONS[ccCellBR, ccRowList]};
'C => {ccRowList ← CONS[ccCellCR, ccRowList]};
'D => {ccRowList ← CONS[ccCellDR, ccRowList]};
'E => {ccRowList ← CONS[ccCellER, ccRowList]};
'F => {ccRowList ← CONS[ccCellFR, ccRowList]};
'G => {ccRowList ← CONS[ccCellGR, ccRowList]};
'H => {ccRowList ← CONS[ccCellHR, ccRowList]};
'I => {ccRowList ← CONS[ccCellIR, ccRowList]};
'J => {ccRowList ← CONS[ccCellJR, ccRowList]};
ENDCASE => {
TerminalIO.WriteRope["Bad character in the input file ... \n"];
};
};
ENDLOOP;
ccRow ← PW.AbutListY[PW.Reverse[ccRowList]];
ccArrayList ← CONS[ccRow, ccArrayList];
numccRows ← numccRows + 1;
ENDLOOP;
ccArray ← PW.AbutListX[ccArrayList];
RETURN[ccArray];
};
ccStream: IO.STREAM;
explanation: Rope.ROPE;
IF ccFile = NIL THEN RETURN[NIL];
ccStream ← FS.StreamOpen[fileName: ccFile, wDir: CDIO.GetWorkingDirectory[] ! FS.Error => IF error.group = user THEN {ccStream ← NIL; CONTINUE}];
IF ccStream = NIL THEN
TerminalIO.WriteRope["Could not open input file \n"];
ccArray ← BuildCCArray[ccStream ! BoolOps.Error => {explanation ← msg; CONTINUE}];
IF explanation # NIL THEN
TerminalIO.WriteRope["Bad character in the input file ... \n"];
RETURN[ccArray];
};
AdderGen: PROC [adderFile: Rope.ROPE] RETURNS [adder: PW.Object] = {
BuildAdder: PROC[in: IO.STREAM] RETURNS [adder: PW.Object] = {
pterms: INT ← 0;
r: Rope.ROPE;
addlist: LIST OF PW.Object;
addcol: PW.Object ← NIL;
eof: BOOLFALSE;
DO
r ← IO.GetLineRope[in ! IO.EndOfStream => {eof ← TRUE; CONTINUE}];
IF eof THEN EXIT;
IF Rope.Length[r] < 1 THEN LOOP;
FOR j: INT IN [0..Rope.Length[r]) DO
ch: CHAR ← Rope.Fetch[r, j];
SELECT ch FROM
'B => {addlist ← CONS[cpAddB, addlist]};
'R => {addlist ← CONS[cpAddR, addlist]};
ENDCASE => {
TerminalIO.WriteRope["Bad character in the input file ... \n"];
};
ENDLOOP;
addcol ← PW.AbutListY[addlist];
ENDLOOP;
RETURN[addcol];
};
addStream: IO.STREAM;
explanation: Rope.ROPE;
IF adderFile = NIL THEN RETURN[NIL];
addStream ← FS.StreamOpen[fileName: adderFile, wDir: CDIO.GetWorkingDirectory[] ! FS.Error => IF error.group = user THEN {addStream ← NIL; CONTINUE}];
IF addStream = NIL THEN
TerminalIO.WriteRope["Could not open input file \n"];
adder ← BuildAdder[addStream ! BoolOps.Error => {explanation ← msg; CONTINUE}];
IF explanation # NIL THEN
TerminalIO.WriteRope["Bad character in the input file ... \n"];
RETURN[adder];
};
datapath: PW.Object;
InitDP[myLib];
datapath ← PW.AbutX[PW.ArrayY[ dswap, NUMBITS], ShiftGen[], AdderGen["///users/ross.pa/tamarin/Adder.spec"], PW.ArrayY[lu2, NUMBITS], CCodeGen["///users/ross.pa/tamarin/CondCode.spec"]];
datapath ← PW.AbutX[PW.AbutY[msbside, datapath, lsbside], restOfDp];
RETURN[datapath];
};
PW.Register[Generate, "DPBuilder"];
END.