SKB: Refactor decodingNet modules
authorDaniel Schwyn <schwyda@student.ethz.ch>
Mon, 19 Jun 2017 09:19:09 +0000 (11:19 +0200)
committerDaniel Schwyn <schwyda@student.ethz.ch>
Mon, 19 Jun 2017 09:19:09 +0000 (11:19 +0200)
Signed-off-by: Daniel Schwyn <schwyda@student.ethz.ch>

usr/skb/programs/decodingNet.pl
usr/skb/programs/decodingNetQueries.pl
usr/skb/programs/decodingNetSKB.pl [new file with mode: 0644]

index a3e32a3..cd5b975 100644 (file)
 :- export net/2.
 :- export loadnet/1.
 :- export resolve/2.
-:- export toRange/2.
+:- export toRegion/2.
 
 :- lib(ic).
 
 :- dynamic net/2.
 
 %% Load a precompiled decoding net
-loadnet(Name) :-
-    concat_string(["sockeyefacts/",Name],File),
-    [File].
+loadnet(File) :- [File].
 
 %% Address range in block
 blockRange(block(Base,Limit),Range) :-
@@ -97,8 +95,9 @@ resolve(SrcName,DestName) :-
     ),
     acceptedName(DestName).
 
-toRange(Name,Range) :-
+toRegion(Name,Region) :-
     name(Id,Addr) = Name,
     get_min(Addr,Min),get_max(Addr,Max),
-    Range = (Id, Min, Max).
+    Size is Max - Min + 1,
+    Region = (Id, Min, Size).
   
\ No newline at end of file
index 40eb762..eb78f7e 100644 (file)
@@ -8,73 +8,75 @@
 % Attn: Systems Group.
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-:- use_module(decodingNet).
-
-%% Printing
-printRange((SrcId,SrcMin,SrcMax)) :-
-    printf("%a [0x%16R..0x%16R]",
-        [ SrcId,SrcMin,SrcMax ]
-    ).
+:- module(decodingNetQueries).
+:- export findTargetRegion/2.
+:- export findOriginRegion/2.
+:- export findDeviceRegion/3.
+:- export findMemoryRegion/3.
+:- export findSharedMemoryRegion/3.
+:- export findDeviceId/3.
+:- export findInterruptLine/3.
 
-printSrcDestRanges(SrcRange,DestRange) :-
-    printRange(SrcRange),
-    write(" -> "),
-    printRange(DestRange),
-    writeln("").
+:- use_module(decodingNet).
 
-printSharedRanges(Range1,SharedRange,Range2) :-
-    printRange(Range1),
-    write(" -> "),
-    printRange(SharedRange),
-    write(" <- "),
-    printRange(Range2),
-    writeln("").
 
-%% Helper predicates
-resolveToRange(SrcName,DestName,SrcRange,DestRange) :-
+%%%%%%%%%%%%%%%%%%%%%%%
+%% Helper predicates %%
+%%%%%%%%%%%%%%%%%%%%%%%
+resolveToRegion(SrcName,DestName,SrcRegion,DestRegion) :-
     resolve(SrcName,DestName),
-    toRange(SrcName,SrcRange),
-    toRange(DestName,DestRange).
+    toRegion(SrcName,SrcRegion),
+    toRegion(DestName,DestRegion).
 
-all(Pred) :- findall(_,Pred,_).
 
-%% Queries
-findTargetRange(NodeId) :-
+%%%%%%%%%%%%%
+%% Queries %%
+%%%%%%%%%%%%%
+findTargetRegion(NodeId,Result) :-
     SrcName = name(NodeId,_),
-    resolveToRange(SrcName,_,SrcRange,DestRange),
-    printSrcDestRanges(SrcRange,DestRange).
+    resolveToRegion(SrcName,_,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
 
-findOriginRange(NodeId) :-
+findOriginRegion(NodeId,Result) :-
     DestName = name(NodeId,_),
-    resolveToRange(_,DestName,SrcRange,DestRange),
-    printSrcDestRanges(SrcRange,DestRange).
+    resolveToRegion(_,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
 
-findDeviceFrame(NodeId,DeviceId) :-
+%% Address space queries
+findDeviceRegion(NodeId,DeviceId,Result) :-
     SrcName = name(NodeId,_),
     DestName = name(DeviceId,_),
     net(DeviceId,node(device,_,_,_)),
-    resolveToRange(SrcName,DestName,SrcRange,DestRange),
-    printSrcDestRanges(SrcRange,DestRange).
+    resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
 
-findInterruptLine(NodeId,DeviceId) :-
-    SrcName = name(DeviceId,_),
-    DestName = name(NodeId,_),
-    resolveToRange(SrcName,DestName,SrcRange,DestRange),
-    printSrcDestRanges(SrcRange,DestRange).
+findMemoryRegion(NodeId,MemoryId,Result) :-
+    SrcName = name(NodeId,_),
+    DestName = name(MemoryId,_),
+    net(MemoryId,node(memory,_,_,_)),
+    resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
 
-findSharedMemoryFrame(NodeId,DeviceId) :-
+findSharedMemoryRegion(NodeId,DeviceId,Result) :-
     NodeName = name(NodeId,_),
     DeviceName = name(DeviceId,_),
     SharedName = name(SharedId,_),
     net(SharedId,node(memory,_,_,_)),
     resolve(NodeName,SharedName),
     resolve(DeviceName,SharedName),
-    toRange(NodeName,NodeRange),
-    toRange(SharedName,SharedRange),
-    toRange(DeviceName,DeviceRange),
-    printSharedRanges(NodeRange,SharedRange,DeviceRange).
+    toRegion(NodeName,NodeRegion),
+    toRegion(SharedName,SharedRegion),
+    toRegion(DeviceName,DeviceRegion),
+    Result = (NodeRegion,DeviceRegion,SharedRegion).
 
-findDeviceId(NodeId,Addr) :-
+findDeviceId(NodeId,Addr,Result) :-
     SrcName = name(NodeId,Addr),
     resolve(SrcName,name(DeviceId,_)),
-    writeln(DeviceId).
\ No newline at end of file
+    Result = DeviceId.
+
+%% Interrupt queries
+findInterruptLine(NodeId,DeviceId,Result) :-
+    SrcName = name(DeviceId,_),
+    DestName = name(NodeId,_),
+    resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
\ No newline at end of file
diff --git a/usr/skb/programs/decodingNetSKB.pl b/usr/skb/programs/decodingNetSKB.pl
new file mode 100644 (file)
index 0000000..93a7e04
--- /dev/null
@@ -0,0 +1,78 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% 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.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+:- use_module(decodingNet).
+:- use_module(decodingNetQueries).
+:- local loadnet/1.
+
+%%%%%%%%%%%%%%
+%% Printing %%
+%%%%%%%%%%%%%%
+printRegion((Id,Addr,Size)) :-
+    End is Addr + Size - 1,
+    printf("%a [0x%16R..0x%16R]",
+        [ Id,Addr,End ]
+    ).
+
+printSrcDestRegions((SrcRegion,DestRegion)) :-
+    printRegion(SrcRegion),
+    write(" -> "),
+    printRegion(DestRegion),
+    writeln("").
+
+printSharedRegions((Region1,Region2,SharedRegion)) :-
+    printRegion(Region1),
+    write(" -> "),
+    printRegion(SharedRegion),
+    write(" <- "),
+    printRegion(Region2),
+    writeln("").
+
+
+%%%%%%%%%%%%%%%%%%%%%%%
+%% Helper predicates %%
+%%%%%%%%%%%%%%%%%%%%%%%
+loadnet(Name) :- 
+    concat_string(["sockeyefacts/",Name],File),
+    decodingNet:loadnet(File).
+
+all(Pred) :- findall(_,Pred,_).
+
+
+%%%%%%%%%%%%%
+%% Queries %%
+%%%%%%%%%%%%%
+findTargetRegion(NodeId) :-
+    findTargetRegion(NodeId,Result),
+    printSrcDestRegions(Result).
+
+findOriginRegion(NodeId) :-
+    findOriginRegion(NodeId,Result),
+    printSrcDestRegions(Result).
+
+findDeviceRegion(NodeId,DeviceId) :-
+    findDeviceRegion(NodeId,DeviceId,Result),
+    printSrcDestRegions(Result).
+
+findMemoryRegion(NodeId,MemoryId) :-
+    findMemoryRegion(NodeId,MemoryId,Result),
+    printSrcDestRegions(Result).
+
+findSharedMemoryRegion(NodeId,DeviceId) :-
+    findSharedMemoryRegion(NodeId,DeviceId,Result),
+    printSharedRegions(Result).
+
+findDeviceId(NodeId,Addr) :-
+    findDeviceId(NodeId,Addr,Result),
+    writeln(Result).
+
+findInterruptLine(NodeId,DeviceId) :-
+    findInterruptLine(NodeId,DeviceId,Result),
+    printSrcDestRegions(Result).
\ No newline at end of file