Rev 153 | Rev 231 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 153 | Rev 222 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | # Read in the file, storing information about each pin.
|
14 | # Read in the file, storing information about each pin.
|
15 | 15 | ||
16 | my $pinnumwidth = 0; |
16 | my $pinnumwidth = 0; |
17 | my $blockname; |
17 | my $blockname; |
18 | 18 | ||
- | 19 | # vars used later too
|
|
- | 20 | my (%x, %y); |
|
- | 21 | ||
- | 22 | # vars used during parsing
|
|
- | 23 | my ($side, $busmode, $errors) = ('',0, 0); |
|
- | 24 | # main loop which parses file
|
|
19 | while (<>) { |
25 | while (<>) { |
- | 26 | # skip empty lines
|
|
20 | next if /^#/; |
27 | next if /^#/; |
- | 28 | ||
- | 29 | # cleanup leading/trailing spaces
|
|
21 | s/^\s+//; |
30 | s/^\s+//; |
22 | s/\s+$//; |
31 | s/\s+$//; |
- | 32 | ||
- | 33 | # convert spaces/tabs sequence to single space
|
|
23 | s/[\s\t]+/ /g; |
34 | s/[\s\t]+/ /g; |
- | 35 | ||
- | 36 | # remove all CR/LF newlines
|
|
24 | s/[\r\n]+$//; |
37 | s/[\r\n]+$//; |
25 | 38 | ||
26 | # Note change of section.
|
39 | # Note change of section.
|
27 | if (/^\[(.*)\]/) { |
40 | if (/^\[(.*)\]/) { |
28 | $side = $1; |
41 | $side = $1; |
29 | $space = 0; |
42 | $space = 0; |
30 | next; |
43 | next; |
31 | }
|
44 | }
|
32 | 45 | ||
33 | # Start a bus
|
46 | # Start a bus
|
34 | if (/^\.bus/) { |
47 | if (/^\.bus/) { |
35 | $busmode = 1; |
48 | $busmode = 1; |
36 | next; |
49 | next; |
37 | }
|
50 | }
|
38 | 51 | ||
39 | # blank lines - cancel bus, add gap.
|
52 | # blank lines - cancel bus, add gap.
|
40 | if (! /\S/) { |
53 | if (! /\S/) { |
41 | if ($busmode) { |
54 | if ($busmode) { |
42 | $y{$side} += 200; |
55 | $y{$side} += 200; |
43 | }
|
- | |
44 | $busmode = 0; |
56 | $busmode = 0; |
- | 57 | }
|
|
45 | if ($space) { |
58 | if ($space) { |
46 | if ($side =~ /left|right/) { |
59 | if ($side =~ /left|right/) { |
47 | $y{$side} += 300; |
60 | $y{$side} += 300; |
48 | }
|
- | |
49 | if ($side =~ /top|bottom/) { |
61 | } elsif ($side =~ /top|bottom/) { |
50 | $x{$side} += 400; |
62 | $x{$side} += 400; |
51 | }
|
63 | }
|
52 | $space = 0; |
64 | $space = 0; |
53 | }
|
65 | }
|
54 | next; |
- | |
55 | }
|
- | |
56 | - | ||
57 | # Hidden labels are stored separately, because we don't care how
|
- | |
58 | # big they are.
|
- | |
59 | if (/! (\S.*)/ && $side eq "labels") { |
- | |
60 | push(@attrs, $1); |
- | |
61 | next; |
- | |
62 | }
|
- | |
63 | - | ||
64 | # Visible labels are stored as pins because their size affects the
|
- | |
65 | # size of the symbols' box.
|
- | |
66 | if (/\S/ && $side eq "labels") { |
- | |
67 | if ($_ =~ /^block=/) { |
- | |
68 | $blockname = $_; |
- | |
69 | #printf STDERR "Blocname %s\n", $blockname;
|
- | |
70 | next; |
66 | next; |
71 | }
|
67 | }
|
72 | $labelpin --; |
- | |
73 | $pinside{$labelpin} = $side; |
- | |
74 | $piny{$labelpin} = $y{labels}; |
- | |
75 | $pinlabel{$labelpin} = $_; |
- | |
76 | $y{labels} -= 200; |
- | |
77 | $rlen{$labelpin} = &textlen($_); |
- | |
78 | next; |
- | |
79 | }
|
- | |
80 | 68 | ||
81 | # Regular pins are handled here.
|
- | |
82 | if (/^([0-9A-Za-z]+)\s*(.*)/) { |
- | |
83 | $space = 1; |
- | |
84 | ($pin, $rest) = ($1,$2); |
- | |
85 | 69 | ||
86 | if ($saw_pin{$pin}) { |
- | |
87 | print STDERR "DUPLICATE PIN $pin (was $pinlabel{$pin}, now $rest)\n"; |
70 | # Hidden labels are stored separately, because we don't care how
|
88 | $errors ++; |
71 | # big they are.
|
89 | }
|
- | |
90 | $saw_pin{$pin} = 1; |
- | |
91 | $maxpin = $pin if $maxpin < $pin; |
- | |
92 | - | ||
93 | $pinside{$pin} = $side; |
- | |
94 | next if $side eq "nc"; |
72 | if (/! (\S.*)/ && $side eq "labels") { |
95 | if ($rest =~ /^([!>]+) (.*)/) { |
73 | # code probably could be more smart and store labels ex in certain order
|
96 | $flags = $1; |
74 | push(@attrs, $1); |
97 | $pinlabel{$pin} = $2; |
- | |
98 | $bubble{$pin} = 1 if $flags =~ /!/; |
- | |
99 | $edge{$pin} = 1 if $flags =~ />/; |
- | |
100 | } else { |
75 | next; |
101 | $pinlabel{$pin} = $rest; |
- | |
102 | }
|
- | |
103 | $rlen{$pin} = &textlen($pinlabel{$pin}); |
- | |
104 | - | ||
105 | if ($pinnumwidth < &textlen($pin)) { |
- | |
106 | $pinnumwidth = &textlen($pin); |
- | |
107 | }
|
- | |
108 | - | ||
109 | if ($side =~ /left|right/) { |
- | |
110 | $y = $piny{$pin} = $y{$side}; |
- | |
111 | $y{$side} += ($busmode ? 200 : 300); |
- | |
112 | }
|
- | |
113 | if ($side =~ /top|bottom/) { |
- | |
114 | $tw = &alignpin((200 + $rlen{$pin}) / 2); |
- | |
115 | $pinx{$pin} = $w{$side} + $tw; |
- | |
116 | $w{$side} += $tw + $tw; |
- | |
117 | }
|
76 | }
|
118 | 77 | ||
- | 78 | # Visible labels are stored as pins because their size affects the
|
|
- | 79 | # size of the symbols' box.
|
|
- | 80 | if (/\S/ && $side eq "labels") { |
|
- | 81 | # an blockswith
|
|
- | 82 | if ($_ =~ /^block=/) { |
|
- | 83 | $blockname = $_; |
|
- | 84 | # printf STDERR "Blocname %s\n", $blockname;
|
|
- | 85 | next; |
|
- | 86 | }
|
|
- | 87 | ||
- | 88 | $labelpin --; |
|
- | 89 | $pinside{$labelpin} = $side; |
|
- | 90 | $piny{$labelpin} = $y{labels}; |
|
- | 91 | $pinlabel{$labelpin} = $_; |
|
- | 92 | $y{labels} -= 200; |
|
- | 93 | $rlen{$labelpin} = &textlen($_); |
|
- | 94 | next; |
|
- | 95 | }
|
|
- | 96 | ||
- | 97 | # Regular pins are handled here.
|
|
- | 98 | if (/^([0-9A-Za-z]+)\s*(.*)/) { |
|
- | 99 | $space = 1; |
|
- | 100 | ($pin, $rest) = ($1,$2); |
|
- | 101 | ||
- | 102 | if ($saw_pin{$pin}) { |
|
- | 103 | print STDERR "DUPLICATE PIN $pin (was $pinlabel{$pin}, now $rest)\n"; |
|
- | 104 | $errors ++; |
|
- | 105 | }
|
|
- | 106 | ||
- | 107 | $saw_pin{$pin} = 1; |
|
- | 108 | # our symbols use letters in names so next line wents wrong imo
|
|
- | 109 | # we have two solutions, use numbers only (hard for BGA or sth like that)
|
|
- | 110 | # or rework symdefs that we would get:
|
|
- | 111 | # <#pin> <pin-number from datasheet> <pinname> <pintype> <other attributes>
|
|
- | 112 | $maxpin = $pin if $maxpin < $pin; |
|
- | 113 | ||
- | 114 | $pinside{$pin} = $side; |
|
- | 115 | ||
- | 116 | next if $side eq "nc"; |
|
- | 117 | ||
- | 118 | if ($rest =~ /^([!>]+) (.*)/) { |
|
- | 119 | $flags = $1; |
|
- | 120 | $pinlabel{$pin} = $2; |
|
- | 121 | $bubble{$pin} = 1 if $flags =~ /!/; |
|
- | 122 | $edge{$pin} = 1 if $flags =~ />/; |
|
- | 123 | } else { |
|
- | 124 | $pinlabel{$pin} = $rest; |
|
- | 125 | }
|
|
- | 126 | ||
- | 127 | $rlen{$pin} = &textlen($pinlabel{$pin}); |
|
- | 128 | ||
- | 129 | if ($pinnumwidth < &textlen($pin)) { |
|
- | 130 | $pinnumwidth = &textlen($pin); |
|
- | 131 | }
|
|
- | 132 | ||
- | 133 | if ($side =~ /left|right/) { |
|
- | 134 | $y = $piny{$pin} = $y{$side}; |
|
- | 135 | $y{$side} += ($busmode ? 200 : 300); |
|
- | 136 | }
|
|
- | 137 | ||
- | 138 | if ($side =~ /top|bottom/) { |
|
- | 139 | $tw = &alignpin((200 + $rlen{$pin}) / 2); |
|
- | 140 | $pinx{$pin} = $w{$side} + $tw; |
|
- | 141 | $w{$side} += $tw + $tw; |
|
119 | }
|
142 | }
|
- | 143 | ||
- | 144 | }
|
|
120 | 145 | ||
121 | }
|
146 | }
|
122 | 147 | ||
- | 148 | # parser finished here
|
|
- | 149 | ||
- | 150 | # round to nearest multiple of 100 larger or equal to actual number
|
|
123 | $pinnumwidth += 100 - ($pinnumwidth % 100); |
151 | $pinnumwidth += 100 - ($pinnumwidth % 100); |
124 | 152 | ||
125 | $minpin = $labelpin; |
153 | $minpin = $labelpin; |
126 | $boxwidth = 0; |
154 | $boxwidth = 0; |
127 | %bw = (); |
155 | %bw = (); |
Line 130... | Line 158... | ||
130 | # width is used up by the left, middle, and right labels.
|
158 | # width is used up by the left, middle, and right labels.
|
131 | for $lp (keys %pinside) { |
159 | for $lp (keys %pinside) { |
132 | next unless $pinside{$lp} =~ /left|right|label/; |
160 | next unless $pinside{$lp} =~ /left|right|label/; |
133 | $yb = &alignpin($piny{$lp}); |
161 | $yb = &alignpin($piny{$lp}); |
134 | for ($y=$yb-100; $y<=$yb+100; $y+=100) { |
162 | for ($y=$yb-100; $y<=$yb+100; $y+=100) { |
- | 163 | # again we got not numbers inside, so lt/gt operator dont work well.. need to track why and how fix
|
|
135 | if ($bw{$y}{$pinside{$lp}} < $rlen{$lp}) { |
164 | if ($bw{$y}{$pinside{$lp}} < $rlen{$lp}) { |
136 | $bw{$y}{$pinside{$lp}} = $rlen{$lp}; |
165 | $bw{$y}{$pinside{$lp}} = $rlen{$lp}; |
137 | }
|
166 | }
|
138 | }
|
167 | }
|
139 | }
|
168 | }
|
140 | 169 | ||
141 | # Compute the height of the box.
|
170 | # Compute the height of the box.
|
142 | for $p (keys %pinside) { |
171 | for $p (keys %pinside) { |
143 | next unless $pinside{$p} =~ /left|right/; |
172 | next unless $pinside{$p} =~ /left|right/; |
144 | if ($maxy < $piny{$p}) { |
173 | if ($maxy < $piny{$p}) { |
145 | $maxy = $piny{$p}; |
174 | $maxy = $piny{$p}; |
146 | }
|
175 | }
|
147 | }
|
176 | }
|
148 | $maxy += 300; |
177 | $maxy += 300; |
149 | 178 | ||
150 | # Now, use the slice widths to compute the minimum width of the box.
|
179 | # Now, use the slice widths to compute the minimum width of the box.
|
151 | for ($i=0; $i<$maxy; $i+=100) { |
180 | for ($i=0; $i<$maxy; $i+=100) { |
- | 181 | my $w = 0; |
|
- | 182 | ||
- | 183 | $w += $bw{$i}{left} if (defined $bw{$i}{left}); |
|
- | 184 | $w += $bw{$i}{labels} if (defined $bw{$i}{labels}); |
|
152 | $w = $bw{$i}{left} + $bw{$i}{labels} + $bw{$i}{right}; |
185 | $w += $bw{$i}{right} if (defined $bw{$i}{right}); |
- | 186 | ||
153 | if ($bw{$i}{labels}) { |
187 | if ($bw{$i}{labels}) { |
154 | $wl = ($bw{$i}{left} + $bw{$i}{labels}/2) * 2; |
188 | $wl = ($bw{$i}{left} + $bw{$i}{labels}/2) * 2; |
155 | $w = $wl if $w < $wl; |
189 | $w = $wl if $w < $wl; |
156 | $wl = ($bw{$i}{right} + $bw{$i}{labels}/2) * 2; |
190 | $wl = ($bw{$i}{right} + $bw{$i}{labels}/2) * 2; |
157 | $w = $wl if $w < $wl; |
191 | $w = $wl if $w < $wl; |
158 | }
|
192 | }
|
- | 193 | # need to review that if()'s
|
|
159 | if ($bw{$i}{left} && $bw{$i}{labels}) { |
194 | if ($bw{$i}{left} && $bw{$i}{labels}) { |
160 | $w += 100; |
195 | $w += 100; |
161 | } elsif ($bw{$i}{left} && $bw{$i}{right}) { |
196 | } elsif ($bw{$i}{left} && $bw{$i}{right}) { |
162 | $w += 200; |
197 | $w += 200; |
163 | }
|
198 | }
|
Line 241... | Line 276... | ||
241 | if(defined $blockname) { |
276 | if(defined $blockname) { |
242 | printf("T %d %d 5 10 1 1 0 6 1\n%s\n", $boxwidth + $pinnumwidth, $maxy + 400, $blockname); |
277 | printf("T %d %d 5 10 1 1 0 6 1\n%s\n", $boxwidth + $pinnumwidth, $maxy + 400, $blockname); |
243 | }
|
278 | }
|
244 | 279 | ||
245 | # Now print all the pins.
|
280 | # Now print all the pins.
|
- | 281 | # and here non digit numbers bug us too, so we need to rework..
|
|
246 | for $p (sort {$a<=>$b} keys %pinside) { |
282 | for $p (sort {$a<=>$b} keys %pinside) { |
247 | next unless $pinside{$p}; |
283 | next unless $pinside{$p}; |
248 | if ($pinside{$p} eq "left") { |
284 | if ($pinside{$p} eq "left") { |
249 | $pinx{$p} = $pinnumwidth; |
285 | $pinx{$p} = $pinnumwidth; |
250 | }
|
286 | }
|
251 | if ($pinside{$p} eq "right") { |
287 | if ($pinside{$p} eq "right") { |
252 | $pinx{$p} = $pinnumwidth + $boxwidth; |
288 | $pinx{$p} = $pinnumwidth + $boxwidth; |
253 | }
|
289 | }
|
- | 290 | # here we get warning about undefined value in addition, probably one of things isnt defined..
|
|
254 | if ($p > 0 && !$saw_pin{$p}) { |
291 | if ($p > 0 && !$saw_pin{$p}) { |
255 | print STDERR "MISSING PIN $p\n"; |
292 | print STDERR "MISSING PIN $p\n"; |
256 | $errors++; |
293 | $errors++; |
257 | } else { |
294 | } else { |
258 | printf STDERR ("%3d %-6s %4d %4d %s\n", |
295 | printf STDERR ("%3d %-6s %4d %4d %s\n", |