# man > B(3perl)

---
type: CommandReference
command: B
mode: perldoc
section: 3perl
source: perldoc
---

## Quick Reference
- `use B;` — load the Perl compiler backend module
- `svref_2object($ref)` — turn a Perl reference into a B::SV/B::OP object
- `main_root()` — get root op of main program
- `main_start()` — get starting op of main program
- `walkoptree($op, \&method)` — traverse the syntax tree calling method on each op
- `walksymtable(\%main::, \&sub, \&recurse, 'prefix')` — walk symbol table
- `hash("string")` — return internal hash value as hex string
- `cstring($str)` — quote string for C source code

## Name
B - The Perl Compiler Backend

## Synopsis
perl
use B;
## Options
### Functions returning SV/AV/HV/CV objects
- `sv_undef` — SV object for `sv_undef`
- `sv_yes` — SV object for `sv_yes`
- `sv_no` — SV object for `sv_no`
- `svref_2object(REF)` — convert a Perl reference into the appropriate B::SV/B::OP class
- `amagic_generation` — SV for `amagic_generation` (always `PL_na`)
- `init_av` — AV of INIT blocks
- `check_av` — AV of CHECK blocks
- `unitcheck_av` — AV of UNITCHECK blocks
- `begin_av` — AV of BEGIN blocks
- `end_av` — AV of END blocks
- `comppadlist` — PADLIST of global comppadlist (B::AV before 5.18)
- `regex_padav` — only with ithreads
- `main_cv` — CV for main part of the program

### Symbol table walking
- `walksymtable(SYMREF, METHOD, RECURSE, PREFIX)` — walk symbol tree; call METHOD on each B::GV; recurse into packages where RECURSE returns true

### Functions returning B::OP objects / op tree walking
- `main_root` — root op of main program
- `main_start` — starting op of main program
- `walkoptree(OP, METHOD)` — depth-first walk, call METHOD on each op (before children)
- `walkoptree_debug(DEBUG)` — get/set debugging flag for `walkoptree`

### Miscellaneous utility functions
- `ppname(OPNUM)` — PP function name for op number (e.g. "pp_add")
- `hash(STR)` — hex string of internal hash of STR
- `cast_I32(I)` — cast to I32
- `minus_c` — equivalent of `-c` switch (BEGIN‑safe)
- `cstring(STR)` — quoted C string
- `perlstring(STR)` — quoted Perl string
- `safename(STR)` — convert first control char to ^X notation
- `class(OBJ)` — strip leading class name down to last `::` part

### Exported utility variables
- `@optype` — op type number to name mapping
- `@specialsv_name` — special SV index to name mapping

### SV‑related classes and methods
Inheritance: B::SV → B::PV, B::IV, B::NV → B::PVIV, B::PVNV → B::PVMG → B::AV, B::GV, B::HV, B::CV, B::IO, B::REGEXP; further: B::PVLV, B::FM, B::INVLIST, B::BM.

**B::SV**: `REFCNT`, `FLAGS`, `object_2svref`  
**B::IV**: `IV` (signed), `IVX`, `UVX`, `int_value` (correct signed/unsigned), `needs64bits`, `packiv`  
**B::NV**: `NV`, `NVX`, `COP_SEQ_RANGE_LOW`, `COP_SEQ_RANGE_HIGH`  
**B::RV**: `RV`  
**B::PV**: `PV` (real string), `RV` (dies if not a ref), `PVX` (C string, NUL‑term), `CUR` (byte length), `LEN` (allocated length)  
**B::PVMG**: `MAGIC`, `SvSTASH`  
**B::MAGIC**: `MOREMAGIC`, `precomp` (r‑magic), `PRIVATE`, `TYPE`, `FLAGS`, `OBJ` (dies on r‑magic), `PTR`, `REGEX` (r‑magic integer)  
**B::INVLIST**: `prev_index`, `is_offset`, `array_len`, `get_invlist_array`  
**B::PVLV**: `TARGOFF`, `TARGLEN`, `TYPE`, `TARG`  
**B::BM**: `USEFUL`, `PREVIOUS`, `RARE`, `TABLE`  
**B::REGEXP**: `REGEX`, `precomp`, `qr_anoncv`, `compflags` (5.22+)  
**B::GV**: `is_empty`, `NAME`, `SAFENAME` (^X notation), `STASH`, `SV`, `IO`, `FORM`, `AV`, `HV`, `EGV`, `CV`, `CVGEN`, `LINE`, `FILE`, `FILEGV`, `GvREFCNT`, `FLAGS`, `GPFLAGS` (5.22+)  
**B::IO**: base IO methods (e.g., `fileno()` via `object_2svref`), `LINES`, `PAGE`, `PAGE_LEN`, `LINES_LEFT`, `TOP_NAME`, `TOP_GV`, `FMT_NAME`, `FMT_GV`, `BOTTOM_NAME`, `BOTTOM_GV`, `SUBPROCESS`, `IoTYPE` (‑/I/</>/a/+/s/|/I/#/space/NUL), `IoFLAGS`, `IsSTD('stdin'|'stdout'|'stderr')`  
**B::AV**: `FILL`, `MAX`, `ARRAY`, `ARRAYelt($index)`  
**B::CV**: `STASH`, `START`, `ROOT`, `GV`, `FILE`, `DEPTH`, `PADLIST` (B::PADLIST), `OUTSIDE`, `OUTSIDE_SEQ`, `XSUB`, `XSUBANY` (constant SV for const sub), `CvFLAGS`, `const_sv`, `NAME_HEK` (lexical sub name)  
**B::HV**: `FILL`, `MAX`, `KEYS`, `RITER`, `NAME`, `ARRAY`

### OP‑related classes and methods
Inheritance: B::OP → B::UNOP, B::SVOP, B::PADOP, B::COP, B::PVOP, B::METHOP → B::BINOP, B::LOGOP, B::UNOP_AUX → B::LISTOP → B::LOOP, B::PMOP.

**B::OP**: `next`, `sibling`, `parent` (needs `-DPERL_OP_PARENT`), `name`, `ppaddr`, `desc`, `targ`, `type`, `opt`, `flags`, `private`, `spare`  
**B::UNOP**: `first`  
**B::UNOP_AUX** (5.22+): `aux_list($cv)`, `string($cv)`  
**B::BINOP**: `last`  
**B::LOGOP**: `other`  
**B::LISTOP**: `children`  
**B::PMOP**: `pmreplroot`, `pmreplstart`, `pmflags`, `precomp`, `pmoffset` (ithreads), `code_list` (5.17.1+), `pmregexp` (5.22+)  
**B::SVOP**: `sv`, `gv`  
**B::PADOP**: `padix`  
**B::PVOP**: `pv`  
**B::LOOP**: `redoop`, `nextop`, `lastop`  
**B::COP**: `label`, `stash`, `stashpv`, `stashoff` (threaded), `file`, `cop_seq`, `line`, `warnings`, `io`, `hints`, `hints_hash`  
**B::METHOP** (5.22+): `first`, `meth_sv`

### PAD‑related classes (5.18+)
**B::PADLIST**: `MAX`, `ARRAY` (first element = names PADNAMELIST, rest AVs), `ARRAYelt($idx)`, `NAMES` (5.22+), `REFCNT`, `id` (5.22+), `outid` (5.22+)  
**B::PADNAMELIST** (5.22+): `MAX`, `ARRAY`, `ARRAYelt`, `REFCNT`  
**B::PADNAME** (5.22+): `PV`, `PVX`, `LEN`, `REFCNT`, `FLAGS`, `TYPE` (stash), `SvSTASH` (alias for TYPE), `OURSTASH`, `PROTOCV`, `COP_SEQ_RANGE_LOW`, `COP_SEQ_RANGE_HIGH`, `PARENT_PAD_INDEX`, `PARENT_FAKELEX_FLAGS`

### Overlay facility
- `$B::overlay` — if set to a hashref keyed by OP address (e.g., `$$op`), method calls on that op return the stored value. Used by B::Deparse for undoing optimisations.

## See Also
- [O](http://localhost/phpMan.php/perldoc/O/markdown) — user‑visible compiler frontend
- [B::Deparse](http://localhost/phpMan.php/perldoc/B::Deparse/markdown)
- [B::Concise](http://localhost/phpMan.php/perldoc/B::Concise/markdown)
- [B::Showlex](http://localhost/phpMan.php/perldoc/B::Showlex/markdown)
- [B::Terse](http://localhost/phpMan.php/perldoc/B::Terse/markdown)
- [B::Xref](http://localhost/phpMan.php/perldoc/B::Xref/markdown)
- [perlapi](http://localhost/phpMan.php/man/perlapi/markdown) — Perl C API documentation

## Exit Codes
Not documented.