DIRECTORY
Alloc: TYPE USING [Notifier],
Code: TYPE USING [codeptr],
CodeDefs:
TYPE
USING [
Base, CCIndex, CCNull, CJItem, codeType, EINull, EnableIndex,
JumpCCIndex, JumpCCNull, LabelCCIndex, LabelCCNull],
OpTableDefs: TYPE USING [InstLength],
P5F: TYPE USING [DidSomething, StartIndex, UCjump, UnthreadJump],
P5U: TYPE USING [CreateLabel, DeleteCell, OutJump, ParamCount];
CrossJump:
PROGRAM
IMPORTS CPtr: Code, OpTableDefs, P5U, P5F
EXPORTS CodeDefs, P5F =
BEGIN
OPEN CodeDefs;
CJcheck: PUBLIC BOOL ← FALSE;
CJNull: CJItem = [CCNull, fallIn[LabelCCNull]];
FunnyJump: SIGNAL [c: CCIndex] = CODE;
CPass5:
PUBLIC
PROC =
BEGIN
CPass5a[];
CPass5b[];
END;
CPass5a:
PROC =
BEGIN -- set enable index in jumps and labels
stack: ARRAY [0..15) OF EnableIndex;
sptr: CARDINAL ← 0;
curEi: EnableIndex ← EINull;
c: CCIndex;
Push:
PROC [new: EnableIndex] =
BEGIN
stack[sptr] ← curEi;
curEi ← new;
sptr ← sptr + 1;
END;
Pop:
PROC =
BEGIN
sptr ← sptr - 1;
curEi ← stack[sptr];
END;
FOR c ← cb[P5F.StartIndex].flink, cb[c].flink
WHILE c # CCNull
DO
WITH cc: cb[c]
SELECT
FROM
label => cc.ei ← curEi;
jump => cc.ei ← curEi;
other =>
WITH cc
SELECT
FROM
markCatch => IF start THEN Push[index] ELSE Pop[];
ENDCASE;
ENDCASE;
ENDLOOP;
END;
FirstItem:
PROC[lc: LabelCCIndex]
RETURNS [item: CJItem] =
BEGIN
j: JumpCCIndex ← cb[lc].jumplist;
pred: CCIndex;
IF j = JumpCCNull THEN RETURN [CJNull];
IF (pred←PrevInst[lc]) = CCNull THEN RETURN [CJNull];
item ← [pred, fallIn[lc]];
IF Executable[pred] THEN RETURN [item];
RETURN [NextItem[item]]
END;
CrossJumpIt:
PROC [i1, i2: CJItem] =
BEGIN
l: LabelCCIndex;
fb: CCIndex = PrevInst[i1.inst];
WITH cb[fb]
SELECT
FROM
label => l ← LOOPHOLE[fb];
ENDCASE => {CPtr.codeptr ← fb; l ← P5U.CreateLabel[]};
CPtr.codeptr ← cb[i2.inst].blink; -- don't skip over source here
P5U.OutJump[Jump,l];
WITH cb[i2.inst]
SELECT
FROM
jump => P5F.UnthreadJump[LOOPHOLE[i2.inst]];
ENDCASE;
P5U.DeleteCell[i2.inst];
WITH ii: i2
SELECT
FROM
jumpIn =>
IF ii.jc # i2.inst
THEN
{P5F.UnthreadJump[ii.jc]; P5U.DeleteCell[ii.jc]};
ENDCASE;
END;
the following two procs are like NextInteresting and PrevInteresting
in PeepholeU, only they won't skip over a MarkCatch