communication.lp
No OneTemporary

File Metadata

Created
Thu, Jul 9, 4:29 AM

communication.lp

%INPUT:
% const horizon - Max Depth of communication analysis
% comm_order(Alias)), bind(X, comm_alias(Alias) - to apply additional order constraints
% dfa_uppy from dfa-propagation
% INIT
%===========================================================
comm_bind(end, end).
comm_bind(begin, begin).
comm_bind(X, Op):- bind(X, commop(Op)).
% ORDER
%============================================================
comm_link(X2, X1) :- bind(X2, comm_order(Alias)); bind(X1, comm_alias(Alias)).
% INHERITS
%============================================================
comm_link(X, Y) :- dfa_uppy(X, Y).
comm_link(end, X) :- v(X); #sum{1: weak(comm_link(Smth, X)), v(Smth)}0.
comm_link(X, begin):- v(X); #sum{1: weak(comm_link(X, Smth)), v(Smth)}0.
% SCAN
%============================================================
%SOURCE
comm_scan(X, source(X), length(0)) :- comm_bind(X, send).
comm_scan(Z, source(X), length(Length + 1)) :-
comm_link(Z, Y);
comm_scan(Y, source(X), length(Length)); Length < horizon;
not comm_bind(Z, _).
comm_scan(Z, source(X), report(Op)) :-
comm_link(Z, Y);
comm_scan(Y, source(X), length(Length)); Length < horizon;
comm_bind(Z, Op).
%SINK
comm_scan(X, sink(X), length(0)) :- comm_bind(X, receive).
comm_scan(Z, sink(X), length(Length + 1)) :-
comm_link(Y, Z);
comm_scan(Y, sink(X), length(Length)); Length < horizon;
not comm_bind(Z, _).
comm_scan(Z, sink(X), report(Op)) :-
comm_link(Y, Z);
comm_scan(Y, sink(X), length(Length)); Length < horizon;
comm_bind(Z, Op).
% REPORTS
%==============================================================
comm_reports_type(rprtLostEnd; rprtLost; rprtCorruptNull; rprtDup; rprtOutOfReach).
comm_reports(rprtLostEnd , Source, undef) :- comm_scan(_, source(Source), report(end)).
comm_reports(rprtLost , Source, Spot) :- comm_scan(Spot, source(Source), report(send)).
comm_reports(rprtCorruptNull, Sink, undef) :- comm_scan(_, sink(Sink), report(begin)).
comm_reports(rprtDup , Sink, Spot) :- comm_scan(Spot, sink(Sink), report(receive)).
comm_halt(Source):- comm_reports(rprtLostEnd, Source, undef).
comm_halt(Source):- comm_reports(rprtLost, Source, _).
comm_halt(Sink):- comm_reports(rprtCorruptNull, Sink, undef).
comm_halt(Sink):- comm_reports(rprtDup, Sink, Spot).
% WEAK REPORTS
%=============================================================
weak(comm_reports(rprtLostEnd , Source)) :- weak(comm_scan(_, source(Source), report(end))).
weak(comm_reports(rprtLost , Source, Spot)) :- weak(comm_scan(Spot, source(Source), report(send))).
weak(comm_reports(rprtCorruptNull, Sink)) :- weak(comm_scan(_, sink(Sink), report(begin))).
weak(comm_reports(rprtDup, Sink, Spot)) :- weak(comm_scan(Spot, sink(Sink), report(receive))).
comm_reports(rprtOutOfReach, X, Spot) :- weak(comm_scan(Spot, source(X), length(horizon))).
comm_reports(rprtOutOfReach, X, Spot) :- weak(comm_scan(Spot, sink(X), length(horizon))).
% SOLUTIONS
%=============================================================
comm_impl(Source, commGuarded):- comm_bind(Source, send);
not comm_halt(Source);
1{ weak(comm_reports(Type, Source, _)): comm_reports_type(Type) }.
comm_impl(Source, commDirect):- comm_bind(Source, send);
not comm_halt(Source);
not comm_impl(Source, commGuarded).
bind(Source, callguard(commDirect)):- comm_impl(Source, commDirect).
bind(Source, callguard(commGuarded)):- comm_impl(Source, commGuarded).
% WEAK ANALYSIS
%=============================================================
weak(comm_link(X, Y)) :- weak(dfa_uppy(X, Y)).
weak(comm_scan(Arg1, Arg2, Arg3)) :- comm_scan(Arg1, Arg2, Arg3).
weak(comm_scan(Z, sink(X), length(Length + 1))):-
weak(comm_link(Y, Z));
weak(comm_scan(Y, sink(X), length(Length))); Length < horizon;
not comm_bind(Z, _).
weak(comm_scan(Z, sink(X), report(Op))):-
weak(comm_link(Y, Z));
weak(comm_scan(Y, sink(X), length(Length))); Length < horizon;
comm_bind(Z, Op).
weak(comm_scan(Z, source(X), length(Length + 1))) :-
weak(comm_link(Z, Y));
weak(comm_scan(Y, source(X), length(Length))); Length < horizon;
not comm_bind(Z, _).
weak(comm_scan(Z, source(X), report(Op))) :-
weak(comm_link(Z, Y));
weak(comm_scan(Y, source(X), length(Length))); Length < horizon;
comm_bind(Z, Op).

Event Timeline