AlpsBool:
CEDAR
DEFINITIONS =
BEGIN
Types and data structures
ROPE: TYPE = Rope.ROPE;
VarNb: TYPE = [0..999);
CompClass: TYPE = {case11, case10, caseX1, caseX0, case1X, case0X, caseXNotX, caseXY};
RopeFromCompClass: PROC [case: CompClass] RETURNS [rope: ROPE];
Expression: TYPE = REF ExpressionRec;
ExpressionRec:
TYPE =
MACHINE DEPENDENT RECORD [
varNb: VarNb, -- variable corresponding to this level of currification
norm: BOOL ← TRUE, -- says whether the record represents the information (TRUE) or its complement (FALSE)
case: CompClass, -- Class of the composition
spare: [0..4) ← 0,
subexpr1, subexpr2: Expression -- they are not always useful, but that's the cheapest way to have them
];
TableOfVariables: TYPE = REF TableOfVariablesRec;
TableOfVariablesRec:
TYPE =
RECORD [
outputs: LIST OF OutputRef ← NIL,
inputs:
SEQUENCE size: VarNb
OF
RECORD [
name: ROPE ← NIL,
fromOutput: OutputRef ← NIL -- the corresponding output for latches or auxiliary variables
]];
OutputRef: TYPE = REF OutputRec;
OutputRec:
TYPE =
RECORD [
name: ROPE ← NIL,
type: OutputType ← output,
expr: Expression,
fedBackInput: VarNb ← 0 -- the corresponding input for latches or auxiliary variables
];
OutputType: TYPE = {output, aux, latch};
Constants
true: READONLY Expression;
false: READONLY Expression;
Usual Operators
And: PROC [table: TableOfVariables, expr1, expr2, expr3, expr4, expr5, expr6: Expression ← true] RETURNS [Expression];
AndList: PROC [table: TableOfVariables, exprs: LIST OF Expression] RETURNS [Expression];
AndTwo: PROC [table: TableOfVariables, expr1, expr2: Expression, norm1, norm2: BOOL ← TRUE] RETURNS [Expression];
Or: PROC [table: TableOfVariables, expr1, expr2, expr3, expr4, expr5, expr6: Expression ← false] RETURNS [Expression];
OrList: PROC [table: TableOfVariables, exprs: LIST OF Expression] RETURNS [Expression];
This one is the primitive for the others
OrTwo: PROC [table: TableOfVariables, expr1, expr2: Expression, norm1, norm2: BOOL ← TRUE] RETURNS [result: Expression];
Nor: PROC [table: TableOfVariables, expr1, expr2, expr3, expr4, expr5, expr6: Expression ← false] RETURNS [Expression];
NorList: PROC [table: TableOfVariables, exprs: LIST OF Expression] RETURNS [Expression];
NorTwo: PROC [table: TableOfVariables, expr1, expr2: Expression, norm1, norm2: BOOL ← TRUE] RETURNS [Expression];
Not: PROC [expr: Expression] RETURNS [Expression];
Norm: PROC [expr: Expression, norm: BOOL] RETURNS [Expression];
Xor: PROC [table: TableOfVariables, expr1, expr2: Expression] RETURNS [expr: Expression];
Returns (expr AND exprTrue) OR (~expr AND exprFalse)
Norm specifies whether or not If should negate both exprTrue and exprFalse
If: PROC [table: TableOfVariables, expr, exprTrue, exprFalse: Expression, norm: BOOL ← TRUE] RETURNS [Expression];
Creates an expression from a variable
Var, ExprFromVarNb: PROC [varNb: VarNb, norm: BOOL ← TRUE] RETURNS [Expression];
Instanciation of expressions
Low level function for creating Expressions.
MakeComp: PROC [case: CompClass, varNb: VarNb, subexpr1, subexpr2: Expression, norm: BOOL ← TRUE] RETURNS [Expression];
Creates an expression, setting the case field to the appriopriate value depending on possible simplifications.
If comp=FALSE then both whenTrue and whenFalse have in fact opposite values
Comp: PROC [table: TableOfVariables, varNb: VarNb, whenTrue, whenFalse: Expression, norm: BOOL ← TRUE] RETURNS [Expression];
Does NOT take expr.norm into account
WhenTrue: PROC [expr: Expression] RETURNS [Expression];
WhenFalse: PROC [expr: Expression] RETURNS [Expression];
Expanses once the expression expr, assuming that its first variable is an auxiliary
ExpandAux: PROC [table: TableOfVariables, expr: Expression] RETURNS [Expression];
-- Expanses expr by replacing all occurences of auxVarNb by auxExpr
ExpanseAux: PROC [table: TableOfVariables, expr, auxExpr: Expression, auxVarNb: VarNb] RETURNS [Expression];
Procs operating on expressions
Equal: PROC [table: TableOfVariables, expr1, expr2: Expression, norm: BOOL ← TRUE] RETURNS [BOOL];
This Equal follows auxVar for equality
FullEqual: PROC [table: TableOfVariables, expr1, expr2: Expression, norm: BOOL ← TRUE] RETURNS [BOOL];
RopeFromExpression: PROC [table: TableOfVariables, expr: Expression, norm: BOOL ← TRUE, deep: INT ← 4] RETURNS [ROPE];
AlpsRopeFromExpr: PROC [table: TableOfVariables, expr: Expression] RETURNS [rope: ROPE];
Utilities
NewName: PROC [rope: ROPE ← NIL] RETURNS [ROPE];
InitTableOfVariables: PROC [size: INT] RETURNS [table: TableOfVariables];
AddOutput: PUBLIC PROC [table: TableOfVariables, output: OutputRef];
VarNbFromRope: PROC [table: TableOfVariables, name: ROPE] RETURNS [varNb: VarNb];
RopeFromVarNb: PROC [table: TableOfVariables, varNb: VarNb] RETURNS [name: ROPE ← NIL];
May raise TerminalIO.UserAbort
Input: PROC [text: ROPE] RETURNS [ROPE];
Output: PROC [t1, t2, t3, t4, t5: ROPE ← NIL];
Alps heart
ReadPLAFile: PROC [fileName: ROPE, inputs, outputs: LIST OF ROPE ← NIL] RETURNS [table: TableOfVariables];
DumpTT: PROC [table: TableOfVariables, stream: IO.STREAM];
DumpAlps: PROC [table: TableOfVariables, name: ROPE, stream: IO.STREAM];
EachNodeProc: TYPE = PROC [expr: Expression] RETURNS [quit: BOOL ← FALSE];
Enumerate: PROC [expr: Expression, eachNodeProc: EachNodeProc];
EachBranchProc: TYPE = PROC [expr: Expression] RETURNS [newExpr: Expression];
CopyTree: PROC [table: TableOfVariables, expr: Expression, eachBranchProc: EachBranchProc] RETURNS [newExpr: Expression];
Size: PROC [table: TableOfVariables, expr: Expression, varNb: VarNb] RETURNS [size: INT ← 0];
NbOfCaseXY: PROC [table: TableOfVariables, expr: Expression] RETURNS [nbCaseXY: INT ← 0];
NbOfCaseXNotX: PROC [table: TableOfVariables, expr: Expression] RETURNS [nbCaseXNotX: INT ← 0];
NbOfCasesArray: TYPE = ARRAY CompClass OF INT ← ALL[0];
MaxWidth: PROC [table: TableOfVariables, expr: Expression] RETURNS [INT];
MinWidth: PROC [table: TableOfVariables] RETURNS [minWidth: INT ← 0];
UsedVarsSequence: TYPE = REF UsedVarsSequenceRec;
UsedVarsSequenceRec:
TYPE =
RECORD [
contents: PACKED SEQUENCE size: VarNb OF BOOL
];
To create a fresh UsedVarsSequence with contents being ALL[FALSE]
NoUsedVarsSequence: PROC [table: TableOfVariables] RETURNS [allFalseUsedVarSequence: UsedVarsSequence];
-- Adds to usedVars all the vars used in thes Expression expr
ExprAddUsedVars: PROC [expr: Expression, usedVars: UsedVarsSequence];
NbVars: PROC [table: TableOfVariables, expr: Expression] RETURNS [nb: INT ← 0];
NbUsedVar: PROC [expr: Expression, varNb: VarNb] RETURNS [nbUsedVar: INT ← 0];
Deep: PROC [table: TableOfVariables, expr: Expression] RETURNS [INT];
NbOfVars: PROC [table: TableOfVariables] RETURNS [input, aux, output, latch: VarNb ← 0];
printLevel=0 prints nothing and just returns statistics
PrintExpression: PROC [table: TableOfVariables, output: OutputRef, printLevel: INT ← 4] RETURNS [size, nbOfCaseXY, maxWidth, deep: INT];
TableStatistics: PROC [table: TableOfVariables, print: BOOL ← FALSE] RETURNS [area, sigmaSize, sigmaNbOfCaseXY, sigmaMaxWidth, maxDeep: INT ← 0];
With printLevel=0, just final statistics are printed
PrintTable: PROC [table: TableOfVariables, printLevel: INT ← 4];
RenumProc: TYPE = PROC [oldVarNb: VarNb] RETURNS [newVarNb: VarNb];
IdentityRenum: RenumProc;
ChangeVars: PROC [table: TableOfVariables, expr: Expression, renumProc: RenumProc] RETURNS [Expression];
Factorize: PROC [table: TableOfVariables, expr, aux: Expression, auxVar: VarNb] RETURNS [Expression];
Permute2Vars: PROC [table: TableOfVariables, varNb1, varNb2: VarNb] RETURNS [newTable: TableOfVariables];
ExprWhenVarIs:
PROC [table: TableOfVariables, expr: Expression, varNb: VarNb, varNbNorm:
BOOL ←
TRUE]
RETURNS [newExpr: Expression];
Checksum: PROC [table: TableOfVariables] RETURNS [checksum: INT ← 0];
EstimatedArea: PROC [table: TableOfVariables] RETURNS [area: INT ← 0];
END.