PLAOpsImplC.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last edited by Curry, April 4, 1986 2:38:28 pm PST
PLAOpsImplC:
CEDAR
PROGRAM
IMPORTS Basics, BasicTime, IO, PLAOps, REFBit, Rope
EXPORTS PLAOps =
BEGIN OPEN PLAOps, REFBit;
NewPLA:
PUBLIC
PROC[inRef, outRef:
REF]
RETURNS[pla:
PLA] = {
inName, outName: IO.ROPE;
WITH inRef
SELECT
FROM
name: IO.ROPE => {inName ← name};
refText: REF TEXT => {inName ← Rope.FromRefText[refText]};
ref:
REF => {
inName ← REFBit.Desc[ref].typeName;
IF inName = NIL OR inName.Length[]=0 THEN ERROR};
ENDCASE;
WITH outRef
SELECT
FROM
name: IO.ROPE => {outName ← name};
refText: REF TEXT => {outName ← Rope.FromRefText[refText]};
ref:
REF => {
outName ← REFBit.Desc[ref].typeName;
IF outName = NIL OR outName.Length[]=0 THEN ERROR};
ENDCASE;
pla ←
NEW[PLARec ← [
mask: REFBit.NEWFromName[inName],
data: REFBit.NEWFromName[inName],
out: REFBit.NEWFromName[outName],
time: BasicTime.Now[],
termList: NIL,
term: NIL] ];
FOR bit:
INT
IN [0..REFBit.Size[pla.data])
DO
-- Check for non-zero initial value
IF REFBit.Get[pla.data, bit]
THEN
{
Error[IO.PutFR["Non-zero initial value for pla input record: %g.%g",
IO.rope[inName], IO.rope[REFBit.Desc[pla.data].bitForm[bit].name]]]} ENDLOOP;
FOR bit:
INT
IN [0..REFBit.Size[pla.out])
DO
-- Check for non-zero initial value
IF REFBit.Get[pla.out, bit]
THEN
{
Error[IO.PutFR["Non-zero initial value for pla output record: %g.%g",
IO.rope[outName], IO.rope[REFBit.Desc[pla.out].bitForm[bit].name]]]} ENDLOOP;
pla.termList ←
NEW[TermListRec ← [
inBits: REFBit.Desc[pla.data].wds.size*16,
outBits: REFBit.Desc[pla.out].wds.size*16] ];
pla.term ← NewTerm[inBitSize: pla.termList.inBits, outBitSize: pla.termList.outBits] };
Error: ERROR [msg: IO.ROPE] = CODE;
CopyPLA
SubFields:
PUBLIC
PROC[refPla: PLA, outRef:
REF ]
RETURNS[newPla: PLA] = {
newTerm: Term;
refForm, newForm, oldForm: Format;
newPla ← NewPLA[refPla.data, outRef];
IF refPla.termList = NIL THEN RETURN[NIL];
newTerm ← NewTerm[newPla.termList.inBits, newPla.termList.outBits];
newTerm.in ← NIL; -- Throw away in sequence
refForm ← REFBit.Desc[refPla.out].fieldForm;
newForm ← REFBit.Desc[newPla.out].fieldForm;
oldForm ← NEW[FormatSeq[newForm.size]]; -- translation from new to old field position
FOR newField:
CARDINAL
IN [0..newForm.size)
DO
FOR refField:
CARDINAL
IN [0..refForm.size)
DO
IF
Rope.Equal[refForm[refField].name, newForm[newField].name] AND
Rope.Equal[refForm[refField].nameInv, newForm[newField].nameInv]
THEN {oldForm[newField] ← refForm[refField]; EXIT}
REPEAT FINISHED => ERROR -- NOT found -- ENDLOOP ENDLOOP;
FOR i:
CARDINAL
IN [0..newTerm.out.wdSize)
DO
newTerm.out[i] ← initOutQrtWz ENDLOOP;
FOR refTerm: Term ← refPla.termList.begin, refTerm.next
WHILE refTerm#
NIL
DO
interesting: BOOL ← FALSE;
FOR field:
CARDINAL
IN [0..newForm.size)
DO
FOR bit:
CARDINAL
IN [0..newForm[field].bitSize)
DO
q: Qrt ← GetOutQrt[refTerm, oldForm[field].firstBit + bit];
SetOutQrt[q, newTerm, newForm[field].firstBit + bit];
interesting ← interesting OR q=one OR q=dontcare
ENDLOOP;
ENDLOOP;
IF ~interesting THEN LOOP;
newTerm.in ← refTerm.in; ACopy[newTerm, newPla.termList ];
ENDLOOP;
newTerm.in ← newTerm.out ← NIL;
newTerm ← NIL };
GetBEForDataMask:
PUBLIC PROC[pla:
PLA]
RETURNS[be: BoolExpr] = {
dDesc: REFBitDesc ← REFBit.Desc[pla.data];
mDesc: REFBitDesc ← REFBit.Desc[pla.mask];
term: Term ← NewTerm[inBitSize: pla.termList.inBits, outBitSize: 16];
pla.validTerm ← FALSE;
be ← NEW[TermListRec ← [inBits: pla.termList.inBits, outBits: 16] ];
REFBit.TVToDescWds[dDesc];
REFBit.TVToDescWds[mDesc];
FOR i:
CARDINAL
IN [0..term.in.wdSize)
DO
term.in[i].d ← Basics.BITAND[dDesc.wds[i], mDesc.wds[i]];
term.in[i].m ← mDesc.wds[i]; ENDLOOP;
term.out[0].d ← term.out[0].m ← 177777B;
AppendTerm[term, be ] };
SetOutForBE:
PUBLIC PROC[pla:
PLA, be: BoolExpr] = {
oDesc: REFBitDesc ← REFBit.Desc[pla.out];
pla.validTerm ← FALSE;
REFBit.TVToDescWds[oDesc];
FOR i:
CARDINAL
IN [0..oDesc.wds.size)
DO
IF oDesc.wds[i] # 0
THEN
EXIT;
REPEAT FINISHED => RETURN ENDLOOP;
FOR t: Term ← be.begin, t.next
WHILE t#
NIL
DO
new: Term ← NewTerm[pla.termList.inBits, pla.termList.outBits];
FOR i: CARDINAL IN [0..new.in.wdSize) DO new.in[i] ← t.in[i] ENDLOOP;
FOR i:
CARDINAL
IN [0..pla.term.out.wdSize)
DO
new.out[i].d ← oDesc.wds[i];
new.out[i].m ← 177777B ENDLOOP;
AppendTerm[new, pla.termList] ENDLOOP};
GetOutForData:
PUBLIC PROC[pla:
PLA] = {
dDesc: REFBitDesc ← REFBit.Desc[pla.data];
oDesc: REFBitDesc ← REFBit.Desc[pla.out];
REFBit.TVToDescWds[dDesc];
FOR i:
CARDINAL
IN [0..pla.term.in.wdSize)
DO
IF
NOT pla.validTerm
OR pla.term.in[i].d # dDesc.wds[i]
THEN
{pla.validTerm ← FALSE; pla.term.in[i].d ← dDesc.wds[i]};
IF
NOT pla.validTerm
OR pla.term.in[i].m # 177777B
THEN
{pla.validTerm ← FALSE; pla.term.in[i].m ← 177777B};
ENDLOOP;
IF
NOT pla.validTerm
THEN {
GetTermVal[pla.term, pla.termList]; pla.validTerm ← TRUE;
FOR i: CARDINAL IN [0..pla.term.out.wdSize) DO oDesc.wds[i] ← pla.term.out[i].d ENDLOOP;
REFBit.DescWdsToTV[oDesc]} };
END.