Refactor decoding net skb programs
authorDaniel Schwyn <schwyda@student.ethz.ch>
Mon, 12 Jun 2017 08:44:33 +0000 (10:44 +0200)
committerDaniel Schwyn <schwyda@student.ethz.ch>
Tue, 13 Jun 2017 12:22:59 +0000 (14:22 +0200)
Signed-off-by: Daniel Schwyn <schwyda@student.ethz.ch>

usr/skb/programs/decodingNet.pl
usr/skb/programs/decodingNetQueries.pl

index 88ba87b..a3e32a3 100644 (file)
 
 :- module(decodingNet).
 :- export net/2.
+:- export loadnet/1.
 :- export resolve/2.
-:- export findRanges/4.
+:- export toRange/2.
 
 :- lib(ic).
 
 :- dynamic net/2.
 
+%% Load a precompiled decoding net
+loadnet(Name) :-
+    concat_string(["sockeyefacts/",Name],File),
+    [File].
+
 %% Address range in block
 blockRange(block(Base,Limit),Range) :-
     Range = Base..Limit.
@@ -91,12 +97,8 @@ resolve(SrcName,DestName) :-
     ),
     acceptedName(DestName).
 
-findRanges(SrcName,DestName,SrcRange,DestRange) :-
-    resolve(SrcName,DestName),
-    name(SrcId,SrcAddr) = SrcName,
-    name(DestId,DestAddr) = DestName,
-    get_min(SrcAddr,SrcMin),get_max(SrcAddr,SrcMax),
-    get_min(DestAddr,DestMin),get_max(DestAddr,DestMax),
-    SrcRange = (SrcId, SrcMin, SrcMax),
-    DestRange = (DestId, DestMin, DestMax).
+toRange(Name,Range) :-
+    name(Id,Addr) = Name,
+    get_min(Addr,Min),get_max(Addr,Max),
+    Range = (Id, Min, Max).
   
\ No newline at end of file
index 783ee17..40eb762 100644 (file)
@@ -10,6 +10,7 @@
 
 :- use_module(decodingNet).
 
+%% Printing
 printRange((SrcId,SrcMin,SrcMax)) :-
     printf("%a [0x%16R..0x%16R]",
         [ SrcId,SrcMin,SrcMax ]
@@ -29,37 +30,48 @@ printSharedRanges(Range1,SharedRange,Range2) :-
     printRange(Range2),
     writeln("").
 
-findTargetRanges(NodeId) :-
-    SrcName = name(NodeId,_),
-    findall((SrcRange,DestRange),findRanges(SrcName,_,SrcRange,DestRange),List),
-    (foreach((Src,Dest),List) do printSrcDestRanges(Src,Dest)).
+%% Helper predicates
+resolveToRange(SrcName,DestName,SrcRange,DestRange) :-
+    resolve(SrcName,DestName),
+    toRange(SrcName,SrcRange),
+    toRange(DestName,DestRange).
 
+all(Pred) :- findall(_,Pred,_).
 
-findOriginRanges(NodeId) :-
+%% Queries
+findTargetRange(NodeId) :-
+    SrcName = name(NodeId,_),
+    resolveToRange(SrcName,_,SrcRange,DestRange),
+    printSrcDestRanges(SrcRange,DestRange).
+
+findOriginRange(NodeId) :-
     DestName = name(NodeId,_),
-    findall((SrcRange,DestRange),findRanges(_,DestName,SrcRange,DestRange),List),
-    (foreach((Src,Dest),List) do printSrcDestRanges(Src,Dest)).
+    resolveToRange(_,DestName,SrcRange,DestRange),
+    printSrcDestRanges(SrcRange,DestRange).
 
 findDeviceFrame(NodeId,DeviceId) :-
     SrcName = name(NodeId,_),
     DestName = name(DeviceId,_),
     net(DeviceId,node(device,_,_,_)),
-    findRanges(SrcName,DestName,SrcRange,DestRange),
+    resolveToRange(SrcName,DestName,SrcRange,DestRange),
     printSrcDestRanges(SrcRange,DestRange).
 
 findInterruptLine(NodeId,DeviceId) :-
     SrcName = name(DeviceId,_),
     DestName = name(NodeId,_),
-    findRanges(SrcName,DestName,SrcRange,DestRange),
+    resolveToRange(SrcName,DestName,SrcRange,DestRange),
     printSrcDestRanges(SrcRange,DestRange).
 
 findSharedMemoryFrame(NodeId,DeviceId) :-
     NodeName = name(NodeId,_),
-    DevName = name(DeviceId,_),
+    DeviceName = name(DeviceId,_),
     SharedName = name(SharedId,_),
     net(SharedId,node(memory,_,_,_)),
-    findRanges(NodeName,SharedName,NodeRange,SharedRange),
-    findRanges(DevName,SharedName,DeviceRange,SharedRange),
+    resolve(NodeName,SharedName),
+    resolve(DeviceName,SharedName),
+    toRange(NodeName,NodeRange),
+    toRange(SharedName,SharedRange),
+    toRange(DeviceName,DeviceRange),
     printSharedRanges(NodeRange,SharedRange,DeviceRange).
 
 findDeviceId(NodeId,Addr) :-