Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sasa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
verimag
synchrone
sasa
Commits
846612bb
Commit
846612bb
authored
4 years ago
by
Gabriel B. Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Optionally clock generated code
parent
8007cdab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dot2lus.ml
+57
-29
57 additions, 29 deletions
dot2lus.ml
with
57 additions
and
29 deletions
dot2lus.ml
+
57
−
29
View file @
846612bb
...
@@ -9,6 +9,8 @@ let action_type = "action"
...
@@ -9,6 +9,8 @@ let action_type = "action"
let
action_number
=
"actions_number"
let
action_number
=
"actions_number"
let
action_of_int
=
"action_of_int"
let
action_of_int
=
"action_of_int"
let
clock
=
ref
false
let
algo_name
(
node
:
Topology
.
node
)
=
Filename
.
chop_suffix
node
.
file
".ml"
let
algo_name
(
node
:
Topology
.
node
)
=
Filename
.
chop_suffix
node
.
file
".ml"
...
@@ -39,11 +41,13 @@ function _first_set<<const N:int>>(s : bool^N) returns (x : int);
...
@@ -39,11 +41,13 @@ function _first_set<<const N:int>>(s : bool^N) returns (x : int);
var
var
found : int;
found : int;
let
let
found = with (N = 1) then (if s[0] then 0 else -1)
found =
else _first_set<<N-1>>(s[1 .. N-1]);
with (N = 1) then (if s[0] then 0 else -1)
x = if s[0] then 0
else _first_set<<N-1>>(s[1 .. N-1]);
else if found < 0 then -1
x =
else found + 1;
if s[0] then 0
else if found < 0 then -1
else found + 1;
tel;
\n
"
;
tel;
\n
"
;
Printf
.
fprintf
output
"
Printf
.
fprintf
output
"
...
@@ -62,16 +66,16 @@ let output_topology output (graph : Topology.t) name =
...
@@ -62,16 +66,16 @@ let output_topology output (graph : Topology.t) name =
|>
List
.
iteri
(
fun
index
node_id
->
Hashtbl
.
add
index_map
node_id
index
);
|>
List
.
iteri
(
fun
index
node_id
->
Hashtbl
.
add
index_map
node_id
index
);
Hashtbl
.
find
index_map
(* returns the partially applied find *)
in
Hashtbl
.
find
index_map
(* returns the partially applied find *)
in
let
sprint_neighbor_list
neighbor_ids
:
string
=
let
index_of_id
=
make_index
graph
in
let
sprint_neighbor_list
neighbor_ids
list
:
string
=
match
neighbor_ids
with
match
neighbor_ids
with
|
[]
->
"[]"
|
[]
->
"[]"
|
n
::
ns
->
|
n
::
ns
->
let
prefix
,
sufix
=
Printf
.
sprintf
"[
node
s[%d]"
n
,
" ]"
in
let
prefix
,
sufix
=
Printf
.
sprintf
"[
%
s[%d]"
list
n
,
" ]"
in
let
concat
acc
n
=
acc
^
(
Printf
.
sprintf
",
node
s[%d]"
n
)
in
let
concat
acc
n
=
acc
^
(
Printf
.
sprintf
",
%
s[%d]"
list
n
)
in
(
List
.
fold_left
concat
prefix
ns
)
^
sufix
in
(
List
.
fold_left
concat
prefix
ns
)
^
sufix
in
let
index_of_id
=
make_index
graph
in
Printf
.
fprintf
output
Printf
.
fprintf
output
"
\n
node %s(activations : bool^%s^card; initials : %s^card)
\n
"
"
\n
node %s(activations : bool^%s^card; initials : %s^card)
\n
"
name
action_number
state_type
;
name
action_number
state_type
;
...
@@ -82,11 +86,13 @@ let output_topology output (graph : Topology.t) name =
...
@@ -82,11 +86,13 @@ let output_topology output (graph : Topology.t) name =
output_string
output
"var
\n
"
;
output_string
output
"var
\n
"
;
Printf
.
fprintf
output
"
\t
prev_nodes : %s^card;
\n\n
"
state_type
;
graph
.
nodes
graph
.
nodes
|>
List
.
iteri
(
fun
i
_
->
Printf
.
fprintf
output
"
\t
sel_%d : bool;
\n
"
i
);
|>
List
.
iteri
(
fun
i
_
->
Printf
.
fprintf
output
"
\t
sel_%d : bool;
\n
"
i
);
output_string
output
"let
\n
"
;
output_string
output
"let
\n
"
;
output_string
output
"
\t
prev_nodes = initials -> pre(nodes);
\n\n
"
;
graph
.
nodes
graph
.
nodes
|>
List
.
iteri
(
fun
i
_
->
|>
List
.
iteri
(
fun
i
_
->
Printf
.
fprintf
output
Printf
.
fprintf
output
...
@@ -98,32 +104,54 @@ let output_topology output (graph : Topology.t) name =
...
@@ -98,32 +104,54 @@ let output_topology output (graph : Topology.t) name =
let
algo
=
algo_name
n
in
let
algo
=
algo_name
n
in
let
neighbors
=
graph
.
succ
n
.
id
|>
List
.
map
(
fun
(
_
,
id
)
->
index_of_id
id
)
in
let
neighbors
=
graph
.
succ
n
.
id
|>
List
.
map
(
fun
(
_
,
id
)
->
index_of_id
id
)
in
let
deg
=
List
.
length
neighbors
in
let
deg
=
List
.
length
neighbors
in
let
nl
=
sprint_neighbor_list
neighbors
in
let
nl
=
sprint_neighbor_list
neighbors
"nodes"
in
Printf
.
fprintf
output
"
let
pnl
=
sprint_neighbor_list
neighbors
"prev_nodes"
in
nodes[%d] = initials[%d] ->
Printf
.
fprintf
output
if sel_%d
"
\t
nodes[%d] =
\n\t\t
if not sel_%d then prev_nodes[%d]
\n\t\t
else "
then %s_step<<%d>>(pre(nodes[%d]), pre(%s), _action_of_activation(activations[%d]))
i
i
i
;
else pre(nodes[%d]);
if
!
clock
then
Printf
.
fprintf
output
enables[%d] = %s_enable<<%d>>(nodes[%d], %s);
\n
"
"current(%s_step<<%d>>(prev_nodes[%d], %s, _action_of_activation(activations[%d])) when sel_%d);
\n
"
i
i
i
algo
deg
i
nl
i
i
i
algo
deg
i
nl
);
algo
deg
i
pnl
i
i
else
Printf
.
fprintf
output
"%s_step<<%d>>(prev_nodes[%d], %s, _action_of_activation(activations[%d]));
\n
"
algo
deg
i
pnl
i
;
Printf
.
fprintf
output
"
\t
enables[%d] = %s_enable<<%d>>(nodes[%d], %s);
\n
"
i
algo
deg
i
nl
);
output_string
output
"tel;
\n
"
output_string
output
"tel;
\n
"
let
graph2lus
graph
name
=
let
dot2lus
dotfile
lusfile
=
let
output
=
open_out
(
name
^
".lus"
)
in
let
graph
=
Topology
.
read
dotfile
in
let
name
=
dotfile
|>
Filename
.
basename
|>
Filename
.
chop_extension
in
let
output
=
match
lusfile
with
|
None
->
open_out
(
name
^
".lus"
)
|
Some
lus
->
open_out
lus
in
output_prelude
output
graph
;
output_prelude
output
graph
;
output_topology
output
graph
name
;
output_topology
output
graph
name
;
close_out
output
close_out
output
let
dot2lus
dotfile
=
let
graph
=
Topology
.
read
dotfile
in
let
name
=
dotfile
|>
Filename
.
basename
|>
Filename
.
chop_extension
in
graph2lus
graph
name
let
_
=
let
_
=
match
Array
.
length
Sys
.
argv
with
let
usage
=
"dot2lus <dotfile> [-o lusfile] [--clock] [--help]"
in
|
2
->
dot2lus
Sys
.
argv
.
(
1
)
let
dotfile
=
ref
""
in
|
_
->
print_string
"usage: dot2lus <dotfile>
\n
"
;
exit
1
let
lusfile
=
ref
""
in
let
anon_parse
arg
=
match
!
dotfile
with
|
""
->
dotfile
:=
arg
|
_
->
raise
(
Arg
.
Bad
"multiple input topologies not supported"
)
in
let
speclist
=
[
(
"-o"
,
Arg
.
Set_string
lusfile
,
"Set output file"
);
(
"--clock"
,
Arg
.
Set
clock
,
"Generate clocked code (default is unclocked)"
)
]
in
Arg
.
parse
speclist
anon_parse
usage
;
match
!
dotfile
with
|
""
->
print_string
(
Arg
.
usage_string
speclist
usage
);
exit
1
|
dot
->
match
!
lusfile
with
|
""
->
dot2lus
dot
None
|
lus
->
dot2lus
dot
(
Some
lus
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment