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

Subversion Repositories mpeg2fpga

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

powered by: WebSVN 2.1.0

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