| 1 | # Assembler.pm | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 1996 Malcolm Beattie | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright (c) 2008,2009,2010,2011,2012 Reini Urban | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2014 cPanel Inc | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # You may distribute under the terms of either the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # License or the Artistic License, as specified in the README file. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | package B::Assembler; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use B qw(ppname); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use B::Asmdata qw(%insn_data @insn_name); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Config qw(%Config); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | require ByteLoader; # we just need its $VERSION | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | no warnings; # XXX | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our @EXPORT_OK = qw(assemble_fh newasm endasm assemble asm maxopix maxsvix); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | our $VERSION = '1.13'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my %opnumber; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my ( $i, $opname ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | for ( $i = 0 ; defined( $opname = ppname($i) ) ; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 429 | $opnumber{$opname} = $i; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my ( $linenum, $errors, $out ); # global state, set up by newasm | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 23 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 23 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 23 | warn "$linenum: $str\n"; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 23 | $errors++; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub debug { $debug = shift } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $quiet = 0; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub quiet { $quiet = shift } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiet: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my ( $maxopix, $maxsvix ) = ( 0xffffffff, 0xffffffff ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub maxopix { $maxopix = shift } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maxopix: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub maxsvix { $maxsvix = shift } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maxsvix: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 160 | ▶ | sub limcheck($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
limcheck: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 160 | my ( $val, $lo, $hi, $loc ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 160 | ▶ | if ( $val < $lo || $hi < $val ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val < $lo or $hi < $val
MC/DC100%2/2
$val < $lo or $hi < $val
$val < $lo
$hi < $val
Truth table100%3/3
A or B
A= $val < $loB= $hi < $val
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 16 | error "argument for $loc outside [$lo, $hi]: $val"; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | $val = $hi; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 160 | return $val; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # First define all the data conversion subs to which Asmdata will refer | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 29 | ▶ | sub B::Asmdata::PUT_U8 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_U8: called CC=4 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 29 | ▶ | error "Missing argument to PUT_U8" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 29 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 29 | my $c = uncstring($arg); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 29 | ▶ | if ( defined($c) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( length($c) != 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | error "argument for U8 is too long: $c"; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $c = substr( $c, 0, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 29 | $arg = limcheck( $arg, 0, 0xff, 'U8' ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 29 | $c = chr($arg); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 29 | return $c; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | ▶ | sub B::Asmdata::PUT_U16 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_U16: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | ▶ | error "Missing argument to PUT_U16" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | my $arg = limcheck( $_[0], 0, 0xffff, 'U16' ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | pack( "S", $arg ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 35 | ▶ | sub B::Asmdata::PUT_U32 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_U32: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 35 | ▶ | error "Missing argument to PUT_U32" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 35 | my $arg = limcheck( $_[0], 0, 0xffffffff, 'U32' ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 35 | pack( "L", $arg ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | ▶ | sub B::Asmdata::PUT_I32 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_I32: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 7 | ▶ | error "Missing argument to PUT_I32" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | my $arg = limcheck( $_[0], -0x80000000, 0x7fffffff, 'I32' ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | pack( "l", $arg ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | sub B::Asmdata::PUT_NV { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_NV: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | error "Missing argument to PUT_NV" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | sprintf( "%s\0", $_[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } # "%lf" looses precision and pack('d',...) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # may not even be portable between compilers | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 81 | ▶ | sub B::Asmdata::PUT_objindex { # could allow names here | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_objindex: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 81 | ▶ | error "Missing argument to PUT_objindex" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 81 | ▶ | my $maxidx = $_[1] || 0xffffffff; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] || 4294967295
MC/DC0%0/1
$_[1] || 4294967295
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 81 | ▶ | my $what = $_[2] || 'ix'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[2] || 'ix'
MC/DC0%0/1
$_[2] || 'ix'
$_[2]
Truth table50%1/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 81 | my $arg = limcheck( $_[0], 0, $maxidx, $what ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 81 | pack( "L", $arg ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 50 | ▶ | sub B::Asmdata::PUT_svindex { B::Asmdata::PUT_objindex( @_, $maxsvix, 'svix' ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_svindex: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 19 | ▶ | sub B::Asmdata::PUT_opindex { B::Asmdata::PUT_objindex( @_, $maxopix, 'opix' ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_opindex: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 12 | ▶ | sub B::Asmdata::PUT_pvindex { B::Asmdata::PUT_objindex( @_, $maxsvix, 'pvix' ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_pvindex: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub B::Asmdata::PUT_hekindex { B::Asmdata::PUT_objindex( @_ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_hekindex: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 17 | ▶ | sub B::Asmdata::PUT_strconst { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_strconst: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 17 | ▶ | error "Missing argument to PUT_strconst" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 17 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 17 | my $str = uncstring($arg); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 17 | ▶ | if ( !defined($str) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my @callstack = caller(3); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | error "bad string constant: '$arg', called from ".$callstack[3] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | ." line:".$callstack[2] unless $callstack[3] eq 'B::PADNAME::ix'; # empty newpadnx | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $str = ''; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 17 | ▶ | if ( $str =~ s/\0//g ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | error "string constant argument contains NUL: $arg"; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | $str = ''; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 17 | return $str . "\0"; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # expects the string argument already on the "stack" (with depth 1, one sv) | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | sub B::Asmdata::PUT_pvcontents { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_pvcontents: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | ▶ | error "extraneous argument to pvcontents: $arg" if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | return ""; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | sub B::Asmdata::PUT_PV { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_PV: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | error "Missing argument to PUT_PV" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | my $str = uncstring($arg); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | if ( !defined($str) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | error "bad string argument: $arg"; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $str = ''; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | return pack( "L", length($str) ) . $str; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | sub B::Asmdata::PUT_comment_t { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_comment_t: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | $arg = uncstring($arg); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | error "bad string argument: $arg" unless defined($arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | ▶ | if ( $arg =~ s/\n//g ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | error "comment argument contains linefeed: $arg"; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | return $arg . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub B::Asmdata::PUT_double { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_double: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | error "Missing argument to PUT_double" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | sprintf( "%s\0", $_[0] ) | |||||||||||||||||||||||||||||||||||||||||
| 159 | } # see PUT_NV above | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | ▶ | sub B::Asmdata::PUT_none { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_none: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | ▶ | error "extraneous argument: $arg" if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | return ""; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | sub B::Asmdata::PUT_op_tr_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_op_tr_array: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | error "Missing argument to PUT_tr_array" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | my @ary = split /\s*,\s*/, shift; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | return pack "S*", @ary; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 9 | ▶ | sub B::Asmdata::PUT_IV64 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_IV64: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 9 | ▶ | error "Missing argument to PUT_IV64" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 9 | return pack "Q", shift; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | ▶ | sub B::Asmdata::PUT_IV { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_IV: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | ▶ | $Config{ivsize} == 4 ? &B::Asmdata::PUT_I32 : &B::Asmdata::PUT_IV64; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub B::Asmdata::PUT_PADOFFSET { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_PADOFFSET: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $Config{ptrsize} == 8 ? &B::Asmdata::PUT_IV64 : &B::Asmdata::PUT_U32; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub B::Asmdata::PUT_long { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_long: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $Config{longsize} == 8 ? &B::Asmdata::PUT_IV64 : &B::Asmdata::PUT_U32; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub B::Asmdata::PUT_svtype { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_svtype: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | $Config{longsize} == 8 ? &B::Asmdata::PUT_IV64 : &B::Asmdata::PUT_U32; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | sub B::Asmdata::PUT_pmflags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUT_pmflags: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | ▶ | return ($] < 5.013) ? B::Asmdata::PUT_U16(@_) : B::Asmdata::PUT_U32(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | my %unesc = ( | |||||||||||||||||||||||||||||||||||||||||
| 199 | n => "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 200 | r => "\r", | ||||||||||||||||||||||||||||||||||||||||||
| 201 | t => "\t", | ||||||||||||||||||||||||||||||||||||||||||
| 202 | a => "\a", | ||||||||||||||||||||||||||||||||||||||||||
| 203 | b => "\b", | ||||||||||||||||||||||||||||||||||||||||||
| 204 | f => "\f", | ||||||||||||||||||||||||||||||||||||||||||
| 205 | v => "\013" | ||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 53 | ▶ | sub uncstring { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uncstring: called CC=5 SCAR=17.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 53 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 53 | ▶ | $s =~ s/^"// and $s =~ s/"$// or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$s =~ s/^"// and $s =~ s/"$//
MC/DC50%1/2
$s =~ s/^"// and $s =~ s/"$//
$s =~ s/^"//
$s =~ s/"$//
Truth table66%2/3
A and B
A= $s =~ s/^"//B= $s =~ s/"$//
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 22 | ▶ | $s =~ s/\\(\d\d\d|.)/length($1) == 3 ? chr(oct($1)) : ($unesc{$1}||$1)/eg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$unesc{$1} or $1
MC/DC0%0/2
$unesc{$1} or $1
$unesc{$1}
$1
Truth table33%1/3
A or B
A= $unesc{$1}B= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 22 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 201 | ▶ | sub strip_comments { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_comments: called CC=2 SCAR=8.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 201 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # Comments only allowed in instructions which don't take string arguments | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # Treat string as a single line so .* eats \n characters. | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 201 | my $line = $stmt; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 201 | $stmt =~ s{ | |||||||||||||||||||||||||||||||||||||||||
| 222 | ^\s* # Ignore leading whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 223 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 224 | [^"]* # A double quote '"' indicates a string argument. If we | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # find a double quote, the match fails and we strip nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 226 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 227 | \s*\# # Any amount of whitespace plus the comment marker... | ||||||||||||||||||||||||||||||||||||||||||
| 228 | \s*(.*)$ # ...which carries on to end-of-string. | ||||||||||||||||||||||||||||||||||||||||||
| 229 | }{$1}sx; # Keep only the instruction and optional argument. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 201 | ▶ | return ($stmt) if $line eq $stmt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $stmt =~ m{ | |||||||||||||||||||||||||||||||||||||||||
| 233 | ^\s* | ||||||||||||||||||||||||||||||||||||||||||
| 234 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 235 | [^"]* | ||||||||||||||||||||||||||||||||||||||||||
| 236 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 237 | \s*\# | ||||||||||||||||||||||||||||||||||||||||||
| 238 | \s*(.*)$ | ||||||||||||||||||||||||||||||||||||||||||
| 239 | }sx; # Keep only the instruction and optional argument. | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my ( $line, $comment ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | # $line =~ s/\t$// if $comment; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return ( $line, $comment ); | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # create the ByteCode header: | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # magic, archname, ByteLoader $VERSION, ivsize, ptrsize, longsize, byteorder, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # archflag, perlversion | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # byteorder is strconst, not U32 because of varying size issues (?) | ||||||||||||||||||||||||||||||||||||||||||
| 250 | # archflag: bit 1: useithreads, bit 2: multiplicity | ||||||||||||||||||||||||||||||||||||||||||
| 251 | # perlversion for the bytecode translation. | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | ▶ | sub gen_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_header: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | my $header = gen_header_hash(); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | my $string = ""; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | $string .= B::Asmdata::PUT_U32( $header->{magic} ); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | $string .= B::Asmdata::PUT_strconst( '"' . $header->{archname} . '"' ); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | $string .= B::Asmdata::PUT_strconst( '"' . $header->{blversion} . '"' ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $string .= B::Asmdata::PUT_U32( $header->{ivsize} ); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | $string .= B::Asmdata::PUT_U32( $header->{ptrsize} ); | |||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | if ( exists $header->{longsize} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | $string .= B::Asmdata::PUT_U32( $header->{longsize} ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $string .= B::Asmdata::PUT_strconst( sprintf(qq["0x%s"], $header->{byteorder} )); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | if ( exists $header->{archflag} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | $string .= B::Asmdata::PUT_U16( $header->{archflag} ); | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | if ( exists $header->{perlversion} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | $string .= B::Asmdata::PUT_strconst( '"' . $header->{perlversion} . '"'); | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | $string; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | # Calculate the ByteCode header values: | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # magic, archname, ByteLoader $VERSION, ivsize, ptrsize, longsize, byteorder | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # archflag, perlversion | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # nvtype is irrelevant (floats are stored as strings) | ||||||||||||||||||||||||||||||||||||||||||
| 278 | # byteorder is strconst, not U32 because of varying size issues (?) | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # archflag: bit 1: useithreads, bit 2: multiplicity | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # perlversion for the bytecode translation. | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | sub gen_header_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_header_hash: called CC=12 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | my $header = {}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | my $blversion = "$ByteLoader::VERSION"; | |||||||||||||||||||||||||||||||||||||||||
| 285 | #if ($] < 5.009 and $blversion eq '0.06_01') { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # $blversion = '0.06';# fake the old backwards compatible version | ||||||||||||||||||||||||||||||||||||||||||
| 287 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $header->{magic} = 0x43424c50; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | $header->{archname} = $Config{archname}; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | $header->{blversion} = $blversion; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $header->{ivsize} = $Config{ivsize}; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | $header->{ptrsize} = $Config{ptrsize}; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | ▶ | if ( $blversion ge "0.06_03" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | $header->{longsize} = $Config{longsize}; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | my $byteorder = $Config{byteorder}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | ▶ | if ($] < 5.007) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | # until 5.6 the $Config{byteorder} was dependent on ivsize, which was wrong. we need longsize. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $t = $Config{ivtype}; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $s = $Config{longsize}; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | my $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ($s == 4 || $s == 8) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$s == 4 or $s == 8
MC/DC0%0/2
$s == 4 or $s == 8
$s == 4
$s == 8
Truth table0%0/3
A or B
A= $s == 4B= $s == 8
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | foreach my $c (reverse(2..$s)) { $i |= ord($c); $i <<= 8 } | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $i |= ord(1); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $byteorder = join('', unpack('a'x$s, pack($f, $i))); | |||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $byteorder = '?'x$s; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | $header->{byteorder} = $byteorder; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | ▶ | if ( $blversion ge "0.06_05" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | my $archflag = 0; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ▶ | $archflag += 1 if $Config{useithreads}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | ▶ | $archflag += 2 if $Config{usemultiplicity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | $header->{archflag} = $archflag; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | if ( $blversion ge "0.06_06" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | $header->{perlversion} = $]; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | $header; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 201 | ▶ | sub parse_statement { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_statement: called CC=6 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 201 | my $stmt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 201 | my ( $insn, $arg ) = $stmt =~ m{ | |||||||||||||||||||||||||||||||||||||||||
| 327 | ^\s* # allow (but ignore) leading whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 328 | (.*?) # Ignore -S op groups. Instruction continues up until... | ||||||||||||||||||||||||||||||||||||||||||
| 329 | (?: # ...an optional whitespace+argument group | ||||||||||||||||||||||||||||||||||||||||||
| 330 | \s+ # first whitespace. | ||||||||||||||||||||||||||||||||||||||||||
| 331 | (.*) # The argument is all the rest (newlines included). | ||||||||||||||||||||||||||||||||||||||||||
| 332 | )?$ # anchor at end-of-line | ||||||||||||||||||||||||||||||||||||||||||
| 333 | }sx; | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 201 | ▶ | if ( defined($arg) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 190 | ▶ | if ( $arg =~ s/^0x(?=[0-9a-fA-F]+$)// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 9 | $arg = hex($arg); | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | elsif ( $arg =~ s/^0(?=[0-7]+$)// ) { | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $arg = oct($arg); | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | elsif ( $arg =~ /^pp_/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $arg =~ s/\s*$//; # strip trailing whitespace | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $opnum = $opnumber{$arg}; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ( defined($opnum) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $arg = $opnum; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | # TODO: ignore [op] from O=Bytecode,-S | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | error qq(No such op type "$arg"); | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $arg = 0; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 201 | return ( $insn, $arg ); | |||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 201 | ▶ | sub assemble_insn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assemble_insn: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 201 | my ( $insn, $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 201 | my $data = $insn_data{$insn}; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 201 | ▶ | if ( defined($data) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 200 | my ( $bytecode, $putsub ) = @{$data}[ 0, 1 ]; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 200 | ▶ | error qq(unsupported instruction "$insn") unless $putsub; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 200 | ▶ | return "" unless $putsub; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 200 | my $argcode = &$putsub($arg); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 200 | return chr($bytecode) . $argcode; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | error qq(no such instruction "$insn"); | |||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | return ""; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | ▶ | sub assemble_fh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assemble_fh: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | my ( $fh, $out ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | my $line; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | my $asm = newasm($out); | |||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | ▶ | while ( $line = <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 201 | assemble($line); | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | endasm(); | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | sub newasm { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newasm: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | my ($outsub) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | die "Invalid printing routine for B::Assembler\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | unless ref $outsub eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | ▶ | die <<EOD if ref $out; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | Can't have multiple byteassembly sessions at once! | ||||||||||||||||||||||||||||||||||||||||||
| 390 | (perhaps you forgot an endasm()?) | ||||||||||||||||||||||||||||||||||||||||||
| 391 | EOD | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | $linenum = $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | $out = $outsub; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 1 | $out->( gen_header() ); | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | sub endasm { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
endasm: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | if ($errors) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | die "There were $errors assembly errors\n"; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $linenum = $errors = $out = 0; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | ### interface via whole line, and optional comments | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 201 | ▶ | sub assemble { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assemble: called CC=9 SCAR=30.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 201 | my ($line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 201 | my ( $insn, $arg, $comment ); | |||||||||||||||||||||||||||||||||||||||||
| 410 | 201 | $linenum++; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 201 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 201 | $line =~ s/\cM$//; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 201 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $quotedline = $line; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $quotedline =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $quotedline =~ s/"/\\"/g; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $out->( assemble_insn( "comment", qq("$quotedline") ) ); | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 201 | ( $line, $comment ) = strip_comments($line); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 201 | ▶ | if ($line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 201 | ( $insn, $arg ) = parse_statement($line); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 201 | ▶ | if ($debug and !$comment and $insn =~ /_flags/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$debug and not $comment and $insn =~ /_flags/
$debug and not $comment
MC/DC0%0/3
$debug and not $comment and $insn =~ /_flags/
$debug
not $comment
$insn =~ /_flags/
Truth table25%1/4
A and not(B) and C
A= $debugB= not $commentC= $insn =~ /_flags/
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $comment = sprintf("0x%x", $arg); | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 201 | $out->( assemble_insn( $insn, $arg, $comment ) ); | |||||||||||||||||||||||||||||||||||||||||
| 426 | 201 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $out->( assemble_insn( "nop", undef ) ); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | ▶ | elsif ( $debug and $comment ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$debug and $comment
MC/DC0%0/2
$debug and $comment
$debug
$comment
Truth table0%0/3
A and B
A= $debugB= $comment
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $out->( assemble_insn( "nop", undef, $comment ) ); | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | ### temporary workaround | ||||||||||||||||||||||||||||||||||||||||||
| 436 | ### interface via 2-3 args | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | sub asm ($;$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
asm: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | return if $_[0] =~ /\s*\W/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if ( defined $_[1] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | return | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if $_[1] eq "0" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[1] eq 0 and not $_[0] =~ /^(?:ldsv|stsv|newsvx?|newpad.*|av_pushx?|av_extend|xav_flags)$/
MC/DC0%0/2
$_[1] eq 0 and not $_[0] =~ /^(?:ldsv|stsv|newsvx?|newpad.*|av_pushx?|av_extend|xav_flags)$/
$_[1] eq 0
not $_[0] =~ /^(?:ldsv|stsv|newsvx?|newpad.*|av_pushx?|av_extend|xav_flags)$/
Truth table0%0/3
A and not(B)
A= $_[1] eq 0B= not $_[0] =~ /^(?:ldsv|stsv|newsvx?|newpad.*|av_pushx?|av_extend|xav_flags)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | and $_[0] !~ /^(?:ldsv|stsv|newsvx?|newpad.*|av_pushx?|av_extend|xav_flags)$/; | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | return if $_[1] eq "1" and $]>5.007 and $_[0] =~ /^(?:sv_refcnt)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$_[1] eq 1 and $] > "5.007" and $_[0] =~ /^(?:sv_refcnt)$/
$_[1] eq 1 and $] > "5.007"
MC/DC0%0/3
$_[1] eq 1 and $] > "5.007" and $_[0] =~ /^(?:sv_refcnt)$/
$_[1] eq 1
$] > "5.007"
$_[0] =~ /^(?:sv_refcnt)$/
Truth table0%0/4
A and B and C
A= $_[1] eq 1B= $] > "5.007"C= $_[0] =~ /^(?:sv_refcnt)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my ( $insn, $arg, $comment ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | if ($] < 5.007) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if ($insn eq "newsvx") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $arg = $arg & 0xff; # sv not SVt_NULL | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $insn = "newsv"; | |||||||||||||||||||||||||||||||||||||||||
| 451 | # XXX but this needs stsv tix-1 also | ||||||||||||||||||||||||||||||||||||||||||
| 452 | } elsif ($insn eq "newopx") { | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $insn = "newop"; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } elsif ($insn eq "av_pushx") { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $insn = "av_push"; | |||||||||||||||||||||||||||||||||||||||||
| 456 | } elsif ($insn eq "ldspecsvx") { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $insn = "ldspecsv"; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } elsif ($insn eq "gv_stashpvx") { | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $insn = "gv_stashpv"; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } elsif ($insn eq "gv_fetchpvx") { | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | $insn = "gv_fetchpv"; | |||||||||||||||||||||||||||||||||||||||||
| 462 | } elsif ($insn eq "main_cv") { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $out->( assemble_insn( $insn, $arg, $comment ) ); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $linenum++; | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | # assemble "@_"; | ||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | __END__ | ||||||||||||||||||||||||||||||||||||||||||