5 use XML::Simple qw(:strict);
25 if(!$infile || !$outfile) {
26 say "Usage: hdf2arch <infile> <outfile>";
27 say "\tinfile: Epiphany HDF file";
28 say "\toutfile: DOL XML file";
29 say "\tSpecify '-' to use standard input/output";
34 my $num_chips; # number of chips in system
35 my @chiplist; # information about current chip
36 my $chipnum = -1; # current chip
37 my $num_emems; # number of emems in system
38 my @ememlist; # information about current emem
39 my $ememnum = -1; # current emem
40 open (FH, "<$infile") or die("Can't open $infile.");
42 next if /\/\/.*/; # skip comment lines
44 # globals - ignore them for now
45 #$data->{'version'} = $1 if(/^PLATFORM_VERSION\s+(\S+)\s*$/);
46 #$data->{'regbase'} = $1 if(/^ESYS_REGS_BASE\s+(\S+)\s*$/);
50 if(/^NUM_CHIPS\s+(\S+)\s*$/) {
54 say STDERR "Warning: multiple 'NUM_CHIPS' entries!";
58 # per-chip information
59 if(/^CHIP\s+(\S+)\s*$/) {
63 $chiplist[$chipnum]->{'id'} = $id;
64 $chiplist[$chipnum]->{'rows'} =
65 $chips->{$id}->{'cores'}->[0];
66 $chiplist[$chipnum]->{'cols'} =
67 $chips->{$id}->{'cores'}->[1];
68 $chiplist[$chipnum]->{'sram'} = $chips->{$id}->{'sram'};
70 say STDERR "Warning: unknown CHIP '$id' - ignoring!";
74 $chiplist[$chipnum]->{'row'} = $1 if(/^CHIP_ROW\s+(\S+)\s*$/);
75 $chiplist[$chipnum]->{'col'} = $1 if(/^CHIP_COL\s+(\S+)\s*$/);
78 if(/^NUM_EXT_MEMS\s+(\S+)\s*$/) {
82 say STDERR "Warning: multiple 'NUM_EXT_EMEM' entries!";
87 # per-emem information
88 if(/^EMEM\s+(\S+)\s*$/) {
90 if($id eq 'ext-DRAM') {
92 $ememlist[$ememnum]->{'id'} = $id;
94 say STDERR "Warning: unknown EMEM '$id' - ignoring!";
98 $ememlist[$ememnum]->{'base'} = $1 if(/^EMEM_BASE_ADDRESS\s+(\S+)\s*$/);
99 $ememlist[$ememnum]->{'epi'} = $1 if(/^EMEM_EPI_BASE\s+(\S+)\s*$/);
100 $ememlist[$ememnum]->{'size'} = $1 if(/^EMEM_SIZE\s+(\S+)\s*$/);
101 $ememlist[$ememnum]->{'type'} = $1 if(/^EMEM_TYPE\s+(\S+)\s*$/);
104 # some simple consistency checks
105 if($num_chips != scalar @chiplist) {
106 say STDERR "Warning: NUM_CHIPS does not match the number of CHIPs!";
108 if($num_emems != scalar @ememlist) {
109 say STDERR "Warning: NUM_EXT_MEMS does not match the number of EMEMs!";
112 # generate output data
113 $data->{'processor'} = [];
114 $data->{'memory'} = [];
116 # host processor, epiphany cores and their memories
117 push $data->{'processor'}, {
126 for my $chip(@chiplist) {
127 for my $row (0..$chip->{'rows'}-1) {
128 for my $col (0..$chip->{'cols'}-1) {
129 my $r = $chip->{'row'} + $row;
130 my $c = $chip->{'col'} + $col;
131 push $data->{'processor'}, {
132 'name' => "core_${r}_${c}",
136 'value' => $chip->{'id'}, },
140 push $data->{'memory'}, {
141 'name' => "mem_${r}_${c}",
145 'value' => $chip->{'sram'}, },
153 for my $idx(0..(scalar @ememlist-1)) {
154 push $data->{'memory'}, {
155 'name' => "shm_$idx",
159 'value' => $ememlist[$idx]->{'size'} },
161 'value' => $ememlist[$idx]->{'type'} },
163 'value' => $ememlist[$idx]->{'base'} },
164 { 'name' => 'epibase',
165 'value' => $ememlist[$idx]->{'epi'} },
172 # write data in xml format
173 $data->{'name'} = 'Adapteva Parallella Architecture';
174 $data->{'xmlns'} = 'http://www.tik.ee.ethz.ch/~shapes/schema/ARCHITECTURE';
175 $data->{'xmlns:xsi'} = 'http://www.w3.org/2001/XMLSchema-instance';
176 $data->{'xsi:schemaLocation'} = 'http://www.tik.ee.ethz.ch/~shapes/schema/ARCHITECTURE http://www.tik.ee.ethz.ch/~shapes/schema/architecture.xsd';
177 my $outxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
178 XMLout({'architecture' => $data},
182 if($outfile eq '-') {
186 open (FH, ">$outfile");