OpenCores
URL https://opencores.org/ocsvn/mpeg2fpga/mpeg2fpga/trunk

Subversion Repositories mpeg2fpga

[/] [mpeg2fpga/] [trunk/] [tools/] [fsmgraph/] [mkfsmgraph] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kdv
#!/usr/bin/perl
2
 
3
# code used to generate the state machine graph.
4
# input: verilog code
5
# output: gml graph
6
# use: mkgraph < vld.v > vld.gml
7
#
8
# Flow:
9
#     mkfsmgraph < vld.v > vld.gml
10
#     gml2udg vld.gml  > vld.graph
11
#     uDrawGraph vld.graph
12
#     Choose menu "Layout->Improve All"
13
#     Choose menu "View->Full Scale"
14
#     Choose menu "File->Print" (print to file vld.ps, fit to page, center graph on page)
15
#     ps2pdf vld.ps
16
#
17
# Algorithm:
18
#
19
#   /* next state logic */
20
#     always @*
21
#       casex (state)
22
#         STATE_1:           if (somecondition) next = STATE_2;
23
#                              else next = STATE_1;
24
#
25
#  - find comment /* next state logic */
26
#  - take first always block after this comment
27
#  - any word beginning with STATE_ is a fsm state
28
#  - if character following the state is a colon (:) the state is source of a transition
29
#  - if character following the state is a semicolon (;) the state is destination of a transition
30
#
31
#
32
$gmlgraph = 1; # "gml" format
33
$dotgraph = 0; # "dot" format
34
 
35
%nodes = ();
36
%edges = ();
37
$cnt = 1;
38
 
39
$fsmfound = 0;
40
 
41
# extract next state logic from verilog
42
while (<>) {
43
  chop;
44
  if ($_ =~ /next state logic/) { $fsmfound = 1; }
45
  if ($_ =~ /always \@/) { if ($fsmfound == 1) {$fsmfound = 2; } else {$fsmfound = 0; }}
46
 
47
  if ($fsmfound) { $fsm = $fsm.$_; }
48
  }
49
 
50
# extract fsm states and edges from next state logic
51
while ($fsm =~ m/STATE_\w+/g) {
52
  $state = $&;
53
 
54
  if (!exists($nodes{$state})) {
55
    $nodes{$state} = $cnt;
56
    $cnt++;
57
    }
58
 
59
  $fsm =~ m/[:;]/g;
60
  $separator = $&;
61
 
62
  if ($separator eq ":") {
63
    $from = $state;
64
    }
65
  if ($separator eq ";") {
66
    $to = $state;
67
    $edges{"$from $to"} = 1;
68
    }
69
  }
70
 
71
if ($gmlgraph) {
72
  # output "gml" format graph
73
  print "graph [\n";
74
  print " directed 1\n";
75
 
76
  foreach $key (sort keys %nodes) {
77
    print " node [ id ".$nodes{$key}." label \"".$key."\" ]\n";
78
    }
79
 
80
  foreach $key (sort keys %edges) {
81
    ($from, $to) = split (/ /, $key);
82
    # uncomment next two lines to simplify graph
83
    # next if ($to eq "STATE_NEXT_START_CODE");
84
    # next if ($to eq "STATE_ERROR");
85
    print " edge [ source ".$nodes{$from}." target ". $nodes{$to}." ] \n";
86
    }
87
 
88
  print "]\n"
89
  }
90
 
91
if ($dotgraph) {
92
  # output "dot" format graph
93
  print "digraph \"fsmgraph\" {\n";
94
  foreach $key (sort keys %edges) {
95
    ($from, $to) = split (/ /, $key);
96
    # uncomment next two lines to simplify graph
97
    # next if ($to eq "STATE_NEXT_START_CODE");
98
    # next if ($to eq "STATE_ERROR");
99
    print " \"".$from."\" -> \"".$to."\"\n";
100
    }
101
  print "}\n";
102
  }
103
 
104
# not truncated

powered by: WebSVN 2.1.0

© copyright 1999-2019 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.