SKB: Refactor decodingNet modules
[barrelfish] / usr / skb / programs / decodingNetSKB.pl
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Copyright (c) 2017, ETH Zurich.
3 % All rights reserved.
4 %
5 % This file is distributed under the terms in the attached LICENSE file.
6 % If you do not find this file, copies can be found by writing to:
7 % ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich.
8 % Attn: Systems Group.
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
11 :- use_module(decodingNet).
12 :- use_module(decodingNetQueries).
13 :- local loadnet/1.
14
15 %%%%%%%%%%%%%%
16 %% Printing %%
17 %%%%%%%%%%%%%%
18 printRegion((Id,Addr,Size)) :-
19     End is Addr + Size - 1,
20     printf("%a [0x%16R..0x%16R]",
21         [ Id,Addr,End ]
22     ).
23
24 printSrcDestRegions((SrcRegion,DestRegion)) :-
25     printRegion(SrcRegion),
26     write(" -> "),
27     printRegion(DestRegion),
28     writeln("").
29
30 printSharedRegions((Region1,Region2,SharedRegion)) :-
31     printRegion(Region1),
32     write(" -> "),
33     printRegion(SharedRegion),
34     write(" <- "),
35     printRegion(Region2),
36     writeln("").
37
38
39 %%%%%%%%%%%%%%%%%%%%%%%
40 %% Helper predicates %%
41 %%%%%%%%%%%%%%%%%%%%%%%
42 loadnet(Name) :- 
43     concat_string(["sockeyefacts/",Name],File),
44     decodingNet:loadnet(File).
45
46 all(Pred) :- findall(_,Pred,_).
47
48
49 %%%%%%%%%%%%%
50 %% Queries %%
51 %%%%%%%%%%%%%
52 findTargetRegion(NodeId) :-
53     findTargetRegion(NodeId,Result),
54     printSrcDestRegions(Result).
55
56 findOriginRegion(NodeId) :-
57     findOriginRegion(NodeId,Result),
58     printSrcDestRegions(Result).
59
60 findDeviceRegion(NodeId,DeviceId) :-
61     findDeviceRegion(NodeId,DeviceId,Result),
62     printSrcDestRegions(Result).
63
64 findMemoryRegion(NodeId,MemoryId) :-
65     findMemoryRegion(NodeId,MemoryId,Result),
66     printSrcDestRegions(Result).
67
68 findSharedMemoryRegion(NodeId,DeviceId) :-
69     findSharedMemoryRegion(NodeId,DeviceId,Result),
70     printSharedRegions(Result).
71
72 findDeviceId(NodeId,Addr) :-
73     findDeviceId(NodeId,Addr,Result),
74     writeln(Result).
75
76 findInterruptLine(NodeId,DeviceId) :-
77     findInterruptLine(NodeId,DeviceId,Result),
78     printSrcDestRegions(Result).