SKB: Adapt decoding net scripts to use struct notation
authorDaniel Schwyn <schwyda@student.ethz.ch>
Mon, 11 Sep 2017 15:05:36 +0000 (17:05 +0200)
committerDaniel Schwyn <schwyda@student.ethz.ch>
Mon, 11 Sep 2017 15:05:36 +0000 (17:05 +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

index 5591ccd..ed6ed9c 100644 (file)
@@ -9,23 +9,36 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 :- module(decodingNet).
-:- export net/2.
 :- export loadnet/1.
 :- export resolve/2.
 :- export toRegion/2.
+:- export node/2.
+
+:- dynamic node/2.
+
+:- export struct(node(id:nodeId,spec:nodeSpec)).
+:- export struct(nodeId(name,namespace)).
+:- export struct(nodeSpec(type,accept,translate)).
+:- local struct(map(srcBlock,destNode,destBase)).
+:- local struct(block(base,limit)).
+
+:- export struct(name(nodeId:nodeId,address)).
+:- export struct(region(nodeId:nodeId,base,size)).
 
 :- lib(ic).
 
 :- set_flag(syntax_option,based_bignums).
 :- set_flag(syntax_option,iso_base_prefix).
 
-:- dynamic net/2.
-
 %% Load a precompiled decoding net
 loadnet(File) :- [File].
 
 %% Address range in block
-blockRange(block(Base,Limit),Range) :-
+blockRange(Block,Range) :-
+    block{
+        base:Base,
+        limit:Limit
+    } = Block,
     Range = Base..Limit.
 
 %% Address ranges in block list
@@ -41,57 +54,87 @@ blockListRanges(Blocks,Ranges) :-
 %% Extract block ranges from map list
 mapListRanges(Maps,Ranges) :-
     (
-        foreach(map(Block,_,_),Maps),
+        foreach(map{srcBlock:Block},Maps),
         fromto([],Prev,Next,Blocks)
     do
         Next = [Block|Prev]
     ),
     blockListRanges(Blocks,Ranges).
 
-mapsToName(map(SrcBlock,Dest,DestBase),Addr,Name) :-
-    name(Dest,DestAddr) = Name,
+mapsToName(Map,Addr,Name) :-
+    map{
+        srcBlock:SrcBlock,
+        destNode:Dest,
+        destBase:DestBase
+    } = Map,
+    name{
+        nodeId:Dest,
+        address:DestAddr
+    } = Name,
     blockRange(SrcBlock,Range),
     Addr :: Range,
-    block(SrcBase,_) = SrcBlock,
+    block{base:SrcBase} = SrcBlock,
     DestAddr #= Addr - SrcBase + DestBase.
 
 listMapsToName([M|Maps],Addr,Name) :-
     mapsToName(M,Addr,Name);
     listMapsToName(Maps,Addr,Name).    
 
-translateMap(node(_,_,Translate),Addr,Name) :-
+translateMap(NodeSpec,Addr,Name) :-
+    nodeSpec{translate:Translate} = NodeSpec,
     listMapsToName(Translate,Addr,Name).
 
 translate(Node,Addr,Name) :-
     translateMap(Node,Addr,Name).
 
-accept(node(_,Accept,_),Addr) :-
+accept(NodeSpec,Addr) :-
+    nodeSpec{accept:Accept} = NodeSpec,
     blockListRanges(Accept,Ranges),
     Addr :: Ranges.
 
-acceptedName(name(NodeId,Addr)) :-
-    net(NodeId,Node),
-    accept(Node,Addr).
+acceptedName(Name) :-
+    name{
+        nodeId:NodeId,
+        address:Addr
+    } = Name,
+    node{
+        id:NodeId,
+        spec:NodeSpec
+    },
+    accept(NodeSpec,Addr).
+
+decodeStep(SrcName,DestName) :-
+    name{
+        nodeId:NodeId,
+        address:Addr
+    } = SrcName,
+    node{
+        id:NodeId,
+        spec:NodeSpec
+    },
+    translate(NodeSpec,Addr,DestName).
 
-decodeStep(name(NodeId,Addr),Name) :-
-    net(NodeId,Node),
-    translate(Node,Addr,Name).
+decodesTo(SrcName,DestName) :-
+    SrcName = DestName.
 
 decodesTo(SrcName,DestName) :-
     decodeStep(SrcName,Name),
-    (   DestName = Name
-    ;   decodesTo(Name,DestName)
-    ).
+    decodesTo(Name,DestName).
 
 resolve(SrcName,DestName) :-
-    (   DestName = SrcName
-    ;   decodesTo(SrcName,DestName)
-    ),
+    decodesTo(SrcName,DestName),
     acceptedName(DestName).
 
 toRegion(Name,Region) :-
-    name(Id,Addr) = Name,
+    name{
+        nodeId:Id,
+        address:Addr
+    } = Name,
     get_min(Addr,Min),get_max(Addr,Max),
     Size is Max - Min + 1,
-    Region = (Id, Min, Size).
+    Region = region{
+        nodeId:Id,
+        base:Min,
+        size:Size
+    }.
   
\ No newline at end of file
index db892f4..7c716ea 100644 (file)
@@ -33,35 +33,44 @@ resolveToRegion(SrcName,DestName,SrcRegion,DestRegion) :-
 %% Queries %%
 %%%%%%%%%%%%%
 findTargetRegion(NodeId,Result) :-
-    SrcName = name(NodeId,_),
+    SrcName = name{nodeId:NodeId},
     resolveToRegion(SrcName,_,SrcRegion,DestRegion),
     Result = (SrcRegion,DestRegion).
 
 findOriginRegion(NodeId,Result) :-
-    DestName = name(NodeId,_),
+    DestName = name{nodeId:NodeId},
     resolveToRegion(_,DestName,SrcRegion,DestRegion),
     Result = (SrcRegion,DestRegion).
 
 %% Address space queries
 findDeviceRegion(NodeId,DeviceId,Result) :-
-    SrcName = name(NodeId,_),
-    DestName = name(DeviceId,_),
-    net(DeviceId,node(device,_,_)),
+    SrcName = name{nodeId:NodeId},
+    DestName = name{nodeId:DeviceId},
+    node{
+        id:DeviceId,
+        type:device
+    },
     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
     Result = (SrcRegion,DestRegion).
 
 findMemoryRegion(NodeId,MemoryId,Result) :-
-    SrcName = name(NodeId,_),
-    DestName = name(MemoryId,_),
-    net(MemoryId,node(memory,_,_)),
+    SrcName = name{nodeId:NodeId},
+    DestName = name{nodeId:MemoryId},
+    node{
+        id:MemoryId,
+        type:memory
+    },
     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
     Result = (SrcRegion,DestRegion).
 
 findSharedMemoryRegion(NodeId,DeviceId,Result) :-
-    NodeName = name(NodeId,_),
-    DeviceName = name(DeviceId,_),
-    SharedName = name(SharedId,_),
-    net(SharedId,node(memory,_,_)),
+    NodeName = name{nodeId:NodeId},
+    DeviceName = name{nodeId:DeviceId},
+    SharedName = name{nodeId:SharedId},
+    node{
+        id:SharedId,
+        type:memory
+    },
     resolve(NodeName,SharedName),
     resolve(DeviceName,SharedName),
     toRegion(NodeName,NodeRegion),
@@ -70,13 +79,17 @@ findSharedMemoryRegion(NodeId,DeviceId,Result) :-
     Result = (NodeRegion,DeviceRegion,SharedRegion).
 
 findDeviceId(NodeId,Addr,Result) :-
-    SrcName = name(NodeId,Addr),
-    resolve(SrcName,name(DeviceId,_)),
+    SrcName = name{
+        nodeId:NodeId,
+        address:Addr
+    },
+    DestName = name{nodeId:DeviceId},
+    resolve(SrcName,DestName),
     Result = DeviceId.
 
 %% Interrupt queries
 findInterruptLine(NodeId,DeviceId,Result) :-
-    SrcName = name(DeviceId,_),
-    DestName = name(NodeId,_),
+    SrcName = name{nodeId:DeviceId},
+    DestName = name{nodeId:NodeId},
     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
     Result = (SrcRegion,DestRegion).
\ No newline at end of file
index c6a2f53..063c47f 100644 (file)
 %%%%%%%%%%%%%%
 %% Printing %%
 %%%%%%%%%%%%%%
-printNodeid(nodeId(Name, Namespace)) :-
+printNodeid(NodeId) :-
+    nodeId{
+        name:Name,
+        namespace:Namespace
+    } = NodeId,
     reverse([Name|Namespace], IdList),
     join_string(IdList,".",String),
     write(String).
 
-printRegion((Id,Addr,Size)) :-
+printRegion(Region) :-
+    region{
+        nodeId:Id,
+        base:Addr,
+        size:Size
+    } = Region,
     End is Addr + Size - 1,
     printNodeid(Id),
     printf(" [0x%16R..0x%16R]",