bsp2arch.pl: initial commit (processor, memory)
[jump.git] / hdf2arch / bsp2arch.pl
1 #!/usr/bin/perl -w
2 use strict;
3 use v5.010;
4
5 use XML::Simple qw(:strict);
6 use Data::Dumper;
7
8 # argument evaluation
9 my $infile  = shift;
10 my $outfile = shift;
11 if(!$infile || !$outfile) {
12         say "Usage: bsp2arch.pl <infile> <outfile>";
13         say "\tinfile:  Epiphany Platform Description";
14         say "\toutfile: DOL Architecture Specification";
15         say "\tUse \'-\' for standard input/output.";
16         exit 1;
17 }
18
19 # parse input xml file
20 my $input = XMLin($infile, ForceArray => '1', KeyAttr => ['chips']);
21
22
23 # per-core definitions
24 my @processors;
25 my @memories;
26 foreach my $chips ($input->{'chips'}->[0]->{'chip'}) {
27         foreach my $chip (@$chips) {
28                 $chip->{'id'} =~ /\((\d+),(\d+)\)/;
29                 my @origin = ($1, $2);
30
31                 foreach my $row (1..$chip->{'rows'}) {
32                         foreach my $col (1..$chip->{'cols'}) {
33                                 my $newrow  = $origin[0] + $row - 1;
34                                 my $newcol  = $origin[1] + $col - 1;
35                                 my $memsize = $chip->{'core_memory_size'};
36                                 $memsize = "0x8000" unless($memsize);
37
38                                 # eCore
39                                 push @processors, {
40                                         'name' => "core_${newrow}_${newcol}",
41                                         'type' => 'RISC',
42                                         'configuration' => [
43                                                 { 'name'  => 'version',
44                                                   'value' => '3' },
45                                         ],
46                                 };
47
48                                 # eCore local memory
49                                 push @memories, {
50                                         'name' => "mem_${newrow}_${newcol}",
51                                         'type' => 'RAM',
52                                         'configuration' => [
53                                                 { 'name'  => 'size',
54                                                   'value' => $memsize },
55                                         ],
56                                 };
57
58                                 # eCore register file
59                                 push @memories, {
60                                         'name' => "regs_${newrow}_${newcol}",
61                                         'type' => 'REG',
62                                 }
63                         }
64                 }
65
66         }
67 }
68
69 # external memory
70 foreach my $banks ($input->{'external_memory'}->[0]->{'bank'}) {
71         my $counter = 0;
72         foreach my $bank (@$banks) {
73                 # DOL doesn't need to know the epiphany-internal address
74                 next if($bank->{'name'} eq 'EPIPHANY_DRAM');
75
76                 if($bank->{'name'} eq 'EXTERNAL_DRAM') {
77                         push @memories, {
78                                 'name' => "emem_${counter}",
79                                 'type' => 'DXM',
80                         };
81                         next;
82                         say "Warning: Unknown Extmem $bank->{'name'}!";
83                 }
84         }
85 }
86
87 # TODO: add hw_channels data
88 my @hw_channels;
89
90 # generate XML output
91 my $output = {
92         'architecture' => {
93                 'xmlns' => "http://www.tik.ee.ethz.ch/~shapes/schema/ARCHITECTURE",
94                 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
95                 'xsi:schemaLocation' => 'http://www.tik.ee.ethz.ch/~shapes/schema/ARCHITECTURE http://www.tik.ee.ethz.ch/~shapes/schema/architecture.xsd',
96                 'name' => 'Adapteva Parallella Architecture',
97
98                 'processor' => \@processors,
99                 'memory' => \@memories,
100                 'hw_channel' => \@hw_channels,
101         },
102 };
103 my $outxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
104                 XMLout($output, KeyAttr => [], KeepRoot => 1);
105
106 # save XML output
107 if($outfile eq '-') {
108         print $outxml;
109         exit 0;
110 } else {
111         open (FH, ">$outfile");
112         print FH $outxml;
113         close (FH);
114 }
115