decoding net predicates (need to be moved to SKB at some point)
authorDaniel Schwyn <danielschwyn@gmail.com>
Thu, 18 May 2017 15:44:15 +0000 (17:44 +0200)
committerDaniel Schwyn <schwyda@student.ethz.ch>
Tue, 13 Jun 2017 12:21:21 +0000 (14:21 +0200)
Signed-off-by: Daniel Schwyn <schwyda@student.ethz.ch>

tools/sockeye2/decodingNet.pl [new file with mode: 0644]

diff --git a/tools/sockeye2/decodingNet.pl b/tools/sockeye2/decodingNet.pl
new file mode 100644 (file)
index 0000000..34e6900
--- /dev/null
@@ -0,0 +1,60 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright (c) 2017, ETH Zurich.
+% All rights reserved.
+%
+% This file is distributed under the terms in the attached LICENSE file.
+% If you do not find this file, copies can be found by writing to:
+% ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich.
+% Attn: Systems Group.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+:- module(decodingNet,[resolve/2]).
+
+blockContains(block(Base, Limit),Addr) :-
+    between(Base,Limit,Addr).
+
+blockListContains([B|Blocks],Addr) :-
+    blockContains(B,Addr);
+    blockListContains(Blocks,Addr).
+
+mapsToName(map(Src,Dest,DestBase),Addr,Name) :-
+    blockContains(Src,Addr),
+    block(SrcBase,_) = Src,
+    DestAddr is Addr - SrcBase + DestBase,
+    Name = name(Dest,DestAddr).
+
+listMapsToName([M|Maps],Addr,Name) :-
+    mapsToName(M,Addr,Name);
+    listMapsToName(Maps,Addr,Name).    
+
+accept(node(Accept,_,_),Addr) :-
+    blockListContains(Accept,Addr).
+
+translate(node(_,Translate,_),Addr,Name) :-
+    listMapsToName(Translate,Addr,Name),!.
+
+translate(Node,Addr,Name) :-
+    not(accept(Node,Addr)),
+    node(_,_,Overlay) = Node,
+    Name = name(Overlay,Addr).
+
+accepted(Name) :-
+    net(NodeId,Node),
+    accept(Node,Addr),
+    Name = name(NodeId,Addr).
+
+decodeStep(name(NodeId,Addr),Name) :-
+    net(NodeId,Node),
+    translate(Node,Addr,Name).
+
+decodesTo(SrcName,DestName) :-
+    decodeStep(SrcName,Name),
+    (   DestName = Name
+    ;   decodesTo(Name,DestName)
+    ).
+
+resolve(SrcName,DestName) :-
+    accepted(DestName),
+    (   DestName = SrcName
+    ;   decodesTo(SrcName,DestName)
+    ).