9 my $url = "http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixassem/alangref/frame9_toc.htm";
13 my ($tag, %attr) = @_;
14 return if $tag ne 'a';
15 foreach my $v (values %attr)
17 $unique_links{$v} = 1 unless $v =~ /javascript|appendix|instr/;
21 my $ua = LWP::UserAgent->new;
23 my $p = HTML::LinkExtor->new(\&callback);
25 my $res = $ua->request(HTTP::Request->new(GET => $url),
26 sub { $p->parse($_[0])});
28 my $base = $res->base;
31 my @links = keys %unique_links;
32 for (@links) { s/\#.*$//; }
33 @links = map {$_ = url($_, $base)->abs; } (@links);
42 my ($self, $text) = @_;
43 ($mnemonic) = ($text =~ /(\S*)\s+/);
44 $self->handler(text => "");
49 my($self, $text) = @_;
51 return unless($text =~ /^[\w|\d|\/|\s]+$/);
56 $text =~ s/^SIMM$/SI/;
57 $text =~ s/^SI\/D$/SI/;
58 $text =~ s/^SI\/UI$/SI/;
63 $mnemonic_info{$mnemonic} .= "$text ";
64 $self->handler(text => "");
68 sub handle_table_entries
70 my($self, $tag, $attr) = @_;
73 if($attr->{'headers'} =~ /COL2/i)
75 $self->handler(text => \&handle_text, "self, dtext");
80 sub restore_default_handler
82 my ($self, $tag) = @_;
85 $self->handler(start => \&check_table_headers, "self, tagname, attr");
92 my($self, $text) = @_;
95 $self->handler(start => \&handle_table_entries, "self, tagname, attr");
96 $self->handler(end => \&restore_default_handler, "self, tagname");
108 sub check_table_headers
110 my($self, $tag, $attr) = @_;
113 if($attr->{'id'} =~ /COL2/i)
115 $self->handler(text => \&check_for_value, "self, dtext");
120 $self->handler(text => \&set_mnemonic, "self, dtext");
125 my $instructionParser = HTML::Parser->new(api_version => 3,
126 handlers => [start => [\&check_table_headers, "self, tagname, attr"],
128 marked_sections => 1);
130 while (my $url = shift(@links))
134 $instructionParser->handler(start => \&check_table_headers, "self, tagname, attr");
135 $res = $ua->request(HTTP::Request->new(GET => $url),
136 sub { $instructionParser->parse($_[0])});
141 my @main_opcode_array;
142 my %extended_opcode_array;
145 foreach my $k(keys %mnemonic_info)
147 my @vals = split(/\s+/, $mnemonic_info{$k});
148 my $primary_opcode = shift @vals;
150 if(exists $main_opcode_array[$primary_opcode])
154 while($i > 0 and not $extended_opcode)
157 $extended_opcode = $vals[$i] if ($vals[$i] =~ /^\d+$/);
159 if(defined $extended_opcode)
161 if($main_opcode_array[$primary_opcode][0] ne "extended")
163 my $tmp_extended_opcode;
164 my $aref = $main_opcode_array[$primary_opcode];
165 my @tmp_vals = @$aref;
167 while($i > 0 and not $tmp_extended_opcode)
170 $tmp_extended_opcode = $tmp_vals[$i] if ($tmp_vals[$i] =~ /^\d+$/);
172 print "@tmp_vals\n" if $tmp_vals[0] =~ /D/;
173 $extended_opcode_array{$primary_opcode}{$tmp_extended_opcode} = [@tmp_vals];
174 $main_opcode_array[$primary_opcode] = ["extended"];
176 print "@vals\n" if $vals[0] =~ /D/;
177 $extended_opcode_array{$primary_opcode}{$extended_opcode} = [@vals];
178 $mnemonics{$vals[0]} = 1;
184 $main_opcode_array[$primary_opcode] = [@vals];
185 $mnemonics{$vals[0]} = 1;
189 my %size_to_result_type = (
203 sub print_table_entry
205 my ($primary_opcode, @data) = @_;
207 map {push (@opcode_data, $_) unless /^[\/\d]*$/; } @data;
208 my $mnem = shift @opcode_data;
213 my ($load, $width, $update, $index) = $mnem =~ /^(l|st)((?:f|m|s|sc|fi)?\w?)(?:z|ar|a|br|c|i)?(u?)(x?)\.?$/;
215 for my $i(0..$#opcode_data)
217 if($opcode_data[$i] eq "D" and $i < $#opcode_data)
219 $opcode_data[$i] = "RT";
221 if($load and $opcode_data[$i] eq "RA")
223 my $load_operand = $load . $update . $index;
224 $load_operand =~ tr/[a-z]/[A-Z]/;
225 splice @opcode_data, $i, 2, "$load_operand<$size_to_result_type{$width}>";
229 my $operands = "operandSpec()";
230 my $next_table = "NULL";
231 if($mnem eq "extended")
233 $next_table = "fn(extended_op_$primary_opcode)";
237 $operands = "list_of(fn(";
238 $operands .= join("))(fn(", @opcode_data);
243 print "power_op_$enum, \"$mnem\", $next_table, $operands";
247 print "enum powerOpcodes {\n";
248 for my $mnem(keys %mnemonics)
251 print "\tpower_op_$mnem,\n";
255 print "power_entry power_entry::main_opcode_table\[\] = {\n";
256 for my $i(0..$#main_opcode_array)
259 print_table_entry($i, @{$main_opcode_array[$i]});
264 foreach my $primary(sort {$a <=> $b} keys %extended_opcode_array)
266 print "std::map<unsigned int,power_entry> power_entry::extended_op_$primary = map_list_of\n";
267 foreach my $extended(sort {$a <=> $b} keys %{$extended_opcode_array{$primary}})
269 print "\t($extended, power_entry(";
270 print_table_entry($primary, @{$extended_opcode_array{$primary}{$extended}});