OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [diagram.pl] - Blame information for rev 48

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 alirezamon
#!/usr/bin/perl -w
2 48 alirezamon
use constant::boolean;
3 34 alirezamon
use strict;
4
use warnings;
5 43 alirezamon
 
6
use FindBin;
7
use lib $FindBin::Bin;
8
 
9 34 alirezamon
use soc;
10
require "widget.pl";
11
require "emulator.pl";
12
use File::Copy;
13
 
14
 
15
 
16 43 alirezamon
 
17 34 alirezamon
sub get_dot_file{
18 38 alirezamon
        my $self= shift;
19
        my $self_name=$self->object_get_attribute('soc_name');
20
        my $remove_clk = $self->object_get_attribute("tile_diagram","show_clk");
21
        my $remove_reset = $self->object_get_attribute("tile_diagram","show_reset");
22
        my $remove_unused = $self->object_get_attribute("tile_diagram","show_unused");
23 34 alirezamon
 
24
        my $dotfile=
25
"digraph G {
26
        graph [rankdir = LR , splines=polyline, overlap = false];
27
        node[shape=record];
28
";
29
 
30 38 alirezamon
        my @all_instances=$self->soc_get_all_instances();
31 34 alirezamon
        #print "@all_instances\n";
32
        my $graph_connect= '';
33
        my $n=0;
34
        #my %socket_color;
35
        foreach my $instance_id (@all_instances){
36
                my $first=1;
37 38 alirezamon
                my $instance_name=$self->soc_get_instance_name($instance_id);
38 34 alirezamon
                $dotfile="$dotfile \n\t$instance_id \[label=\"{  ";
39
 
40 38 alirezamon
                my @sockets= $self->soc_get_all_sockets_of_an_instance($instance_id);
41 34 alirezamon
                @sockets = remove_scolar_from_array(\@sockets,'clk') if ($remove_clk);
42
                @sockets = remove_scolar_from_array(\@sockets,'reset') if ($remove_reset);
43
 
44
 
45
                foreach my $socket (@sockets){
46
 
47 38 alirezamon
                        my @nums=$self->soc_list_socket_nums($instance_id,$socket);
48 34 alirezamon
                        foreach my $num (@nums){
49 38 alirezamon
                                my $name= $self->soc_get_socket_name ($instance_id,$socket,$num);
50
                                my  ($s_type,$s_value,$s_connection_num)=$self->soc_get_socket_of_instance($instance_id,$socket);
51 48 alirezamon
                                my $v=(defined $s_value) ? $self->soc_get_module_param_value($instance_id,$s_value) : 1;
52 34 alirezamon
                                $v=1 if ( length( $v || '' ) ==0);
53
                                #for(my $i=$v-1; $i>=0; $i--) {
54
                                for(my $i=0; $i<$v; $i++) {
55
                                        #$socket_color{socket_${socket}\_$i}=$n;
56
                                        #$n = ($n<30)? $n+1 : 0;
57 38 alirezamon
                                        my ($ref1,$ref2)= $self->soc_get_modules_plug_connected_to_socket($instance_id,$socket,$i);
58 34 alirezamon
                                        my %connected_plugs=%$ref1;
59
                                        my %connected_plug_nums=%$ref2;
60
                                        if(%connected_plugs || $remove_unused==0){
61
                                                $dotfile= ($first)? "$dotfile\{<socket_${socket}\_$i>$name\_$i" : "$dotfile |<socket_${socket}_${i}>$name\_${i}";
62
                                                $first=0;
63
                                        }
64
                                }
65
 
66
                        }
67 43 alirezamon
                }
68 34 alirezamon
 
69
 
70
                $dotfile=($first)? "$dotfile $instance_name"  : "$dotfile}|$instance_name";
71
                $first=1;
72 38 alirezamon
                my @plugs= $self->soc_get_all_plugs_of_an_instance($instance_id);
73 34 alirezamon
                @plugs = remove_scolar_from_array(\@plugs,'clk') if ($remove_clk);
74
                @plugs = remove_scolar_from_array(\@plugs,'reset') if ($remove_reset);
75
 
76
                my %plug_order;
77
                my @noconnect;
78
                foreach my $plug (@plugs){
79
 
80 38 alirezamon
                        my @nums=$self->soc_list_plug_nums($instance_id,$plug);
81 34 alirezamon
                        foreach my $num (@nums){
82 38 alirezamon
                                my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$self->soc_get_plug($instance_id,$plug,$num);
83 34 alirezamon
 
84
                                if(defined $connect_socket || $remove_unused==0){
85
                                        #$dotfile= ($first)?  "$dotfile |{<plug_${plug}_${num}>$name" :  "$dotfile|<plug_${plug}_${num}>$name";
86
                                        if(defined $connect_id && defined $connect_socket){
87 38 alirezamon
                                                my @sockets= $self->soc_get_all_sockets_of_an_instance($connect_id);
88 34 alirezamon
                                                my $order_val=0;
89
                                                my $s1=get_pos($connect_id, @all_instances);
90
                                                my $s2=get_pos($connect_socket,  @sockets);
91
                                                $order_val=$s1*1000000+$s2*10000+$connect_socket_num;
92
                                                $plug_order{$order_val}=  "<plug_${plug}_${num}>$name";
93
                                        }else {push (@noconnect,"<plug_${plug}_${num}>$name");}
94
                                }
95
 
96
 
97 38 alirezamon
                                #my $connect_name=$self->soc_get_instance_name($connect_id);
98 34 alirezamon
                                #my $color = get_color_hex_string($n);
99
                                #$n = ($n<30)? $n+1 : 0;
100
 
101
                                $graph_connect="$graph_connect $instance_id:plug_${plug}_${num} ->  $connect_id:socket_${connect_socket}_${connect_socket_num} [  dir=none]\n" if(defined $connect_socket);
102
 
103
                        }
104
                }
105
                foreach my $p (sort {$a<=>$b} keys %plug_order){
106
                                        my $k=$plug_order{$p};
107
                                        #print "$instance_name   : $k=\$plug_order{$p}\n";
108
                                        $dotfile= ($first) ?   "$dotfile |{ ${k}": "$dotfile |${k}";
109
                                        $first=0;
110
 
111
                                }
112
 
113
                foreach my $k (@noconnect){
114
                        $dotfile= ($first) ?   "$dotfile |{ ${k}": "$dotfile |${k}";
115
                        $first=0;
116
                }
117
 
118
                $dotfile=  "$dotfile} }\"];";
119
 
120
 
121
 
122
        }
123
        $dotfile="$dotfile\n\n$graph_connect";
124
        $dotfile="$dotfile\n\n}\n";
125
 
126
 
127
        return $dotfile;
128
 
129
 
130
}
131
 
132
 
133
 
134
 
135
 
136
sub show_tile_diagram {
137 38 alirezamon
        my $self= shift;
138 34 alirezamon
 
139
        my $table=def_table(20,20,FALSE);
140
 
141
        my $window=def_popwin_size(80,80,"Processing Tile functional block diagram",'percent');
142 48 alirezamon
        my $scrolled_win = add_widget_to_scrolled_win();
143 34 alirezamon
 
144
        $window->add ($table);
145
 
146
        my $plus = def_image_button('icons/plus.png',undef,TRUE);
147
        my $minues = def_image_button('icons/minus.png',undef,TRUE);
148 38 alirezamon
        my $unused = gen_check_box_object ($self,"tile_diagram","show_unused",0,undef,undef);
149 34 alirezamon
        my $save = def_image_button('icons/save.png',undef,TRUE);
150 38 alirezamon
        my $clk = gen_check_box_object ($self,"tile_diagram","show_clk",0,undef,undef);
151
        my $reset = gen_check_box_object ($self,"tile_diagram","show_reset",0,undef,undef);
152 48 alirezamon
        my $dot_file = def_image_button('icons/add-notes.png',undef,TRUE);
153
        set_tip($dot_file, "Show dot file.");
154 34 alirezamon
        #my $save = def_image_button('icons/save.png',undef,TRUE);
155
 
156 38 alirezamon
        my $scale=$self->object_get_attribute("tile_diagram","scale");
157 34 alirezamon
        $scale= 1 if (!defined $scale);
158
 
159
 
160
 
161
 
162
        my $col=0;
163
        $table->attach ($plus ,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
164
        $table->attach ($minues,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
165
        $table->attach ($save,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
166
        $table->attach (gen_label_in_left("     Remove unconnected Interfaces"),  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
167
        $table->attach ($unused,  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
168
        $table->attach (gen_label_in_left("     Remove Clk Interfaces"),  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
169
        $table->attach ($clk,  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
170
        $table->attach (gen_label_in_left("     Remove Reset Interfaces"),  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
171
        $table->attach ($reset,  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
172 48 alirezamon
        $table->attach ($dot_file,  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
173
 
174 34 alirezamon
        while ($col<20){
175
 
176
                my $tmp=gen_label_in_left('');
177
                $table->attach_defaults ($tmp, $col,  $col+1,0,1);$col++;
178
        }
179
 
180 48 alirezamon
        $table->attach_defaults ($scrolled_win, 0, 20, 1, 20); #,'fill','shrink',2,2);   
181
 
182 34 alirezamon
        $plus  -> signal_connect("clicked" => sub{
183
                $scale*=1.1 if ($scale <10);
184 38 alirezamon
                $self->object_add_attribute("tile_diagram","scale", $scale );
185 48 alirezamon
                gen_show_diagram($self,$scrolled_win,'tile',"tile_diagram");
186 34 alirezamon
        });
187
        $minues  -> signal_connect("clicked" => sub{
188
                $scale*=.9  if ($scale >0.1); ;
189 38 alirezamon
                $self->object_add_attribute("tile_diagram","scale", $scale );
190 48 alirezamon
                gen_show_diagram($self,$scrolled_win,'tile',"tile_diagram");
191 34 alirezamon
        });
192
        $save-> signal_connect("clicked" => sub{
193 48 alirezamon
                        save_inline_diagram_as ($self);
194
                        show_tile_diagram($self);
195
                        $window->destroy;
196 34 alirezamon
                });
197
        $unused-> signal_connect("toggled" => sub{
198 48 alirezamon
                gen_show_diagram($self,$scrolled_win,'tile',"tile_diagram");
199 34 alirezamon
 
200
        });
201
        $clk-> signal_connect("toggled" => sub{
202 48 alirezamon
                gen_show_diagram($self,$scrolled_win,'tile',"tile_diagram");
203 34 alirezamon
 
204
        });
205
        $reset-> signal_connect("toggled" => sub{
206 48 alirezamon
 
207
                gen_show_diagram($self,$scrolled_win,'tile',"tile_diagram");
208 34 alirezamon
 
209
        });
210
 
211 48 alirezamon
        $dot_file-> signal_connect("clicked" => sub{
212
                        my $dotfile = get_dot_file_text($self,'tile');
213
                        show_text_in_scrolled_win($self,$scrolled_win, $dotfile);
214
        });
215
 
216
 
217
        gen_show_diagram($self,$scrolled_win,'tile',"tile_diagram");
218 34 alirezamon
        $window->show_all();
219
}
220
 
221
 
222 48 alirezamon
sub gen_show_diagram{
223
        my ($self,$scrolled_win,$type,$name)=@_;
224
 
225
        my $topology=$self->object_get_attribute('noc_param','TOPOLOGY');
226
        if ($type eq 'topology' && $topology eq '"CUSTOM"'){
227
 
228
                 my $name=$self->object_get_attribute('noc_param','CUSTOM_TOPOLOGY_NAME');
229
                 $name=~s/["]//gs;
230
                 my $image=  get_project_dir()."/mpsoc/rtl/src_topolgy/$name/$name.png";
231
                 my $tmp  = "$ENV{'PRONOC_WORK'}/tmp/diagram.png";
232
 
233
                 unlink $tmp;
234
                 return 0 unless (-f "$image");
235
                 copy ($image,$tmp);
236
                 return 0 unless (-f "$tmp");
237
                 show_diagram ($self,$scrolled_win,$name);
238
                 return 1;
239
        }
240
 
241
 
242
 
243
        my $dotfile = get_dot_file_text($self,$type);
244
 
245
        generate_and_show_graph_using_graphviz ($self,$scrolled_win,$dotfile, $name);
246
 
247
}
248
 
249
 
250 43 alirezamon
sub show_topology_diagram {
251
        my $self= shift;
252 34 alirezamon
 
253 43 alirezamon
        my $table=def_table(20,20,FALSE);
254
 
255 48 alirezamon
        my $window=def_popwin_size(80,80,"NoC-based MPSoC topology block diagram",'percent');
256
        my $scrolled_win = add_widget_to_scrolled_win();
257 43 alirezamon
 
258
        $window->add ($table);
259 48 alirezamon
 
260 43 alirezamon
        my $plus = def_image_button('icons/plus.png',undef,TRUE);
261
        my $minues = def_image_button('icons/minus.png',undef,TRUE);
262
        my $save = def_image_button('icons/save.png',undef,TRUE);
263 48 alirezamon
        my $dot_file = def_image_button('icons/add-notes.png',undef,TRUE);
264
        set_tip($dot_file, "Show dot file.");
265 43 alirezamon
 
266 48 alirezamon
        my $gtype=$self->object_get_attribute("tile_diagram","gtype");
267
        if (!defined $gtype){
268
                $gtype='comp' ;
269
                $self->object_add_attribute("tile_diagram","gtype",$gtype);
270
        }
271
        my $graph_type= ($gtype eq 'comp')? def_colored_button('comp',17): def_colored_button('simple',4);
272
        my $box=def_hbox(FALSE,0);
273
        $box->pack_start( $graph_type, FALSE, FALSE, 0);
274
 
275
 
276
 
277
 
278 43 alirezamon
        my $scale=$self->object_get_attribute("tile_diagram","scale");
279
        $scale= 1 if (!defined $scale);
280
 
281
 
282
 
283
 
284
        my $col=0;
285
        $table->attach ($plus ,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
286
        $table->attach ($minues,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
287
        $table->attach ($save,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
288 48 alirezamon
        $table->attach ($dot_file,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
289
        $table->attach ($box,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
290 43 alirezamon
        #$table->attach (gen_label_in_left("     Remove unconnected Interfaces"),  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
291
        #$table->attach (gen_label_in_left("     Remove Clk Interfaces"),  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
292
        #$table->attach (gen_label_in_left("     Remove Reset Interfaces"),  $col,  $col+1,0,1,'shrink','shrink',2,2); $col++;
293
        while ($col<20){
294
                my $tmp=gen_label_in_left('');
295
                $table->attach_defaults ($tmp, $col,  $col+1,0,1);$col++;
296
        }
297
 
298 48 alirezamon
        $table->attach_defaults ($scrolled_win, 0, 20, 1, 20); #,'fill','shrink',2,2);
299
 
300 43 alirezamon
        $plus  -> signal_connect("clicked" => sub{
301
                $scale*=1.1 if ($scale <10);
302
                $self->object_add_attribute("topology_diagram","scale", $scale );
303 48 alirezamon
                gen_show_diagram($self,$scrolled_win,'topology',"topology_diagram");
304
 
305 43 alirezamon
        });
306
        $minues  -> signal_connect("clicked" => sub{
307
                $scale*=.9  if ($scale >0.1); ;
308
                $self->object_add_attribute("topology_diagram","scale", $scale );
309 48 alirezamon
                gen_show_diagram($self,$scrolled_win,'topology',"topology_diagram");
310 43 alirezamon
        });
311
        $save-> signal_connect("clicked" => sub{
312 48 alirezamon
                        save_inline_diagram_as ($self);
313
                        show_topology_diagram($self);
314
                        $window->destroy;
315
        });
316 43 alirezamon
 
317 48 alirezamon
        $dot_file-> signal_connect("clicked" => sub{
318
                        my $dot_file=get_dot_file_text($self,'topology');
319
                        show_text_in_scrolled_win($self,$scrolled_win, $dot_file);
320
        });
321 43 alirezamon
 
322 48 alirezamon
        $graph_type-> signal_connect("clicked" => sub{
323
                        my $gtype=$self->object_get_attribute("tile_diagram","gtype");
324
                        my $new = ($gtype eq "simple")? "comp" : "simple";
325
                        $self->object_add_attribute("tile_diagram","gtype",$new);
326
                        $graph_type= ($new eq 'comp')? def_colored_button('comp',17): def_colored_button('simple',4);
327
                        show_topology_diagram($self);
328
                        $window->destroy;
329
        });
330
 
331
 
332
        gen_show_diagram($self,$scrolled_win,'topology',"topology_diagram");
333 43 alirezamon
        $window->show_all();
334
}
335
 
336
 
337 48 alirezamon
sub get_dot_file_text {
338 38 alirezamon
        my ($self,$type)=@_;
339
        my $dotfile;
340
        $dotfile=   get_dot_file($self) if ($type eq 'tile');
341 43 alirezamon
        $dotfile=   get_topology_dot_file($self) if ($type eq 'topology');
342
        $dotfile=   generate_custom_topology_dot_file($self) if ($type eq 'custom_topology');
343 48 alirezamon
        $dotfile=   generate_trace_dot_file($self) if ($type eq 'trace');
344
        $dotfile=   generate_merge_actor_dot_file       ($self) if ($type eq 'merge-actor');
345
        $dotfile=   generate_map_dot_file($self) if ($type eq 'map');
346
        return $dotfile;
347
}
348
 
349
 
350
sub gen_diagram {
351
        my ($self,$type)=@_;
352
        my $topology=$self->object_get_attribute('noc_param','TOPOLOGY');
353
        if ($type eq 'topology' && $topology eq '"CUSTOM"'){
354
 
355
                 my $name=$self->object_get_attribute('noc_param','CUSTOM_TOPOLOGY_NAME');
356
                 $name=~s/["]//gs;
357
                 my $image=  get_project_dir()."/mpsoc/rtl/src_topolgy/$name/$name.png";
358
                 my $tmp  = "$ENV{'PRONOC_WORK'}/tmp/diagram.png";
359
 
360
                 unlink $tmp;
361
                 return 0 unless (-f "$image");
362
                 copy ($image,$tmp);
363
                 return 0 unless (-f "$tmp");
364
                 return 1;
365
        }
366 38 alirezamon
 
367 48 alirezamon
 
368
 
369
        my $dotfile = get_dot_file_text(@_);
370
 
371 34 alirezamon
        my $tmp_dir  = "$ENV{'PRONOC_WORK'}/tmp";
372 43 alirezamon
 
373 34 alirezamon
 
374 38 alirezamon
        my $cmd;
375 43 alirezamon
        #$cmd=  "dot  $tmp_dir/diagram.txt | neato -n  -Tpng -o $tmp_dir/diagram.png" if ($type eq 'tile' || $type eq 'trace'  );
376
        #$cmd = "dot  $tmp_dir/diagram.txt -Kfdp -n -Tpng -o $tmp_dir/diagram.png" if ( $type eq 'map' || $type eq 'topology' || $type eq 'custom_topology' );  
377
        $cmd=  " dot   | neato -n  -Tpng -o $tmp_dir/diagram.png" if ($type eq 'tile' || $type eq 'trace'  );
378
        $cmd = " dot   -Kfdp -n -Tpng -o $tmp_dir/diagram.png" if ( $type eq 'map' || $type eq 'topology' || $type eq 'custom_topology' );
379
    $cmd = "echo \'$dotfile\' | $cmd";
380 34 alirezamon
 
381
        my ($stdout,$exit,$stderr)= run_cmd_in_back_ground_get_stdout ($cmd);
382
 
383 43 alirezamon
        if ( length( $stderr || '' ) !=0)  {
384 34 alirezamon
                message_dialog("$stderr\nHave you installed graphviz? If not run \n \t \"sudo apt-get install graphviz\" \n in terminal");
385 43 alirezamon
                return 0 unless (-f "$tmp_dir/diagram.png");
386 34 alirezamon
        }
387
                return  1;
388
}
389
 
390
 
391
 
392
sub show_diagram {
393 48 alirezamon
        my ($self,$scrolled_win,$name)=@_;
394
 
395
        my @list = $scrolled_win->get_children();
396
        foreach my $l (@list){
397
                $scrolled_win->remove($l);
398
        }
399
 
400
 
401 38 alirezamon
        my $scale=$self->object_get_attribute($name,"scale");
402 34 alirezamon
        $scale= 1 if (!defined $scale);
403
        my $tmp_dir  = "$ENV{'PRONOC_WORK'}/tmp";
404
        my $diagram=open_image("$tmp_dir/diagram.png",70*$scale,70*$scale,'percent');
405 43 alirezamon
 
406 48 alirezamon
        add_widget_to_scrolled_win($diagram,$scrolled_win);
407 43 alirezamon
        $scrolled_win->show_all();
408 34 alirezamon
 
409 48 alirezamon
}
410
 
411
sub show_text_in_scrolled_win {
412
        my ($self,$scrolled_win, $text)=@_;
413
        my @list = $scrolled_win->get_children();
414
        foreach my $l (@list){
415
                $scrolled_win->remove($l);
416
        }
417 34 alirezamon
 
418 48 alirezamon
 
419
        my ($u,$tview)=create_txview();
420
 
421
        show_info($tview, $text);
422
        add_widget_to_scrolled_win($u,$scrolled_win);
423
        $scrolled_win->show_all();
424
}
425 34 alirezamon
 
426
 
427
 
428
 
429
sub save_diagram_as {
430 38 alirezamon
        my $self= shift;
431 34 alirezamon
 
432
        my $file;
433
        my $title ='Save as';
434
 
435
 
436
 
437
        my @extensions=('png');
438
        my $open_in=undef;
439 48 alirezamon
        my $dialog = save_file_dialog  ( 'Save file',@extensions);
440
        $dialog->set_current_folder ($open_in) if(defined  $open_in);
441
 
442 34 alirezamon
 
443
        if ( "ok" eq $dialog->run ) {
444 48 alirezamon
                $file = $dialog->get_filename;
445 34 alirezamon
                        my $ext = $dialog->get_filter;
446
                        $ext=$ext->get_name;
447
                        my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
448
                        $file = ($suffix eq ".$ext" )? $file : "$file.$ext";
449
 
450 38 alirezamon
                        $self->object_add_attribute("graph_save","name",$file);
451
                        $self->object_add_attribute("graph_save","extension",$ext);
452 34 alirezamon
                        my $tmp  = "$ENV{'PRONOC_WORK'}/tmp/diagram.png";
453
                        copy ($tmp,$file);
454
 
455
 
456
 
457 48 alirezamon
        }
458
        $dialog->destroy;
459 38 alirezamon
}
460 34 alirezamon
 
461
 
462
 
463 48 alirezamon
 
464
sub save_inline_diagram_as {
465
        my $self= shift;
466
 
467
        my $file;
468
        my $title ='Save as';
469
 
470
 
471
 
472
        my @extensions=('png','jpeg');
473
        my $open_in=undef;
474
        my $dialog = save_file_dialog  ('Save file',@extensions);
475
        $dialog->set_current_folder ($open_in) if(defined  $open_in);
476
 
477
 
478
        if ( "ok" eq $dialog->run ) {
479
                $file = $dialog->get_filename;
480
                        my $ext = $dialog->get_filter;
481
                        $ext=$ext->get_name;
482
                        my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
483
 
484
                        $file = ($suffix eq ".$ext" )? $file : "$file.$ext";
485
 
486
                        $self->object_add_attribute("graph_save","name","$path/$name");
487
                        $self->object_add_attribute("graph_save","extension",$ext);
488
                        $self->object_add_attribute("graph_save","enable",1);
489
                        set_gui_status($self,"ref",5);
490
        }
491
        $dialog->destroy;
492
}
493
 
494
 
495
 
496 38 alirezamon
sub generate_trace_dot_file{
497
        my $self=shift;
498
        my $dotfile=
499
"digraph G {
500 48 alirezamon
        graph [ layout = neato, rankdir = LR , splines=polyline, overlap = false];
501 38 alirezamon
 
502
";
503
 
504 48 alirezamon
 
505 38 alirezamon
 
506
#add connections
507 34 alirezamon
 
508 48 alirezamon
        my @traces= get_trace_list($self,'raw');
509 38 alirezamon
        foreach my $p (@traces) {
510 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,'raw',$p);
511 38 alirezamon
                $dotfile=$dotfile."\"$src\" -> \"$dst\"  [label=\"$Mbytes\" ];\n";
512
        }
513
 
514
        $dotfile=$dotfile."\n}\n";
515
        return $dotfile;
516
 
517 34 alirezamon
}
518
 
519
 
520
 
521 38 alirezamon
sub generate_map_dot_file{
522
        my $self=shift;
523
        my $dotfile=
524
"digraph G {
525 48 alirezamon
        graph [layout = neato, rankdir = LR ,splines=spline,  overlap = false];
526 38 alirezamon
        node[shape=record];
527
 
528
        ";
529
 
530 48 alirezamon
#add nodes      
531
        my @tasks=get_all_tasks($self,"merge");
532
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info($self);
533
        my %pos=get_endp_pos($self);
534
        my @mappedtasks;
535
        for(my $i=0; $i<$NE; $i++){
536
                                        my $task=get_task_assigned_to_tile($self,$i);
537 38 alirezamon
                                        push(@mappedtasks,$task) if (defined $task);
538
 
539
                                        $task= "_" if (!defined $task);
540 48 alirezamon
                                        my $n =    "tile($i)" ;
541
                                        my $m =    "tile($i)" ;
542 38 alirezamon
                                        my $node = "\"$m\"";
543
                                        my $label =   "\"<S$task> $n|<R$task> $task\"" ;
544 48 alirezamon
 
545 38 alirezamon
                                        $dotfile=$dotfile."
546
$node\[
547
        label = $label
548 48 alirezamon
    pos = $pos{$i}
549 38 alirezamon
];";
550 48 alirezamon
 
551 38 alirezamon
        }
552
        $dotfile=$dotfile."\n\n";
553 48 alirezamon
        #add connections
554
        my @traces= get_trace_list($self,'merge');
555
        my %src_dst;
556 38 alirezamon
 
557
        foreach my $p (@traces){
558 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,'merge',$p);
559
                my $src_tile=get_task_give_tile($self,"$src");
560
                my $dst_tile=get_task_give_tile($self,"$dst");
561
                next if ($src_dst{"${src_tile}_$dst_tile"}); #make sure there will be only one arow betwenn each source destination tile
562
                next if ( $src_tile eq "-" ||  $dst_tile eq "-" );
563
                $dotfile=$dotfile." \"$src_tile\" :  \"S$src\" ->  \"$dst_tile\" : \"R$dst\"  ;\n" if((defined $src_tile )&& (defined $dst_tile));
564
                $src_dst{"${src_tile}_$dst_tile"}=1;
565 38 alirezamon
        }
566
        $dotfile=$dotfile."\n}\n";
567
        return $dotfile;
568
}
569
 
570
 
571
 
572
 
573
 
574
sub show_trace_diagram {
575
        my ($self,$type)=@_;
576
        my $table=def_table(20,20,FALSE);
577
 
578 48 alirezamon
        my $window=def_popwin_size(80,80,"Trace Diagram",'percent');
579
        my $scrolled_win =add_widget_to_scrolled_win();
580 38 alirezamon
 
581
        $window->add ($table);
582
 
583
        my $plus = def_image_button('icons/plus.png',undef,TRUE);
584
        my $minues = def_image_button('icons/minus.png',undef,TRUE);
585
        my $save = def_image_button('icons/save.png',undef,TRUE);
586 48 alirezamon
        my $dot_file = def_image_button('icons/add-notes.png',undef,TRUE);
587
        set_tip($dot_file, "Show dot file.");
588 38 alirezamon
 
589 48 alirezamon
 
590 38 alirezamon
 
591
        my $scale=$self->object_get_attribute("${type}_diagram","scale");
592
        $scale= 1 if (!defined $scale);
593
 
594
 
595
 
596
 
597
        my $col=0;
598
        $table->attach ($plus ,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
599
        $table->attach ($minues,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
600
        $table->attach ($save,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
601 48 alirezamon
        $table->attach ($dot_file,  $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
602
        $table->attach_defaults ($scrolled_win, 0, 20, 1, 20); #,'fill','shrink',2,2);   
603 38 alirezamon
 
604 48 alirezamon
        while ($col<20){
605 38 alirezamon
                my $tmp=gen_label_in_left('');
606
                $table->attach_defaults ($tmp, $col,  $col+1,0,1);$col++;
607
        }
608
 
609
        $plus  -> signal_connect("clicked" => sub{
610
                $scale*=1.1 if ($scale <10);
611
                $self->object_add_attribute("${type}_diagram","scale", $scale );
612 48 alirezamon
                my $dotfile = get_dot_file_text($self,$type);
613
                generate_and_show_graph_using_graphviz ($self,$scrolled_win,$dotfile, "${type}_diagram");
614 38 alirezamon
        });
615
        $minues  -> signal_connect("clicked" => sub{
616
                $scale*=.9  if ($scale >0.1); ;
617
                $self->object_add_attribute("${type}_diagram","scale", $scale );
618 48 alirezamon
                gen_show_diagram ($self,$scrolled_win,$type,"${type}_diagram");
619 38 alirezamon
        });
620
        $save-> signal_connect("clicked" => sub{
621 48 alirezamon
                        save_inline_diagram_as ($self);
622
                        show_trace_diagram($self,$type);
623
                        $window->destroy;
624 38 alirezamon
                });
625
 
626 48 alirezamon
        $dot_file-> signal_connect("clicked" => sub{
627
                my $dotfile = get_dot_file_text($self,$type);
628
                show_text_in_scrolled_win($self,$scrolled_win, $dotfile);
629
 
630
        });
631 38 alirezamon
 
632 48 alirezamon
        gen_show_diagram ($self,$scrolled_win,$type,"${type}_diagram");
633
 
634 38 alirezamon
        $window->show_all();
635
}
636 43 alirezamon
 
637
 
638
 
639
 
640
 
641
 
642
sub node_connection{
643 48 alirezamon
        my ($sn,$sx,$sy,$sp,$dn,$dx,$dy,$dp,$gtype)=@_;
644
        $gtype="comp" if(!defined $gtype);
645
 
646
        my $spp = (defined $sp  && $gtype eq "comp" ) ? ":\"p$sp\"" : " ";
647
        my $dpp = (defined $dp  && $gtype eq "comp" ) ? ":\"p$dp\"" : " ";
648 43 alirezamon
        my $sname = (defined $sy) ? "\"$sn${sx}_${sy}\"" : "\"$sn${sx}\"";
649
        my $dname = (defined $dy) ? "\"$dn${dx}_${dy}\"" : "\"$dn${dx}\"";
650
 
651
        my $t= "$sname  $spp -> $dname  $dpp [  dir=none];\n";
652
        return $t;
653
}
654
 
655
sub node_connection2{
656
        my ($sn,$sx,$sp,$dn,$dx,$dy,$dp)=@_;
657
        my $spp = (defined $sp) ? ":\"p$sp\"" : " ";
658
        my $dpp = (defined $dp) ? ":\"p$dp\"" : " ";
659
        my $sname =   "\"$sn${sx}\"";
660
        my $dname =  "\"$dn${dx}\"";
661
 
662
        my $t= "$sname  $spp -> $dname  $dpp [  dir=none];\n";
663
        return $t;
664
}
665
 
666
 
667
 
668
 
669
##################################
670
#
671
##################################
672
 
673
 
674
sub generate_mesh_dot_file{
675
        my $self=shift;
676 48 alirezamon
 
677
        my $gtype=$self->object_get_attribute("tile_diagram","gtype");
678
 
679 43 alirezamon
        my $dotfile=
680
"digraph G {
681 48 alirezamon
        graph [layout = neato, rankdir = RL , splines = true, overlap = true];
682 43 alirezamon
 
683
 
684
        node[shape=record];
685
 
686
        ";
687
 
688
#five_port_router [
689
#       label="{ |2| } | {3|R0|1} | { |4|0}"
690
#       shape=record
691
#       color=blue
692
#       style=filled
693
#       fillcolor=blue
694
#];     
695
 
696
#add nodes
697
        my $nx=$self->object_get_attribute('noc_param','T1');
698
        my $ny=$self->object_get_attribute('noc_param','T2');
699
        my $nz=$self->object_get_attribute('noc_param','T3');
700 48 alirezamon
 
701
        my ($NE, $NR, $RAw, $EAw, $Fw)  = get_topology_info($self);
702
 
703
 
704 43 alirezamon
        my $topology=$self->object_get_attribute('noc_param','TOPOLOGY');
705
 
706
 
707
        my $btrace= ($topology eq '"TORUS"' || $topology eq '"RING"');
708
        my $oned = ($topology eq '"RING"' || $topology eq '"LINE"');
709
 
710
        #generate endpoints
711
        for(my $y=0; $y<$ny; $y++){
712
                                for(my $x=0; $x<$nx; $x++){
713
                                        for(my $z=0; $z<$nz; $z++){
714
                                                my $id=($y*$nx+$x)*$nz+$z;
715
                                                my $offsetx = ($z==0 || $z==3) ? 1.05 : -1.05;
716
                                                my $offsety = ($z==0 || $z==1) ? -0.85 : +0.85;
717
                                                my $tx=$x*3+$offsetx;
718
                                                my $ty=($ny-$y-1)*2.5+1+$offsety;
719 48 alirezamon
                                                $dotfile.=get_record_endp_dot_file("T$id","T$id", "$tx,$ty!");
720 43 alirezamon
        }}}
721
 
722 48 alirezamon
        if($topology eq '"FMESH"' ) {
723
                my $tmp = $ny*$nx*$nz;
724
                for(my $x=0; $x<$nx; $x++){
725
                            #top edges
726
                                my $id=$tmp + $x;
727
                                my $tx=$x*3;
728
                                my $ty=($ny)*2.5-.5;
729
                                $dotfile.=get_record_endp_dot_file("T$id","T$id", "$tx,$ty!");
730
                                get_connected_router_id_to_endp($self,$id);
731
 
732
 
733
 
734
                                #down edges
735
                                $id= $tmp + $nx +$x;
736
                                $tx=$x*3;
737
                                $ty=-.5;
738
                                $dotfile.=get_record_endp_dot_file("T$id","T$id", "$tx,$ty!");
739
                }
740
                for(my $y=0; $y<$ny; $y++){
741
                            #right edges
742
                                my $id= $tmp + 2*$nx +$y;
743
                                my $tx=-1.5;
744
                                my $ty=($ny-$y-1)*2.5+1;
745
                                $dotfile.=get_record_endp_dot_file("T$id","T$id", "$tx,$ty!");
746
 
747
 
748
                                #left edges
749
                                $id= $tmp + 2*$nx+$ny +$y;
750
                                $tx=$nx*3-1.5;
751
                                $ty=($ny-$y-1)*2.5+1;
752
                                $dotfile.=get_record_endp_dot_file("T$id","T$id", "$tx,$ty!");
753
 
754
                }
755
 
756
        }
757
 
758
 
759 43 alirezamon
#generate routers       
760
        for(my $y=0; $y<$ny; $y++){
761
                                for(my $x=0; $x<$nx; $x++){
762
                                        my $e0 = '0';
763
                                        my $e1 = ($nz>1)? ( ($oned)? '3':'5') : ' ';
764
                                        my $e2 = ($nz>2)? ( ($oned)? '4':'6') : ' ';
765
                                        my $e3 = ($nz>3)? ( ($oned)? '5':'7') : ' ';
766
 
767
                                        my $id=$y*$nx+$x;
768
                                        my $n = "R${id}";
769
                                        my $label =  ($oned)?
770
                                         "\{<p7>$e2 |<p2> |<p8>$e3 \} | \{<p3>2|$n|<p1>1\} | \{<p6>$e1 |<p4> |<p5>$e0\}"
771
                                        :"\{<p7>$e2 |<p2>2|<p8>$e3 \} | \{<p3>3|$n|<p1>1\} | \{<p6>$e1 |<p4>4|<p5>$e0\}";
772
                                        my $xx=$x*3;
773
                                        my $yy=($ny-$y-1)*2.5+1;
774
 
775
 
776
 
777
 
778 48 alirezamon
                                        $dotfile.=get_router_dot_file($n,$label,"$xx,$yy!",$gtype);
779
 
780 43 alirezamon
 
781
                                }}
782
 
783
 
784
        $dotfile=$dotfile."\n\n";
785
 
786
        #add connections
787
        for(my $y=0; $y<$ny; $y++){
788
                for(my $x=0; $x<$nx; $x++){
789
 
790 48 alirezamon
                         $dotfile=$dotfile.node_connection('R',get_router_num($self,$x,$y),undef,1,'R',get_router_num($self,($x+1),$y),undef,3,$gtype) if($x <$nx-1);
791
                         $dotfile=$dotfile.node_connection('R',get_router_num($self,$x,$y),undef,1,'R',get_router_num($self,0,$y),undef,3,$gtype) if($x == ($nx-1) && $btrace);
792
                         $dotfile=$dotfile.node_connection('R',get_router_num($self,$x,$y),undef,2,'R',get_router_num($self,$x,($y-1)),undef,4,$gtype)if($y>0) ;
793
             $dotfile=$dotfile.node_connection('R',get_router_num($self,$x,$y),undef,2,'R',get_router_num($self,$x,($ny-1)),undef,4,$gtype) if($y ==0 && $btrace && !$oned);
794 43 alirezamon
          #   $dotfile=$dotfile.node_connection('R',$x,$y,0,'T',$x,$y);               
795
    }}
796 48 alirezamon
if($topology eq '"FMESH"' ) {
797 43 alirezamon
        for(my $id=0; $id<$NE; $id++){
798 48 alirezamon
                my $rid= get_connected_router_id_to_endp($self,$id);
799
                my $tmp = $nx*$ny*$nz;
800
                my $p = ($id<$tmp)? $id%$nz+5 :
801
                        ($id<$tmp+$nx)? 2 :
802
                        ($id<$tmp+2*$nx)? 4 :
803
                        ($id<$tmp+2*$nx+$ny)? 3:1;
804
                $dotfile=$dotfile.node_connection('R',$rid,undef,$p,'T',$id,undef,undef,$gtype);
805
 
806
        }
807
 
808
}else{
809
        for(my $id=0; $id<$NE; $id++){
810 43 alirezamon
                my $rid=int($id/$nz);
811
                my $p =  $id%$nz+5;
812 48 alirezamon
                $dotfile=$dotfile.node_connection('R',$rid,undef,$p,'T',$id,undef,undef,$gtype);
813 43 alirezamon
 
814
        }
815 48 alirezamon
}
816 43 alirezamon
        $dotfile=$dotfile."\n}\n";
817
        return $dotfile;
818
 
819
 
820
 
821
}
822
 
823 48 alirezamon
sub get_endp_pos {
824
        my $self=shift;
825
        my $topology=$self->object_get_attribute('noc_param','TOPOLOGY');
826
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info($self);
827
        my %pos;
828
        if($topology eq '"FATTREE"' || $topology eq '"TREE"'){
829
 
830
                for(my $i=0; $i<$NE; $i++){
831
                            $pos{$i} = "\"$i,0!\"";
832
            }
833
                return %pos;
834
        }
835
        #($topology eq '"TORUS"' || $topology eq '"RING"' || $topology eq '"RING"' || $topology eq '"LINE"');   
836
 
837
        my $nx=$self->object_get_attribute('noc_param','T1');
838
        my $ny=$self->object_get_attribute('noc_param','T2');
839
        my $nz=$self->object_get_attribute('noc_param','T3');
840
 
841
 
842
        #generate endpoints
843
        for(my $y=0; $y<$ny; $y++){
844
                                for(my $x=0; $x<$nx; $x++){
845
                                        for(my $z=0; $z<$nz; $z++){
846
                                                my $id=($y*$nx+$x)*$nz+$z;
847
                                                my $offsetx = ($z==0 || $z==3) ? 1.05 : -1.05;
848
                                                my $offsety = ($z==0 || $z==1) ? -0.85 : +0.85;
849
                                                my $tx=$x*3+$offsetx;
850
                                                my $ty=($ny-$y-1)*2.5+1+$offsety;
851
                                                $pos{$id} = "\"$tx,$ty!\"";
852
                                        }
853
                                }
854
        }
855
                return %pos;
856
}
857 43 alirezamon
 
858 48 alirezamon
sub get_record_endp_dot_file {
859
        my ($name,$label,$pos)=@_;
860 43 alirezamon
 
861 48 alirezamon
return "$name\[
862
        label = \"$label\"
863
    pos = \"$pos\"
864
    shape=record
865
        color=orange
866
        style=filled
867
        fillcolor=orange
868
];
869
"
870
;
871
}
872
 
873
sub get_router_dot_file {
874
        my ($name,$label,$pos,$type)=@_;
875
 
876
 
877
        return ($type eq 'comp')? "\"$name\"\[
878
        label=\"$label\"
879
    pos = \"$pos\"
880
    shape=record
881
        color=blue
882
        style=filled
883
        fillcolor=blue
884
];
885
"
886
:
887
"\"$name\"\[
888
        label=\"$name\"
889
    pos = \"$pos\"
890
    shape=circle
891
        color=blue
892
        style=filled
893
        fillcolor=blue
894
];
895
"
896
;
897
 
898
 
899
}
900
 
901 43 alirezamon
sub generate_fattree_dot_file{
902
        my $self=shift;
903 48 alirezamon
        my $gtype=$self->object_get_attribute("tile_diagram","gtype");
904
 
905 43 alirezamon
 
906
        my $dotfile=
907
"digraph G {
908 48 alirezamon
        graph [layout = neato, rankdir = LR , splines = true, overlap = true];
909 43 alirezamon
        node[shape=record];
910
        ";
911
 
912
#add nodes
913 48 alirezamon
    my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
914
 
915 43 alirezamon
        my $k=$self->object_get_attribute('noc_param','T1');
916
        my $nl=$self->object_get_attribute('noc_param','T2');
917
        my @bp;
918
        my @hp;
919
        for(my $p=0; $p<$k; $p++) {push (@bp,"<p$p>$p");}
920
        for(my $p=$k; $p<2*$k; $p++) {push (@hp,"<p$p>$p");}
921
        my $bp= join("|",@bp);
922
        my $hp= join("|",@hp);
923 48 alirezamon
        #my $NC= powi( $k,$nl  ); #total endpoints
924
        my $NL= $NE/$k ; #number of nodes in  each layer 
925 43 alirezamon
 
926
 
927
#add endpoints
928 48 alirezamon
for(my $i=0; $i<$NE; $i++){
929 43 alirezamon
        my $x=$i%$k;
930
        my $y=int($i/$k);
931
 
932
$dotfile=$dotfile."T$i\[
933
        label = \"T$i\"
934
    pos = \"$i,0!\"
935
    shape=house
936
    margin=0
937
        color=orange
938
        style=filled
939
        fillcolor=orange
940
];
941
";
942
        }
943
 
944
        #add roots
945
        for(my $pos=0; $pos<$NL; $pos++){
946
                my $x=($k)*$pos+($k/2)-0.5;
947
                my $y=  1.5*($nl-1)+1;
948
                my $r=$pos;
949 48 alirezamon
                my $label = "\{R$r\}|\{$bp\}";
950
 
951
                $dotfile.=get_router_dot_file("R$r",$label,"$x,$y!",$gtype);
952
 
953 43 alirezamon
        }
954
 
955
        #add leaves
956
        for(my $l=1; $l<$nl; $l++){
957
        for(my $pos=0; $pos<$NL; $pos++){
958 48 alirezamon
                my $x=($k)*$pos+($k/2)-0.5;
959
                my $y=  1.5*($nl-$l-1)+1;
960
                my $r=$NL*$l+$pos;
961
                my $label = "\{$hp\}|\{R$r\}|\{$bp\}";
962
 
963
                $dotfile.=get_router_dot_file("R$r",$label,"$x,$y!",$gtype);
964
 
965
        }
966 43 alirezamon
        }
967
 
968
 
969
 
970 48 alirezamon
        #connect all down input chanels
971 43 alirezamon
        my $n=$nl;
972
        my $nPos = powi( $k, $n-1);
973
        my $chan_per_direction = ($k * powi( $k , $n-1 )); #up or down
974
        my $chan_per_level = 2*($k * powi( $k , $n-1 )); #up+down
975
 
976
        for (my $level = 0; $level<$n-1; $level++){
977 48 alirezamon
            #input chanel are numbered interleavely, the interleaev depends on level
978 43 alirezamon
            my $routers_per_neighborhood = powi($k,$n-1-($level));
979
            my $routers_per_branch = powi($k,$n-1-($level+1));
980
            my $level_offset = $routers_per_neighborhood*$k;
981
            for ( my $pos = 0; $pos < $nPos; ++$pos ) {
982
                        my $neighborhood = int($pos/$routers_per_neighborhood);
983
                        my $neighborhood_pos = $pos % $routers_per_neighborhood;
984
                        for ( my $port = 0; $port < $k; ++$port ) {
985
                                my $link =
986
                                        (($level+1)*$chan_per_level - $chan_per_direction)  #which levellevel
987
                                        +$neighborhood*$level_offset   #region in level
988
                                        +$port*$routers_per_branch*$k  #sub region in region
989
                                        +($neighborhood_pos)%$routers_per_branch*$k  #router in subregion
990
                                        +($neighborhood_pos)/$routers_per_branch; #port on router
991
 
992
        #int link = (level*chan_per_level - chan_per_direction) + pos*k + port ;
993
                                my $connect_l= int(($link+$chan_per_direction)/$chan_per_level);
994
                                my $tmp=(($link+$chan_per_direction) % $chan_per_level);
995
                                my $connect_pos= int($tmp/$k);
996
                                my $connect_port= ($tmp%$k)+$k;
997
                                my $id1=$NL*$level+$pos;
998
                                my $connect_id=$NL*$connect_l+$connect_pos;
999 48 alirezamon
                                $dotfile=$dotfile.node_connection('R',$id1,undef,$port,'R',$connect_id,undef,$connect_port,$gtype);
1000 43 alirezamon
                        }
1001
            }
1002
        }
1003
 
1004
        #add endpoints connection
1005 48 alirezamon
        for(my $i=0; $i<$NE; $i++){
1006 43 alirezamon
                my $r= $NL*($nl-1)+int($i/$k);
1007 48 alirezamon
                 $dotfile=$dotfile.node_connection('T',$i,undef,undef,'R',$r,undef,$i%($k),$gtype);
1008 43 alirezamon
 
1009
        }
1010
        $dotfile=$dotfile."\n}\n";
1011
        return $dotfile;
1012
}
1013
 
1014 48 alirezamon
sub generate_star_dot_file{
1015
        my $self=shift;
1016
 
1017
        my $dotfile=
1018
"digraph G {
1019
        graph [layout = neato, fontsize=3, rankdir = LR , splines = true, overlap = false];
1020
        node[shape=record];
1021
        ";
1022
 
1023
        my $pnum=$self->object_get_attribute('noc_param','T1');
1024
        $dotfile.=router_node_dot_sim($pnum,"R","R");
1025
 
1026
        for(my $p=0; $p<$pnum; $p++) {
1027
        $dotfile.=endp_node_dot_sim ("T$p","T$p");
1028
        $dotfile.="R -> T$p [dir=none];\n";
1029
        $dotfile.='#'.node_connection('T',$p,undef,undef,'R',0,undef,$p);
1030
        }
1031
 
1032
        $dotfile.="\n}\n";
1033
        return $dotfile;
1034
}
1035 43 alirezamon
 
1036
 
1037
 
1038 48 alirezamon
 
1039
 
1040
 
1041
 
1042
 
1043
 
1044
 
1045
 
1046
 
1047 43 alirezamon
sub generate_tree_dot_file{
1048
        my $self=shift;
1049 48 alirezamon
        my $gtype=$self->object_get_attribute("tile_diagram","gtype");
1050 43 alirezamon
 
1051
        my $dotfile=
1052
"digraph G {
1053 48 alirezamon
        graph [layout = neato, rankdir = LR , splines = true, overlap = true];
1054 43 alirezamon
        node[shape=record];
1055
        ";
1056
 
1057
 
1058
        my $k=$self->object_get_attribute('noc_param','T1');
1059
        my $nl=$self->object_get_attribute('noc_param','T2');
1060
        #generate routres port interface
1061
        my @bp;
1062
        my @hp;
1063
        for(my $p=0; $p<$k; $p++) {
1064
                push (@bp,"<n$p>") if(($k%2)==0 && $p==$k/2);#if k is odd number add one empty space in the middle
1065
                push (@bp,"<p$p>$p");
1066
 
1067
        }
1068
        for(my $p=$k; $p<2*$k; $p++) {
1069
                if($p==$k+int(($k-1)/2)){
1070
                        push (@hp,"<n$p>") if(($k%2)==0);#if k is odd number add one empty space in the middle
1071
                        push (@hp,"<p$k>$k");
1072
                }else{
1073
                        push (@hp,"<n$p>");
1074
                }
1075
        }
1076
        my $bp= join("|",@bp);
1077
        my $hp= join("|",@hp);
1078 48 alirezamon
#       my ($NE,$NR)=get_topology_info($self);
1079
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info($self);
1080 43 alirezamon
 
1081
 
1082
        #add endpoints
1083
        for(my $i=0; $i<$NE; $i++){
1084
                $dotfile=$dotfile."T$i\[
1085
        label = \"T$i\"
1086
    pos = \"$i,0!\"
1087
    shape=house
1088
    margin=0
1089
        color=orange
1090
        style=filled
1091
        fillcolor=orange
1092
];
1093
";
1094
        }
1095
 
1096
        #add roots
1097 48 alirezamon
        my $label = "\{R0\}|\{$bp\}";
1098 43 alirezamon
        my $x=(($NE-1)/2);
1099
        my $y=  1.5*($nl-1)+1;
1100 48 alirezamon
        $dotfile.=get_router_dot_file("R0",$label,"$x,$y!",$gtype);
1101 43 alirezamon
 
1102 48 alirezamon
 
1103
 
1104 43 alirezamon
        #add leaves
1105
        my $t=1;
1106
 
1107
        for(my $l=$nl-1; $l>0; $l--){
1108
                my $NL = powi($k,$l);
1109
                $t*=$k;
1110
                for(my $pos=0; $pos<$NL; $pos++){
1111
                        my $x=  $t*$pos + ($t-1)/2 ;
1112
                        my $y=  1.5*($nl-$l)-.5;
1113
                        my $r=sum_powi($k,$l)+$pos;
1114 48 alirezamon
        my $label = "\{$hp\}|\{R$r\}|\{$bp\}";
1115
 
1116
        $dotfile.=get_router_dot_file("R$r",$label,"$x,$y!",$gtype);
1117
 
1118
 
1119 43 alirezamon
                }
1120
        }
1121
 
1122
        #add leave connections
1123
        for(my $l=$nl-1; $l>0; $l--){
1124
                my $NL = powi($k,$l);
1125
                for(my $pos=0; $pos<$NL; $pos++){
1126
                        my $id1=sum_powi($k,$l)+$pos;
1127
                        my $id2=sum_powi($k,$l-1)+int($pos/$k);
1128 48 alirezamon
                        $dotfile=$dotfile.node_connection('R',$id1,undef,$k,'R',$id2,undef,$pos % $k,$gtype);
1129 43 alirezamon
                }
1130
        }
1131
 
1132
        #add endpoints connection
1133
        for(my $i=0; $i<$NE; $i++){
1134
                 my $r= sum_powi($k,$nl-1)+int($i/$k);
1135 48 alirezamon
                 $dotfile=$dotfile.node_connection('T',$i,undef,undef,'R',$r,undef,$i%($k),$gtype);
1136 43 alirezamon
 
1137
        }
1138
 
1139
 
1140
 
1141
        $dotfile=$dotfile."\n}\n";
1142
        return $dotfile;
1143
}
1144
 
1145
 
1146
sub get_topology_dot_file{
1147
        my $self=shift;
1148
        my $topology=$self->object_get_attribute('noc_param','TOPOLOGY');
1149 48 alirezamon
        return generate_mesh_dot_file ($self) if($topology eq '"RING"' || $topology eq '"LINE"' || $topology eq '"MESH"'|| $topology eq '"FMESH"' || $topology eq '"TORUS"' );
1150 43 alirezamon
        return generate_fattree_dot_file ($self) if($topology eq '"FATTREE"');
1151 48 alirezamon
        return generate_tree_dot_file($self) if($topology eq '"TREE"');
1152
        return generate_star_dot_file($self) if($topology eq '"STAR"');
1153
 
1154 43 alirezamon
}
1155
 
1156
 
1157 48 alirezamon
sub generate_merge_actor_dot_file{
1158
        my $self=shift;
1159
        my $dotfile=
1160
"digraph G {
1161
        graph [ layout = neato, rankdir = LR , splines=polyline, overlap = false];
1162
 
1163
";
1164
 
1165 43 alirezamon
 
1166 48 alirezamon
 
1167
#add connections
1168 43 alirezamon
 
1169 48 alirezamon
        my @traces= get_trace_list($self,'merge');
1170
        my %src_dst;
1171
        my %dests= get_destport_constant_list ($self,'merge');
1172
        my %srcs = get_srcport_constant_list  ($self,'merge');
1173
 
1174
 
1175
 
1176
        foreach my $p (@traces){
1177
                my ($src,$dst, $Mbytes, $file_id, $file_name,$init_weight,$min_pck, $max_pck,  $burst, $injct_rate, $injct_rate_var,$src_port,$dst_port,$buff_size,$chanel,$vc,$class)
1178
                                =get_trace($self,'merge',$p);
1179
 
1180
 
1181
 
1182
                $dotfile=$dotfile."\"$src\" -> \"$dst\"  [label=\"$srcs{$src}{$src_port}{$chanel}->$dests{$dst}{$dst_port}\" ];\n";
1183
        }
1184
 
1185
        $dotfile=$dotfile."\n}\n";
1186
        return $dotfile;
1187
 
1188
}
1189 43 alirezamon
 
1190
 
1191
 
1192
 
1193
 
1194
 
1195
 
1196
 
1197 48 alirezamon
 
1198 34 alirezamon
return 1;

powered by: WebSVN 2.1.0

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