Prolog code style fixes
authorDaniel Schwyn <schwyda@student.ethz.ch>
Thu, 14 Sep 2017 15:49:12 +0000 (17:49 +0200)
committerDaniel Schwyn <schwyda@student.ethz.ch>
Thu, 14 Sep 2017 15:49:12 +0000 (17:49 +0200)
- snake case for atoms/predicates/modules/file names

Signed-off-by: Daniel Schwyn <schwyda@student.ethz.ch>

tools/sockeye/SockeyeBackendProlog.hs
usr/skb/programs/decodingNetQueries.pl [deleted file]
usr/skb/programs/decodingNetSKB.pl [deleted file]
usr/skb/programs/decoding_net.pl [moved from usr/skb/programs/decodingNet.pl with 54% similarity]
usr/skb/programs/decoding_net_queries.pl [new file with mode: 0644]
usr/skb/programs/decoding_net_skb.pl [new file with mode: 0644]

index f46206a..929ffb9 100644 (file)
@@ -48,14 +48,14 @@ instance PrologGenerator AST.NodeId where
     generate ast = let
         name = AST.name ast
         namespace = AST.namespace ast
-        in struct "nodeId" [("name", atom name), ("namespace", list $ map atom namespace)]
+        in struct "node_id" [("name", atom name), ("namespace", list $ map atom namespace)]
 
 instance PrologGenerator AST.NodeSpec where
     generate ast = let
         nodeType = generate $ AST.nodeType ast
         accept = generate $ AST.accept ast
         translate = generate $ AST.translate ast
-        in struct "nodeSpec" [("type", nodeType), ("accept", accept), ("translate", translate)]
+        in struct "node_spec" [("type", nodeType), ("accept", accept), ("translate", translate)]
 
 instance PrologGenerator AST.BlockSpec where
     generate blockSpec = let
@@ -68,7 +68,7 @@ instance PrologGenerator AST.MapSpec where
         src  = generate $ AST.srcBlock mapSpec
         dest = generate $ AST.destNode mapSpec
         base = generate $ AST.destBase mapSpec
-        in struct "map" [("srcBlock", src), ("destNode", dest), ("destBase", base)]
+        in struct "map" [("src_block", src), ("dest_node", dest), ("dest_base", base)]
 
 instance PrologGenerator AST.NodeType where
     generate AST.Core   = atom "core"
diff --git a/usr/skb/programs/decodingNetQueries.pl b/usr/skb/programs/decodingNetQueries.pl
deleted file mode 100644 (file)
index 7c716ea..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 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.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-:- module(decodingNetQueries).
-:- export findTargetRegion/2.
-:- export findOriginRegion/2.
-:- export findDeviceRegion/3.
-:- export findMemoryRegion/3.
-:- export findSharedMemoryRegion/3.
-:- export findDeviceId/3.
-:- export findInterruptLine/3.
-
-:- use_module(decodingNet).
-
-
-%%%%%%%%%%%%%%%%%%%%%%%
-%% Helper predicates %%
-%%%%%%%%%%%%%%%%%%%%%%%
-resolveToRegion(SrcName,DestName,SrcRegion,DestRegion) :-
-    resolve(SrcName,DestName),
-    toRegion(SrcName,SrcRegion),
-    toRegion(DestName,DestRegion).
-
-
-%%%%%%%%%%%%%
-%% Queries %%
-%%%%%%%%%%%%%
-findTargetRegion(NodeId,Result) :-
-    SrcName = name{nodeId:NodeId},
-    resolveToRegion(SrcName,_,SrcRegion,DestRegion),
-    Result = (SrcRegion,DestRegion).
-
-findOriginRegion(NodeId,Result) :-
-    DestName = name{nodeId:NodeId},
-    resolveToRegion(_,DestName,SrcRegion,DestRegion),
-    Result = (SrcRegion,DestRegion).
-
-%% Address space queries
-findDeviceRegion(NodeId,DeviceId,Result) :-
-    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: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:NodeId},
-    DeviceName = name{nodeId:DeviceId},
-    SharedName = name{nodeId:SharedId},
-    node{
-        id:SharedId,
-        type:memory
-    },
-    resolve(NodeName,SharedName),
-    resolve(DeviceName,SharedName),
-    toRegion(NodeName,NodeRegion),
-    toRegion(SharedName,SharedRegion),
-    toRegion(DeviceName,DeviceRegion),
-    Result = (NodeRegion,DeviceRegion,SharedRegion).
-
-findDeviceId(NodeId,Addr,Result) :-
-    SrcName = name{
-        nodeId:NodeId,
-        address:Addr
-    },
-    DestName = name{nodeId:DeviceId},
-    resolve(SrcName,DestName),
-    Result = DeviceId.
-
-%% Interrupt queries
-findInterruptLine(NodeId,DeviceId,Result) :-
-    SrcName = name{nodeId:DeviceId},
-    DestName = name{nodeId: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
deleted file mode 100644 (file)
index 063c47f..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 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 %%
-%%%%%%%%%%%%%%
-printNodeid(NodeId) :-
-    nodeId{
-        name:Name,
-        namespace:Namespace
-    } = NodeId,
-    reverse([Name|Namespace], IdList),
-    join_string(IdList,".",String),
-    write(String).
-
-printRegion(Region) :-
-    region{
-        nodeId:Id,
-        base:Addr,
-        size:Size
-    } = Region,
-    End is Addr + Size - 1,
-    printNodeid(Id),
-    printf(" [0x%16R..0x%16R]",
-        [ 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
similarity index 54%
rename from usr/skb/programs/decodingNet.pl
rename to usr/skb/programs/decoding_net.pl
index ed6ed9c..da11809 100644 (file)
@@ -8,22 +8,22 @@
 % Attn: Systems Group.
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-:- module(decodingNet).
-:- export loadnet/1.
+:- module(decoding_net).
+:- export load_net/1.
 :- export resolve/2.
-:- export toRegion/2.
+:- export to_region/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)).
+:- export struct(node(id:node_id,spec:node_spec)).
+:- export struct(node_id(name,namespace)).
+:- export struct(node_spec(type,accept,translate)).
+:- local struct(map(src_block,dest_node,dest_base)).
 :- local struct(block(base,limit)).
 
-:- export struct(name(nodeId:nodeId,address)).
-:- export struct(region(nodeId:nodeId,base,size)).
+:- export struct(name(node_id:node_id,address)).
+:- export struct(region(node_id:node_id,base,size)).
 
 :- lib(ic).
 
 :- set_flag(syntax_option,iso_base_prefix).
 
 %% Load a precompiled decoding net
-loadnet(File) :- [File].
+load_net(File) :- [File].
 
 %% Address range in block
-blockRange(Block,Range) :-
+block_range(Block,Range) :-
     block{
         base:Base,
         limit:Limit
@@ -42,59 +42,59 @@ blockRange(Block,Range) :-
     Range = Base..Limit.
 
 %% Address ranges in block list
-blockListRanges(Blocks,Ranges) :-
+block_list_ranges(Blocks,Ranges) :-
     (
         foreach(Block,Blocks),
         fromto([],Prev,Next,Ranges)
     do
-        blockRange(Block,Range),
+        block_range(Block,Range),
         Next = [Range|Prev]
     ).
     
 %% Extract block ranges from map list
-mapListRanges(Maps,Ranges) :-
+map_list_ranges(Maps,Ranges) :-
     (
-        foreach(map{srcBlock:Block},Maps),
+        foreach(map{src_block:Block},Maps),
         fromto([],Prev,Next,Blocks)
     do
         Next = [Block|Prev]
     ),
-    blockListRanges(Blocks,Ranges).
+    block_list_ranges(Blocks,Ranges).
 
-mapsToName(Map,Addr,Name) :-
+maps_to_name(Map,Addr,Name) :-
     map{
-        srcBlock:SrcBlock,
-        destNode:Dest,
-        destBase:DestBase
+        src_block:SrcBlock,
+        dest_node:Dest,
+        dest_base:DestBase
     } = Map,
     name{
-        nodeId:Dest,
+        node_id:Dest,
         address:DestAddr
     } = Name,
-    blockRange(SrcBlock,Range),
+    block_range(SrcBlock,Range),
     Addr :: Range,
     block{base:SrcBase} = SrcBlock,
     DestAddr #= Addr - SrcBase + DestBase.
 
-listMapsToName([M|Maps],Addr,Name) :-
-    mapsToName(M,Addr,Name);
-    listMapsToName(Maps,Addr,Name).    
+list_maps_to_name([M|Maps],Addr,Name) :-
+    maps_to_name(M,Addr,Name);
+    list_maps_to_name(Maps,Addr,Name).    
 
-translateMap(NodeSpec,Addr,Name) :-
-    nodeSpec{translate:Translate} = NodeSpec,
-    listMapsToName(Translate,Addr,Name).
+translate_map(NodeSpec,Addr,Name) :-
+    node_spec{translate:Translate} = NodeSpec,
+    list_maps_to_name(Translate,Addr,Name).
 
 translate(Node,Addr,Name) :-
-    translateMap(Node,Addr,Name).
+    translate_map(Node,Addr,Name).
 
 accept(NodeSpec,Addr) :-
-    nodeSpec{accept:Accept} = NodeSpec,
-    blockListRanges(Accept,Ranges),
+    node_spec{accept:Accept} = NodeSpec,
+    block_list_ranges(Accept,Ranges),
     Addr :: Ranges.
 
-acceptedName(Name) :-
+accepted_name(Name) :-
     name{
-        nodeId:NodeId,
+        node_id:NodeId,
         address:Addr
     } = Name,
     node{
@@ -103,9 +103,9 @@ acceptedName(Name) :-
     },
     accept(NodeSpec,Addr).
 
-decodeStep(SrcName,DestName) :-
+decode_step(SrcName,DestName) :-
     name{
-        nodeId:NodeId,
+        node_id:NodeId,
         address:Addr
     } = SrcName,
     node{
@@ -114,26 +114,26 @@ decodeStep(SrcName,DestName) :-
     },
     translate(NodeSpec,Addr,DestName).
 
-decodesTo(SrcName,DestName) :-
+decodes_to(SrcName,DestName) :-
     SrcName = DestName.
 
-decodesTo(SrcName,DestName) :-
-    decodeStep(SrcName,Name),
-    decodesTo(Name,DestName).
+decodes_to(SrcName,DestName) :-
+    decode_step(SrcName,Name),
+    decodes_to(Name,DestName).
 
 resolve(SrcName,DestName) :-
-    decodesTo(SrcName,DestName),
-    acceptedName(DestName).
+    decodes_to(SrcName,DestName),
+    accepted_name(DestName).
 
-toRegion(Name,Region) :-
+to_region(Name,Region) :-
     name{
-        nodeId:Id,
+        node_id:Id,
         address:Addr
     } = Name,
     get_min(Addr,Min),get_max(Addr,Max),
     Size is Max - Min + 1,
     Region = region{
-        nodeId:Id,
+        node_id:Id,
         base:Min,
         size:Size
     }.
diff --git a/usr/skb/programs/decoding_net_queries.pl b/usr/skb/programs/decoding_net_queries.pl
new file mode 100644 (file)
index 0000000..edef76a
--- /dev/null
@@ -0,0 +1,95 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% 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.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+:- module(decoding_net_queries).
+:- export find_target_region/2.
+:- export find_origin_region/2.
+:- export find_device_region/3.
+:- export find_memory_region/3.
+:- export find_shared_memory_region/3.
+:- export find_device_id/3.
+:- export find_interrupt_line/3.
+
+:- use_module(decoding_net).
+
+
+%%%%%%%%%%%%%%%%%%%%%%%
+%% Helper predicates %%
+%%%%%%%%%%%%%%%%%%%%%%%
+resolve_to_region(SrcName,DestName,SrcRegion,DestRegion) :-
+    resolve(SrcName,DestName),
+    to_region(SrcName,SrcRegion),
+    to_region(DestName,DestRegion).
+
+
+%%%%%%%%%%%%%
+%% Queries %%
+%%%%%%%%%%%%%
+find_target_region(NodeId,Result) :-
+    SrcName = name{node_id:NodeId},
+    resolve_to_region(SrcName,_,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
+
+find_origin_region(NodeId,Result) :-
+    DestName = name{node_id:NodeId},
+    resolve_to_region(_,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
+
+%% Address space queries
+find_device_region(NodeId,DeviceId,Result) :-
+    SrcName = name{node_id:NodeId},
+    DestName = name{node_id:DeviceId},
+    node{
+        id:DeviceId,
+        type:device
+    },
+    resolve_to_region(SrcName,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
+
+find_memory_region(NodeId,MemoryId,Result) :-
+    SrcName = name{node_id:NodeId},
+    DestName = name{node_id:MemoryId},
+    node{
+        id:MemoryId,
+        type:memory
+    },
+    resolve_to_region(SrcName,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
+
+find_shared_memory_region(NodeId,DeviceId,Result) :-
+    NodeName = name{node_id:NodeId},
+    DeviceName = name{node_id:DeviceId},
+    SharedName = name{node_id:SharedId},
+    node{
+        id:SharedId,
+        type:memory
+    },
+    resolve(NodeName,SharedName),
+    resolve(DeviceName,SharedName),
+    to_region(NodeName,NodeRegion),
+    to_region(SharedName,SharedRegion),
+    to_region(DeviceName,DeviceRegion),
+    Result = (NodeRegion,DeviceRegion,SharedRegion).
+
+find_device_id(NodeId,Addr,Result) :-
+    SrcName = name{
+        node_id:NodeId,
+        address:Addr
+    },
+    DestName = name{node_id:DeviceId},
+    resolve(SrcName,DestName),
+    Result = DeviceId.
+
+%% Interrupt queries
+find_interrupt_line(NodeId,DeviceId,Result) :-
+    SrcName = name{node_id:DeviceId},
+    DestName = name{node_id:NodeId},
+    resolve_to_region(SrcName,DestName,SrcRegion,DestRegion),
+    Result = (SrcRegion,DestRegion).
\ No newline at end of file
diff --git a/usr/skb/programs/decoding_net_skb.pl b/usr/skb/programs/decoding_net_skb.pl
new file mode 100644 (file)
index 0000000..0507d90
--- /dev/null
@@ -0,0 +1,93 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% 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(decoding_net).
+:- use_module(decoding_net_queries).
+:- local load_net/1.
+
+%%%%%%%%%%%%%%
+%% Printing %%
+%%%%%%%%%%%%%%
+print_node_id(NodeId) :-
+    node_id{
+        name:Name,
+        namespace:Namespace
+    } = NodeId,
+    reverse([Name|Namespace], IdList),
+    join_string(IdList,".",String),
+    write(String).
+
+print_region(Region) :-
+    region{
+        node_id:Id,
+        base:Addr,
+        size:Size
+    } = Region,
+    End is Addr + Size - 1,
+    print_node_id(Id),
+    printf(" [0x%16R..0x%16R]",
+        [ Addr,End ]
+    ).
+
+print_src_dest_regions((SrcRegion,DestRegion)) :-
+    print_region(SrcRegion),
+    write(" -> "),
+    print_region(DestRegion),
+    writeln("").
+
+print_shared_regions((Region1,Region2,SharedRegion)) :-
+    print_region(Region1),
+    write(" -> "),
+    print_region(SharedRegion),
+    write(" <- "),
+    print_region(Region2),
+    writeln("").
+
+
+%%%%%%%%%%%%%%%%%%%%%%%
+%% Helper predicates %%
+%%%%%%%%%%%%%%%%%%%%%%%
+load_net(Name) :- 
+    concat_string(["sockeyefacts/",Name],File),
+    decoding_net:load_net(File).
+
+all(Pred) :- findall(_,Pred,_).
+
+
+%%%%%%%%%%%%%
+%% Queries %%
+%%%%%%%%%%%%%
+find_target_region(NodeId) :-
+    find_target_region(NodeId,Result),
+    print_src_dest_regions(Result).
+
+find_origin_region(NodeId) :-
+    find_origin_region(NodeId,Result),
+    print_src_dest_regions(Result).
+
+find_device_region(NodeId,DeviceId) :-
+    find_device_region(NodeId,DeviceId,Result),
+    print_src_dest_regions(Result).
+
+find_memory_region(NodeId,MemoryId) :-
+    find_memory_region(NodeId,MemoryId,Result),
+    print_src_dest_regions(Result).
+
+find_shared_memory_region(NodeId,DeviceId) :-
+    find_shared_memory_region(NodeId,DeviceId,Result),
+    print_shared_regions(Result).
+
+find_device_id(NodeId,Addr) :-
+    find_device_id(NodeId,Addr,Result),
+    writeln(Result).
+
+find_interrupt_line(NodeId,DeviceId) :-
+    find_interrupt_line(NodeId,DeviceId,Result),
+    print_src_dest_regions(Result).
\ No newline at end of file