@@ -107,7 +107,7 @@ PossibleReturnAddressWithPos(targetSetter, retCtx, retBlock, retTarget, pos) :-
107107 postTrans.Statement_Block(targetSetStatement, targetSetter),
108108 postTrans.BasicBlock_Tail(targetSetter, jumpStmt),
109109 postTrans.JUMP(jumpStmt),
110- postTrans.BeforeLocalStackContents(jumpStmt , pos, targetVariable).
110+ postTrans.BlockOutLocalStackContents(targetSetter , pos, targetVariable).
111111
112112/**
113113 This pattern is prominent in 0.8.x code:
@@ -140,7 +140,7 @@ PossibleReturnAddressWithPos(as(next, Block), retCtx, retBlock, retTarget, pos)
140140 postTrans.StaticBlockJumpTarget(targetSetter, next),
141141 postTrans.BasicBlock_Tail(as(next, Block), jumpStmt),
142142 postTrans.JUMP(jumpStmt),
143- postTrans.BeforeLocalStackContents(jumpStmt , pos, stackIndex),
143+ postTrans.BlockOutLocalStackContents(as(next, Block) , pos, stackIndex),
144144 // filter out cases where the function is called directly
145145 !postTrans.IsJumpBlockPrivateFunctionCall(_, as(next, Block)).
146146
@@ -833,6 +833,11 @@ IRLocalStackContents(irstmt, n, varOrStackIndex) :-
833833 Statement_IRStatement(stmt, _, irstmt).
834834
835835
836+ .decl IRBlockOutLocalStackContents(irBlock: IRBlock, n: StackIndex, varOrStackIndex: VariableOrStackIndex)
837+ IRBlockOutLocalStackContents(irBlock, n, varOrStackIndex) :-
838+ postTrans.BlockOutLocalStackContents(block, n, varOrStackIndex),
839+ Block_IRBlock(block, _, irBlock).
840+
836841/***********
837842 * Discovery of arguments accepted by a function
838843 ***********/
@@ -1154,28 +1159,40 @@ BeforeFunctionCallFunctionalBlockOutputContents(block, index, realVariable) :-
11541159 CheckIsStackIndex(stackIndex).
11551160
11561161
1157- // TODO, check case for function call
1162+ // uses of the jump/ call stmt
11581163FunctionalStatement_Uses_Local(stmt, varOrStackIndex, n) :-
11591164 IRFunctionCall(block, func),
11601165 IRBasicBlock_Tail(block, stmt),
11611166 IRStatement_Opcode(stmt, opcode),
11621167 OpcodePopWords(opcode, m),
1163- //// REVIEW
1164- // PossibleNumberOfFunctionArguments(func, n_in),
1168+ NumberOfFunctionArguments(func, _),
1169+ IRBeforeLocalStackContents(stmt, n, varOrStackIndex), n < m.
1170+
1171+ // function args
1172+ FunctionalStatement_Uses_Local(stmt, varOrStackIndex, n + m) :-
1173+ IRFunctionCall(block, func),
1174+ IRBasicBlock_Tail(block, stmt),
1175+ IRStatement_Opcode(stmt, opcode),
1176+ OpcodePopWords(opcode, m),
11651177 NumberOfFunctionArguments(func, n_in),
1166- IsStackIndexLessThan(n, m+n_in),
1167- IRBeforeLocalStackContents(stmt, n, varOrStackIndex).
1178+ IRBlockOutLocalStackContents(block, n, varOrStackIndex), n < n_in.
11681179
11691180// TODO, check case for function return
11701181FunctionalStatement_Uses_Local(stmt, varOrStackIndex, n) :-
1171- //// REVIEW
1182+ NumberOfFunctionReturnArguments(func, _),
1183+ IRFunction_Return(func, retBlock),
1184+ IRBasicBlock_Tail(retBlock, stmt),
1185+ IRStatement_Opcode(stmt, opcode),
1186+ OpcodePopWords(opcode, m),
1187+ IRBeforeLocalStackContents(stmt, n, varOrStackIndex), n < m.
1188+
1189+ FunctionalStatement_Uses_Local(stmt, varOrStackIndex, n + m) :-
11721190 NumberOfFunctionReturnArguments(func, n_out),
11731191 IRFunction_Return(func, retBlock),
11741192 IRBasicBlock_Tail(retBlock, stmt),
11751193 IRStatement_Opcode(stmt, opcode),
11761194 OpcodePopWords(opcode, m),
1177- IsStackIndexLessThan(n, m+n_out),
1178- IRBeforeLocalStackContents(stmt, n, varOrStackIndex).
1195+ IRBlockOutLocalStackContents(retBlock, n, varOrStackIndex), n < n_out.
11791196
11801197FunctionalStatement_Uses_Local(irstmt, varOrStackIndex, n) :-
11811198 postTrans.Statement_Uses_Local(stmt, varOrStackIndex, n),
0 commit comments