SKB: Adapt decoding net scripts to use struct notation
[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 printNodeid(NodeId) :-
19     nodeId{
20         name:Name,
21         namespace:Namespace
22     } = NodeId,
23     reverse([Name|Namespace], IdList),
24     join_string(IdList,".",String),
25     write(String).
26
27 printRegion(Region) :-
28     region{
29         nodeId:Id,
30         base:Addr,
31         size:Size
32     } = Region,
33     End is Addr + Size - 1,
34     printNodeid(Id),
35     printf(" [0x%16R..0x%16R]",
36         [ Addr,End ]
37     ).
38
39 printSrcDestRegions((SrcRegion,DestRegion)) :-
40     printRegion(SrcRegion),
41     write(" -> "),
42     printRegion(DestRegion),
43     writeln("").
44
45 printSharedRegions((Region1,Region2,SharedRegion)) :-
46     printRegion(Region1),
47     write(" -> "),
48     printRegion(SharedRegion),
49     write(" <- "),
50     printRegion(Region2),
51     writeln("").
52
53
54 %%%%%%%%%%%%%%%%%%%%%%%
55 %% Helper predicates %%
56 %%%%%%%%%%%%%%%%%%%%%%%
57 loadnet(Name) :- 
58     concat_string(["sockeyefacts/",Name],File),
59     decodingNet:loadnet(File).
60
61 all(Pred) :- findall(_,Pred,_).
62
63
64 %%%%%%%%%%%%%
65 %% Queries %%
66 %%%%%%%%%%%%%
67 findTargetRegion(NodeId) :-
68     findTargetRegion(NodeId,Result),
69     printSrcDestRegions(Result).
70
71 findOriginRegion(NodeId) :-
72     findOriginRegion(NodeId,Result),
73     printSrcDestRegions(Result).
74
75 findDeviceRegion(NodeId,DeviceId) :-
76     findDeviceRegion(NodeId,DeviceId,Result),
77     printSrcDestRegions(Result).
78
79 findMemoryRegion(NodeId,MemoryId) :-
80     findMemoryRegion(NodeId,MemoryId,Result),
81     printSrcDestRegions(Result).
82
83 findSharedMemoryRegion(NodeId,DeviceId) :-
84     findSharedMemoryRegion(NodeId,DeviceId,Result),
85     printSharedRegions(Result).
86
87 findDeviceId(NodeId,Addr) :-
88     findDeviceId(NodeId,Addr,Result),
89     writeln(Result).
90
91 findInterruptLine(NodeId,DeviceId) :-
92     findInterruptLine(NodeId,DeviceId,Result),
93     printSrcDestRegions(Result).