| 1 | # B.pm |
| 2 | # |
| 3 | # Copyright (c) 1996, 1997, 1998 Malcolm Beattie |
| 4 | # |
| 5 | # You may distribute under the terms of either the GNU General Public |
| 6 | # License or the Artistic License, as specified in the README file. |
| 7 | # |
| 8 | package B; |
| 9 | use XSLoader (); |
| 10 | require Exporter; |
| 11 | @ISA = qw(Exporter); |
| 12 | @EXPORT_OK = qw(minus_c ppname save_BEGINs |
| 13 | class peekop cast_I32 cstring cchar hash threadsv_names |
| 14 | main_root main_start main_cv svref_2object opnumber amagic_generation |
| 15 | walkoptree_slow walkoptree walkoptree_exec walksymtable |
| 16 | parents comppadlist sv_undef compile_stats timing_info |
| 17 | begin_av init_av end_av); |
| 18 | sub OPf_KIDS (); |
| 19 | use strict; |
| 20 | @B::SV::ISA = 'B::OBJECT'; |
| 21 | @B::NULL::ISA = 'B::SV'; |
| 22 | @B::PV::ISA = 'B::SV'; |
| 23 | @B::IV::ISA = 'B::SV'; |
| 24 | @B::NV::ISA = 'B::IV'; |
| 25 | @B::RV::ISA = 'B::SV'; |
| 26 | @B::PVIV::ISA = qw(B::PV B::IV); |
| 27 | @B::PVNV::ISA = qw(B::PV B::NV); |
| 28 | @B::PVMG::ISA = 'B::PVNV'; |
| 29 | @B::PVLV::ISA = 'B::PVMG'; |
| 30 | @B::BM::ISA = 'B::PVMG'; |
| 31 | @B::AV::ISA = 'B::PVMG'; |
| 32 | @B::GV::ISA = 'B::PVMG'; |
| 33 | @B::HV::ISA = 'B::PVMG'; |
| 34 | @B::CV::ISA = 'B::PVMG'; |
| 35 | @B::IO::ISA = 'B::PVMG'; |
| 36 | @B::FM::ISA = 'B::CV'; |
| 37 | |
| 38 | @B::OP::ISA = 'B::OBJECT'; |
| 39 | @B::UNOP::ISA = 'B::OP'; |
| 40 | @B::BINOP::ISA = 'B::UNOP'; |
| 41 | @B::LOGOP::ISA = 'B::UNOP'; |
| 42 | @B::LISTOP::ISA = 'B::BINOP'; |
| 43 | @B::SVOP::ISA = 'B::OP'; |
| 44 | @B::PADOP::ISA = 'B::OP'; |
| 45 | @B::PVOP::ISA = 'B::OP'; |
| 46 | @B::CVOP::ISA = 'B::OP'; |
| 47 | @B::LOOP::ISA = 'B::LISTOP'; |
| 48 | @B::PMOP::ISA = 'B::LISTOP'; |
| 49 | @B::COP::ISA = 'B::OP'; |
| 50 | |
| 51 | @B::SPECIAL::ISA = 'B::OBJECT'; |
| 52 | |
| 53 | { |
| 54 | # Stop "-w" from complaining about the lack of a real B::OBJECT class |
| 55 | package B::OBJECT; |
| 56 | } |
| 57 | |
| 58 | my $debug; |
| 59 | my $op_count = 0; |
| 60 | my @parents = (); |
| 61 | |
| 62 | sub debug { |
| 63 | my ($class, $value) = @_; |
| 64 | $debug = $value; |
| 65 | walkoptree_debug($value); |
| 66 | } |
| 67 | |
| 68 | sub class { |
| 69 | my $obj = shift; |
| 70 | my $name = ref $obj; |
| 71 | $name =~ s/^.*:://; |
| 72 | return $name; |
| 73 | } |
| 74 | |
| 75 | sub parents { \@parents } |
| 76 | |
| 77 | # For debugging |
| 78 | sub peekop { |
| 79 | my $op = shift; |
| 80 | return sprintf("%s (0x%x) %s", class($op), $$op, $op->name); |
| 81 | } |
| 82 | |
| 83 | sub walkoptree { |
| 84 | my($op, $method, $level) = @_; |
| 85 | $op_count++; # just for statistics |
| 86 | $level ||= 0; |
| 87 | warn(sprintf("walkoptree: %d. %s\n", $level, peekop($op))) if $debug; |
| 88 | $op->$method($level); |
| 89 | if ($$op && ($op->flags & OPf_KIDS)) { |
| 90 | my $kid; |
| 91 | unshift(@parents, $op); |
| 92 | for ($kid = $op->first; $$kid; $kid = $kid->sibling) { |
| 93 | walkoptree($kid, $method, $level + 1); |
| 94 | } |
| 95 | shift @parents; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | *walkoptree_slow = \&walkoptree; # Who is using this? |
| 100 | |
| 101 | sub compile_stats { |
| 102 | return "Total number of OPs processed: $op_count\n"; |
| 103 | } |
| 104 | |
| 105 | sub timing_info { |
| 106 | my ($sec, $min, $hr) = localtime; |
| 107 | my ($user, $sys) = times; |
| 108 | sprintf("%02d:%02d:%02d user=$user sys=$sys", |
| 109 | $hr, $min, $sec, $user, $sys); |
| 110 | } |
| 111 | |
| 112 | my %symtable; |
| 113 | |
| 114 | sub clearsym { |
| 115 | %symtable = (); |
| 116 | } |
| 117 | |
| 118 | sub savesym { |
| 119 | my ($obj, $value) = @_; |
| 120 | # warn(sprintf("savesym: sym_%x => %s\n", $$obj, $value)); # debug |
| 121 | $symtable{sprintf("sym_%x", $$obj)} = $value; |
| 122 | } |
| 123 | |
| 124 | sub objsym { |
| 125 | my $obj = shift; |
| 126 | return $symtable{sprintf("sym_%x", $$obj)}; |
| 127 | } |
| 128 | |
| 129 | sub walkoptree_exec { |
| 130 | my ($op, $method, $level) = @_; |
| 131 | my ($sym, $ppname); |
| 132 | my $prefix = " " x $level; |
| 133 | for (; $$op; $op = $op->next) { |
| 134 | $sym = objsym($op); |
| 135 | if (defined($sym)) { |
| 136 | print $prefix, "goto $sym\n"; |
| 137 | return; |
| 138 | } |
| 139 | savesym($op, sprintf("%s (0x%lx)", class($op), $$op)); |
| 140 | $op->$method($level); |
| 141 | $ppname = $op->name; |
| 142 | if ($ppname =~ |
| 143 | /^(or|and|mapwhile|grepwhile|entertry|range|cond_expr)$/) |
| 144 | { |
| 145 | print $prefix, uc($1), " => {\n"; |
| 146 | walkoptree_exec($op->other, $method, $level + 1); |
| 147 | print $prefix, "}\n"; |
| 148 | } elsif ($ppname eq "match" || $ppname eq "subst") { |
| 149 | my $pmreplstart = $op->pmreplstart; |
| 150 | if ($$pmreplstart) { |
| 151 | print $prefix, "PMREPLSTART => {\n"; |
| 152 | walkoptree_exec($pmreplstart, $method, $level + 1); |
| 153 | print $prefix, "}\n"; |
| 154 | } |
| 155 | } elsif ($ppname eq "substcont") { |
| 156 | print $prefix, "SUBSTCONT => {\n"; |
| 157 | walkoptree_exec($op->other->pmreplstart, $method, $level + 1); |
| 158 | print $prefix, "}\n"; |
| 159 | $op = $op->other; |
| 160 | } elsif ($ppname eq "enterloop") { |
| 161 | print $prefix, "REDO => {\n"; |
| 162 | walkoptree_exec($op->redoop, $method, $level + 1); |
| 163 | print $prefix, "}\n", $prefix, "NEXT => {\n"; |
| 164 | walkoptree_exec($op->nextop, $method, $level + 1); |
| 165 | print $prefix, "}\n", $prefix, "LAST => {\n"; |
| 166 | walkoptree_exec($op->lastop, $method, $level + 1); |
| 167 | print $prefix, "}\n"; |
| 168 | } elsif ($ppname eq "subst") { |
| 169 | my $replstart = $op->pmreplstart; |
| 170 | if ($$replstart) { |
| 171 | print $prefix, "SUBST => {\n"; |
| 172 | walkoptree_exec($replstart, $method, $level + 1); |
| 173 | print $prefix, "}\n"; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | sub walksymtable { |
| 180 | my ($symref, $method, $recurse, $prefix) = @_; |
| 181 | my $sym; |
| 182 | my $ref; |
| 183 | no strict 'vars'; |
| 184 | local(*glob); |
| 185 | $prefix = '' unless defined $prefix; |
| 186 | while (($sym, $ref) = each %$symref) { |
| 187 | *glob = "*main::".$prefix.$sym; |
| 188 | if ($sym =~ /::$/) { |
| 189 | $sym = $prefix . $sym; |
| 190 | if ($sym ne "main::" && $sym ne "<none>::" && &$recurse($sym)) { |
| 191 | walksymtable(\%glob, $method, $recurse, $sym); |
| 192 | } |
| 193 | } else { |
| 194 | svref_2object(\*glob)->EGV->$method(); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | { |
| 200 | package B::Section; |
| 201 | my $output_fh; |
| 202 | my %sections; |
| 203 | |
| 204 | sub new { |
| 205 | my ($class, $section, $symtable, $default) = @_; |
| 206 | $output_fh ||= FileHandle->new_tmpfile; |
| 207 | my $obj = bless [-1, $section, $symtable, $default], $class; |
| 208 | $sections{$section} = $obj; |
| 209 | return $obj; |
| 210 | } |
| 211 | |
| 212 | sub get { |
| 213 | my ($class, $section) = @_; |
| 214 | return $sections{$section}; |
| 215 | } |
| 216 | |
| 217 | sub add { |
| 218 | my $section = shift; |
| 219 | while (defined($_ = shift)) { |
| 220 | print $output_fh "$section->[1]\t$_\n"; |
| 221 | $section->[0]++; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | sub index { |
| 226 | my $section = shift; |
| 227 | return $section->[0]; |
| 228 | } |
| 229 | |
| 230 | sub name { |
| 231 | my $section = shift; |
| 232 | return $section->[1]; |
| 233 | } |
| 234 | |
| 235 | sub symtable { |
| 236 | my $section = shift; |
| 237 | return $section->[2]; |
| 238 | } |
| 239 | |
| 240 | sub default { |
| 241 | my $section = shift; |
| 242 | return $section->[3]; |
| 243 | } |
| 244 | |
| 245 | sub output { |
| 246 | my ($section, $fh, $format) = @_; |
| 247 | my $name = $section->name; |
| 248 | my $sym = $section->symtable || {}; |
| 249 | my $default = $section->default; |
| 250 | |
| 251 | seek($output_fh, 0, 0); |
| 252 | while (<$output_fh>) { |
| 253 | chomp; |
| 254 | s/^(.*?)\t//; |
| 255 | if ($1 eq $name) { |
| 256 | s{(s\\_[0-9a-f]+)} { |
| 257 | exists($sym->{$1}) ? $sym->{$1} : $default; |
| 258 | }ge; |
| 259 | printf $fh $format, $_; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | XSLoader::load 'B'; |
| 266 | |
| 267 | 1; |
| 268 | |
| 269 | __END__ |
| 270 | |
| 271 | =head1 NAME |
| 272 | |
| 273 | B - The Perl Compiler |
| 274 | |
| 275 | =head1 SYNOPSIS |
| 276 | |
| 277 | use B; |
| 278 | |
| 279 | =head1 DESCRIPTION |
| 280 | |
| 281 | The C<B> module supplies classes which allow a Perl program to delve |
| 282 | into its own innards. It is the module used to implement the |
| 283 | "backends" of the Perl compiler. Usage of the compiler does not |
| 284 | require knowledge of this module: see the F<O> module for the |
| 285 | user-visible part. The C<B> module is of use to those who want to |
| 286 | write new compiler backends. This documentation assumes that the |
| 287 | reader knows a fair amount about perl's internals including such |
| 288 | things as SVs, OPs and the internal symbol table and syntax tree |
| 289 | of a program. |
| 290 | |
| 291 | =head1 OVERVIEW OF CLASSES |
| 292 | |
| 293 | The C structures used by Perl's internals to hold SV and OP |
| 294 | information (PVIV, AV, HV, ..., OP, SVOP, UNOP, ...) are modelled on a |
| 295 | class hierarchy and the C<B> module gives access to them via a true |
| 296 | object hierarchy. Structure fields which point to other objects |
| 297 | (whether types of SV or types of OP) are represented by the C<B> |
| 298 | module as Perl objects of the appropriate class. The bulk of the C<B> |
| 299 | module is the methods for accessing fields of these structures. Note |
| 300 | that all access is read-only: you cannot modify the internals by |
| 301 | using this module. |
| 302 | |
| 303 | =head2 SV-RELATED CLASSES |
| 304 | |
| 305 | B::IV, B::NV, B::RV, B::PV, B::PVIV, B::PVNV, B::PVMG, B::BM, B::PVLV, |
| 306 | B::AV, B::HV, B::CV, B::GV, B::FM, B::IO. These classes correspond in |
| 307 | the obvious way to the underlying C structures of similar names. The |
| 308 | inheritance hierarchy mimics the underlying C "inheritance". Access |
| 309 | methods correspond to the underlying C macros for field access, |
| 310 | usually with the leading "class indication" prefix removed (Sv, Av, |
| 311 | Hv, ...). The leading prefix is only left in cases where its removal |
| 312 | would cause a clash in method name. For example, C<GvREFCNT> stays |
| 313 | as-is since its abbreviation would clash with the "superclass" method |
| 314 | C<REFCNT> (corresponding to the C function C<SvREFCNT>). |
| 315 | |
| 316 | =head2 B::SV METHODS |
| 317 | |
| 318 | =over 4 |
| 319 | |
| 320 | =item REFCNT |
| 321 | |
| 322 | =item FLAGS |
| 323 | |
| 324 | =back |
| 325 | |
| 326 | =head2 B::IV METHODS |
| 327 | |
| 328 | =over 4 |
| 329 | |
| 330 | =item IV |
| 331 | |
| 332 | =item IVX |
| 333 | |
| 334 | =item needs64bits |
| 335 | |
| 336 | =item packiv |
| 337 | |
| 338 | =back |
| 339 | |
| 340 | =head2 B::NV METHODS |
| 341 | |
| 342 | =over 4 |
| 343 | |
| 344 | =item NV |
| 345 | |
| 346 | =item NVX |
| 347 | |
| 348 | =back |
| 349 | |
| 350 | =head2 B::RV METHODS |
| 351 | |
| 352 | =over 4 |
| 353 | |
| 354 | =item RV |
| 355 | |
| 356 | =back |
| 357 | |
| 358 | =head2 B::PV METHODS |
| 359 | |
| 360 | =over 4 |
| 361 | |
| 362 | =item PV |
| 363 | |
| 364 | =back |
| 365 | |
| 366 | =head2 B::PVMG METHODS |
| 367 | |
| 368 | =over 4 |
| 369 | |
| 370 | =item MAGIC |
| 371 | |
| 372 | =item SvSTASH |
| 373 | |
| 374 | =back |
| 375 | |
| 376 | =head2 B::MAGIC METHODS |
| 377 | |
| 378 | =over 4 |
| 379 | |
| 380 | =item MOREMAGIC |
| 381 | |
| 382 | =item PRIVATE |
| 383 | |
| 384 | =item TYPE |
| 385 | |
| 386 | =item FLAGS |
| 387 | |
| 388 | =item OBJ |
| 389 | |
| 390 | =item PTR |
| 391 | |
| 392 | =back |
| 393 | |
| 394 | =head2 B::PVLV METHODS |
| 395 | |
| 396 | =over 4 |
| 397 | |
| 398 | =item TARGOFF |
| 399 | |
| 400 | =item TARGLEN |
| 401 | |
| 402 | =item TYPE |
| 403 | |
| 404 | =item TARG |
| 405 | |
| 406 | =back |
| 407 | |
| 408 | =head2 B::BM METHODS |
| 409 | |
| 410 | =over 4 |
| 411 | |
| 412 | =item USEFUL |
| 413 | |
| 414 | =item PREVIOUS |
| 415 | |
| 416 | =item RARE |
| 417 | |
| 418 | =item TABLE |
| 419 | |
| 420 | =back |
| 421 | |
| 422 | =head2 B::GV METHODS |
| 423 | |
| 424 | =over 4 |
| 425 | |
| 426 | =item is_empty |
| 427 | |
| 428 | This method returns TRUE if the GP field of the GV is NULL. |
| 429 | |
| 430 | =item NAME |
| 431 | |
| 432 | =item STASH |
| 433 | |
| 434 | =item SV |
| 435 | |
| 436 | =item IO |
| 437 | |
| 438 | =item FORM |
| 439 | |
| 440 | =item AV |
| 441 | |
| 442 | =item HV |
| 443 | |
| 444 | =item EGV |
| 445 | |
| 446 | =item CV |
| 447 | |
| 448 | =item CVGEN |
| 449 | |
| 450 | =item LINE |
| 451 | |
| 452 | =item FILE |
| 453 | |
| 454 | =item FILEGV |
| 455 | |
| 456 | =item GvREFCNT |
| 457 | |
| 458 | =item FLAGS |
| 459 | |
| 460 | =back |
| 461 | |
| 462 | =head2 B::IO METHODS |
| 463 | |
| 464 | =over 4 |
| 465 | |
| 466 | =item LINES |
| 467 | |
| 468 | =item PAGE |
| 469 | |
| 470 | =item PAGE_LEN |
| 471 | |
| 472 | =item LINES_LEFT |
| 473 | |
| 474 | =item TOP_NAME |
| 475 | |
| 476 | =item TOP_GV |
| 477 | |
| 478 | =item FMT_NAME |
| 479 | |
| 480 | =item FMT_GV |
| 481 | |
| 482 | =item BOTTOM_NAME |
| 483 | |
| 484 | =item BOTTOM_GV |
| 485 | |
| 486 | =item SUBPROCESS |
| 487 | |
| 488 | =item IoTYPE |
| 489 | |
| 490 | =item IoFLAGS |
| 491 | |
| 492 | =back |
| 493 | |
| 494 | =head2 B::AV METHODS |
| 495 | |
| 496 | =over 4 |
| 497 | |
| 498 | =item FILL |
| 499 | |
| 500 | =item MAX |
| 501 | |
| 502 | =item OFF |
| 503 | |
| 504 | =item ARRAY |
| 505 | |
| 506 | =item AvFLAGS |
| 507 | |
| 508 | =back |
| 509 | |
| 510 | =head2 B::CV METHODS |
| 511 | |
| 512 | =over 4 |
| 513 | |
| 514 | =item STASH |
| 515 | |
| 516 | =item START |
| 517 | |
| 518 | =item ROOT |
| 519 | |
| 520 | =item GV |
| 521 | |
| 522 | =item FILE |
| 523 | |
| 524 | =item DEPTH |
| 525 | |
| 526 | =item PADLIST |
| 527 | |
| 528 | =item OUTSIDE |
| 529 | |
| 530 | =item XSUB |
| 531 | |
| 532 | =item XSUBANY |
| 533 | |
| 534 | =item CvFLAGS |
| 535 | |
| 536 | =item const_sv |
| 537 | |
| 538 | =back |
| 539 | |
| 540 | =head2 B::HV METHODS |
| 541 | |
| 542 | =over 4 |
| 543 | |
| 544 | =item FILL |
| 545 | |
| 546 | =item MAX |
| 547 | |
| 548 | =item KEYS |
| 549 | |
| 550 | =item RITER |
| 551 | |
| 552 | =item NAME |
| 553 | |
| 554 | =item PMROOT |
| 555 | |
| 556 | =item ARRAY |
| 557 | |
| 558 | =back |
| 559 | |
| 560 | =head2 OP-RELATED CLASSES |
| 561 | |
| 562 | B::OP, B::UNOP, B::BINOP, B::LOGOP, B::LISTOP, B::PMOP, |
| 563 | B::SVOP, B::PADOP, B::PVOP, B::CVOP, B::LOOP, B::COP. |
| 564 | These classes correspond in |
| 565 | the obvious way to the underlying C structures of similar names. The |
| 566 | inheritance hierarchy mimics the underlying C "inheritance". Access |
| 567 | methods correspond to the underlying C structre field names, with the |
| 568 | leading "class indication" prefix removed (op_). |
| 569 | |
| 570 | =head2 B::OP METHODS |
| 571 | |
| 572 | =over 4 |
| 573 | |
| 574 | =item next |
| 575 | |
| 576 | =item sibling |
| 577 | |
| 578 | =item name |
| 579 | |
| 580 | This returns the op name as a string (e.g. "add", "rv2av"). |
| 581 | |
| 582 | =item ppaddr |
| 583 | |
| 584 | This returns the function name as a string (e.g. "PL_ppaddr[OP_ADD]", |
| 585 | "PL_ppaddr[OP_RV2AV]"). |
| 586 | |
| 587 | =item desc |
| 588 | |
| 589 | This returns the op description from the global C PL_op_desc array |
| 590 | (e.g. "addition" "array deref"). |
| 591 | |
| 592 | =item targ |
| 593 | |
| 594 | =item type |
| 595 | |
| 596 | =item seq |
| 597 | |
| 598 | =item flags |
| 599 | |
| 600 | =item private |
| 601 | |
| 602 | =back |
| 603 | |
| 604 | =head2 B::UNOP METHOD |
| 605 | |
| 606 | =over 4 |
| 607 | |
| 608 | =item first |
| 609 | |
| 610 | =back |
| 611 | |
| 612 | =head2 B::BINOP METHOD |
| 613 | |
| 614 | =over 4 |
| 615 | |
| 616 | =item last |
| 617 | |
| 618 | =back |
| 619 | |
| 620 | =head2 B::LOGOP METHOD |
| 621 | |
| 622 | =over 4 |
| 623 | |
| 624 | =item other |
| 625 | |
| 626 | =back |
| 627 | |
| 628 | =head2 B::LISTOP METHOD |
| 629 | |
| 630 | =over 4 |
| 631 | |
| 632 | =item children |
| 633 | |
| 634 | =back |
| 635 | |
| 636 | =head2 B::PMOP METHODS |
| 637 | |
| 638 | =over 4 |
| 639 | |
| 640 | =item pmreplroot |
| 641 | |
| 642 | =item pmreplstart |
| 643 | |
| 644 | =item pmnext |
| 645 | |
| 646 | =item pmregexp |
| 647 | |
| 648 | =item pmflags |
| 649 | |
| 650 | =item pmpermflags |
| 651 | |
| 652 | =item precomp |
| 653 | |
| 654 | =back |
| 655 | |
| 656 | =head2 B::SVOP METHOD |
| 657 | |
| 658 | =over 4 |
| 659 | |
| 660 | =item sv |
| 661 | |
| 662 | =item gv |
| 663 | |
| 664 | =back |
| 665 | |
| 666 | =head2 B::PADOP METHOD |
| 667 | |
| 668 | =over 4 |
| 669 | |
| 670 | =item padix |
| 671 | |
| 672 | =back |
| 673 | |
| 674 | =head2 B::PVOP METHOD |
| 675 | |
| 676 | =over 4 |
| 677 | |
| 678 | =item pv |
| 679 | |
| 680 | =back |
| 681 | |
| 682 | =head2 B::LOOP METHODS |
| 683 | |
| 684 | =over 4 |
| 685 | |
| 686 | =item redoop |
| 687 | |
| 688 | =item nextop |
| 689 | |
| 690 | =item lastop |
| 691 | |
| 692 | =back |
| 693 | |
| 694 | =head2 B::COP METHODS |
| 695 | |
| 696 | =over 4 |
| 697 | |
| 698 | =item label |
| 699 | |
| 700 | =item stash |
| 701 | |
| 702 | =item file |
| 703 | |
| 704 | =item cop_seq |
| 705 | |
| 706 | =item arybase |
| 707 | |
| 708 | =item line |
| 709 | |
| 710 | =back |
| 711 | |
| 712 | =head1 FUNCTIONS EXPORTED BY C<B> |
| 713 | |
| 714 | The C<B> module exports a variety of functions: some are simple |
| 715 | utility functions, others provide a Perl program with a way to |
| 716 | get an initial "handle" on an internal object. |
| 717 | |
| 718 | =over 4 |
| 719 | |
| 720 | =item main_cv |
| 721 | |
| 722 | Return the (faked) CV corresponding to the main part of the Perl |
| 723 | program. |
| 724 | |
| 725 | =item init_av |
| 726 | |
| 727 | Returns the AV object (i.e. in class B::AV) representing INIT blocks. |
| 728 | |
| 729 | =item main_root |
| 730 | |
| 731 | Returns the root op (i.e. an object in the appropriate B::OP-derived |
| 732 | class) of the main part of the Perl program. |
| 733 | |
| 734 | =item main_start |
| 735 | |
| 736 | Returns the starting op of the main part of the Perl program. |
| 737 | |
| 738 | =item comppadlist |
| 739 | |
| 740 | Returns the AV object (i.e. in class B::AV) of the global comppadlist. |
| 741 | |
| 742 | =item sv_undef |
| 743 | |
| 744 | Returns the SV object corresponding to the C variable C<sv_undef>. |
| 745 | |
| 746 | =item sv_yes |
| 747 | |
| 748 | Returns the SV object corresponding to the C variable C<sv_yes>. |
| 749 | |
| 750 | =item sv_no |
| 751 | |
| 752 | Returns the SV object corresponding to the C variable C<sv_no>. |
| 753 | |
| 754 | =item amagic_generation |
| 755 | |
| 756 | Returns the SV object corresponding to the C variable C<amagic_generation>. |
| 757 | |
| 758 | =item walkoptree(OP, METHOD) |
| 759 | |
| 760 | Does a tree-walk of the syntax tree based at OP and calls METHOD on |
| 761 | each op it visits. Each node is visited before its children. If |
| 762 | C<walkoptree_debug> (q.v.) has been called to turn debugging on then |
| 763 | the method C<walkoptree_debug> is called on each op before METHOD is |
| 764 | called. |
| 765 | |
| 766 | =item walkoptree_debug(DEBUG) |
| 767 | |
| 768 | Returns the current debugging flag for C<walkoptree>. If the optional |
| 769 | DEBUG argument is non-zero, it sets the debugging flag to that. See |
| 770 | the description of C<walkoptree> above for what the debugging flag |
| 771 | does. |
| 772 | |
| 773 | =item walksymtable(SYMREF, METHOD, RECURSE) |
| 774 | |
| 775 | Walk the symbol table starting at SYMREF and call METHOD on each |
| 776 | symbol visited. When the walk reached package symbols "Foo::" it |
| 777 | invokes RECURSE and only recurses into the package if that sub |
| 778 | returns true. |
| 779 | |
| 780 | =item svref_2object(SV) |
| 781 | |
| 782 | Takes any Perl variable and turns it into an object in the |
| 783 | appropriate B::OP-derived or B::SV-derived class. Apart from functions |
| 784 | such as C<main_root>, this is the primary way to get an initial |
| 785 | "handle" on a internal perl data structure which can then be followed |
| 786 | with the other access methods. |
| 787 | |
| 788 | =item ppname(OPNUM) |
| 789 | |
| 790 | Return the PP function name (e.g. "pp_add") of op number OPNUM. |
| 791 | |
| 792 | =item hash(STR) |
| 793 | |
| 794 | Returns a string in the form "0x..." representing the value of the |
| 795 | internal hash function used by perl on string STR. |
| 796 | |
| 797 | =item cast_I32(I) |
| 798 | |
| 799 | Casts I to the internal I32 type used by that perl. |
| 800 | |
| 801 | |
| 802 | =item minus_c |
| 803 | |
| 804 | Does the equivalent of the C<-c> command-line option. Obviously, this |
| 805 | is only useful in a BEGIN block or else the flag is set too late. |
| 806 | |
| 807 | |
| 808 | =item cstring(STR) |
| 809 | |
| 810 | Returns a double-quote-surrounded escaped version of STR which can |
| 811 | be used as a string in C source code. |
| 812 | |
| 813 | =item class(OBJ) |
| 814 | |
| 815 | Returns the class of an object without the part of the classname |
| 816 | preceding the first "::". This is used to turn "B::UNOP" into |
| 817 | "UNOP" for example. |
| 818 | |
| 819 | =item threadsv_names |
| 820 | |
| 821 | In a perl compiled for threads, this returns a list of the special |
| 822 | per-thread threadsv variables. |
| 823 | |
| 824 | =back |
| 825 | |
| 826 | =head1 AUTHOR |
| 827 | |
| 828 | Malcolm Beattie, C<mbeattie@sable.ox.ac.uk> |
| 829 | |
| 830 | =cut |