| 1 | package VIC::Receiver; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use bigint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 33 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use List::MoreUtils qw(any firstidx indexes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 33 | our $VERSION = '0.32'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 33 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 33 | ▶ | use Pegex::Base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 33 | extends 'Pegex::Tree'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 33 | ▶ | use VIC::PIC::Any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 33 | has pic_override => undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 33 | has pic => undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 33 | has simulator => undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 33 | has ast => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | block_stack => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | block_mapping => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | block_count => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | funcs => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | variables => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | tmp_variables => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | conditionals => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | tmp_stack_size => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | strings => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | tables => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | asserts => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 33 | has intermediate_inline => undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 33 | has global_collections => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 431 | ▶ | sub stack { reverse @{shift->parser->stack}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stack: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub supported_chips { return VIC::PIC::Any::supported_chips(); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_chips: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub supported_simulators { return VIC::PIC::Any::supported_simulators(); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_simulators: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 19 | ▶ | sub is_chip_supported { return VIC::PIC::Any::is_chip_supported(@_); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_chip_supported: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub is_simulator_supported { return VIC::PIC::Any::is_simulator_supported(@_); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_simulator_supported: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub list_chip_features { return VIC::PIC::Any::list_chip_features(@_); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_chip_features: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub print_pinout { return VIC::PIC::Any::print_pinout(@_); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_pinout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 31 | ▶ | sub current_chip { return $_[0]->pic->type; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_chip: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 31 | ▶ | sub current_simulator { return $_[0]->simulator->type; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_simulator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 33 | ▶ | sub got_mcu_select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_mcu_select: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 33 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # override the PIC in code if defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 33 | ▶ | $type = $self->pic_override if defined $self->pic_override; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 33 | $type = lc $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # assume supported type else return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 33 | $self->pic(VIC::PIC::Any->new($type)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 33 | ▶ | unless (defined $self->pic and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->pic and defined $self->pic->type
MC/DC0%0/2
defined $self->pic and defined $self->pic->type
defined $self->pic
defined $self->pic->type
Truth table33%1/3
A and B
A= defined $self->picB= defined $self->pic->type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | defined $self->pic->type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->parser->throw_error("$type is not a supported chip"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 33 | $self->ast->{include} = $self->pic->include; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # set the defaults in case the headers are not provided by the user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 33 | $self->ast->{org} = $self->pic->org; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 33 | $self->ast->{chip_config} = $self->pic->get_chip_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 33 | $self->ast->{code_config} = $self->pic->code_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # create the default simulator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 33 | $self->simulator(VIC::PIC::Any->new_simulator(pic => $self->pic)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 20 | ▶ | sub got_pragmas { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_pragmas: called CC=9 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 20 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 20 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 20 | $self->pic->update_code_config(@$list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # get the updated config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 20 | $self->ast->{chip_config} = $self->pic->get_chip_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 20 | $self->ast->{code_config} = $self->pic->code_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 20 | ▶ | my ($sim, $stype) = @$list if scalar @$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 20 | ▶ | if ($sim eq 'simulator' and $stype !~ /disable/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$sim eq "simulator" and not $stype =~ /disable/i
MC/DC100%2/2
$sim eq "simulator" and not $stype =~ /disable/i
$sim eq "simulator"
not $stype =~ /disable/i
Truth table100%3/3
A and not(B)
A= $sim eq "simulator"B= not $stype =~ /disable/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | $self->simulator(VIC::PIC::Any->new_simulator( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | type => $stype, pic => $self->pic)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | if ($self->simulator) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | unless ($self->simulator->type eq $stype) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | warn "$stype is not a supported chip. Disabling simulator."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->simulator->disable(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | die "$stype is not a supported simulator."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ▶ | } elsif ($sim eq 'simulator' and $stype =~ /disable/i) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sim eq "simulator" and $stype =~ /disable/i
MC/DC50%1/2
$sim eq "simulator" and $stype =~ /disable/i
$sim eq "simulator"
$stype =~ /disable/i
Truth table66%2/3
A and B
A= $sim eq "simulator"B= $stype =~ /disable/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | $self->simulator->disable(1) if $self->simulator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 94 | ▶ | sub handle_named_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_named_block: called CC=25 SCAR=33.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 94 | my ($self, $name, $anon_block, $parent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 94 | ▶ | my $id = $1 if $anon_block =~ /_anonblock(\d+)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 94 | ▶ | $id = $self->ast->{block_count} unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 94 | my ($expected_label, $expected_param) = ('', ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 94 | ▶ | if ($name eq 'Main') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 32 | $expected_label = "_start"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } elsif ($name =~ /^Loop/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 16 | $expected_label = "_loop_${id}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } elsif ($name =~ /^Action/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | $expected_label = "_action_${id}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | $expected_param = "action${id}_param"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } elsif ($name =~ /^True/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | $expected_label = "_true_${id}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } elsif ($name =~ /^False/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | $expected_label = "_false_${id}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } elsif ($name =~ /^ISR/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | $expected_label = "_isr_${id}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | $expected_param = "isr${id}_param"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } elsif ($name eq 'Simulator') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 19 | $expected_label = '_vic_simulator'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $expected_label = lc "_$name$id"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 94 | ▶ | $name .= $id if $name =~ /^(?:Loop|Action|True|False|ISR)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 94 | $self->ast->{block_mapping}->{$name} = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | label => $expected_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | block => $anon_block, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | params => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | param_prefix => $expected_param, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 94 | $self->ast->{block_mapping}->{$anon_block} = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | label => $expected_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | block => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | params => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | param_prefix => $expected_param, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # make sure the anon-block and named-block refer to the same block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 94 | $self->ast->{$name} = $self->ast->{$anon_block}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 94 | ▶ | my $stack = $self->ast->{$name} || $self->ast->{$anon_block}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->ast->{$name} || $self->ast->{$anon_block}
MC/DC0%0/2
$self->ast->{$name} || $self->ast->{$anon_block}
$self->ast->{$name}
$self->ast->{$anon_block}
Truth table33%1/3
A || B
A= $self->ast->{$name}B= $self->ast->{$anon_block}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 94 | ▶ | if (defined $stack and ref $stack eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $stack and ref $stack eq "ARRAY"
MC/DC0%0/2
defined $stack and ref $stack eq "ARRAY"
defined $stack
ref $stack eq "ARRAY"
Truth table33%1/3
A and B
A= defined $stackB= ref $stack eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 94 | my $block_label = $stack->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ## this expression is dependent on got_start_block() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 94 | my ($tag, $label, @others) = split /::/, $block_label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 94 | ▶ | $label = $expected_label if $label ne $expected_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 94 | ▶ | $block_label = "BLOCK::${label}::${name}" if $label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # change the LABEL:: value in the stack for code-generation ease | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # we want to use the expected label and not the anon one unless it is an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # anon-block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 94 | $stack->[0] = join("::", $tag, $label, @others); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 94 | my $elabel = "_end$label"; # end label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 94 | my $slabel = $label; # start label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 94 | ▶ | if (defined $parent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 43 | ▶ | unless ($parent =~ /BLOCK::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 43 | $block_label .= "::$parent"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 43 | ▶ | if (exists $self->ast->{$parent} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $self->ast->{$parent} and ref $self->ast->{$parent} eq "ARRAY" and $parent ne $anon_block
exists $self->ast->{$parent} and ref $self->ast->{$parent} eq "ARRAY"
MC/DC0%0/3
exists $self->ast->{$parent} and ref $self->ast->{$parent} eq "ARRAY" and $parent ne $anon_block
exists $self->ast->{$parent}
ref $self->ast->{$parent} eq "ARRAY"
$parent ne $anon_block
Truth table25%1/4
A and B and C
A= exists $self->ast->{$parent}B= ref $self->ast->{$parent} eq "ARRAY"C= $parent ne $anon_block
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ref $self->ast->{$parent} eq 'ARRAY' and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $parent ne $anon_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 43 | my ($ptag, $plabel) = split /::/, $self->ast->{$parent}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 43 | ▶ | $block_label .= "::$plabel" if $plabel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 43 | my $ccount = $self->ast->{conditionals}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 43 | ▶ | if ($block_label =~ /True|False/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 16 | $elabel = "_end_conditional_$ccount"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 16 | $slabel = "_start_conditional_$ccount"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 43 | $block_label .= "::$elabel"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 43 | ▶ | $block_label .= "::$expected_param" if length $expected_param; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 43 | push @{$self->ast->{$parent}}, $block_label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # save this for referencing when we need to know what the parent of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # this block is in case we need to jump out of the block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 94 | $self->ast->{block_mapping}->{$name}->{parent} = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 94 | $self->ast->{block_mapping}->{$anon_block}->{parent} = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 94 | $self->ast->{block_mapping}->{$name}->{end_label} = $elabel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 94 | $self->ast->{block_mapping}->{$anon_block}->{end_label} = $elabel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 94 | $self->ast->{block_mapping}->{$name}->{start_label} = $slabel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 94 | $self->ast->{block_mapping}->{$anon_block}->{start_label} = $slabel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 94 | ▶ | $self->ast->{block_mapping}->{$anon_block}->{loop} = '1' if $block_label =~ /Loop/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 94 | return $block_label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 78 | ▶ | sub got_named_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_named_block: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 78 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 78 | ▶ | $self->flatten($list) if ref $list eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 78 | my ($name, $anon_block, $parent_block) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 78 | return $self->handle_named_block(@$list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 94 | ▶ | sub got_anonymous_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_anonymous_block: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 94 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 94 | my $list = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 94 | my ($anon_block, $block_stack, $parent) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # returns anon_block and parent_block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 94 | return [$anon_block, $parent]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 95 | ▶ | sub got_start_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_start_block: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 95 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 95 | my $id = $self->ast->{block_count}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # we may not know the block name here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 95 | my $block = lc "_anonblock$id"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 95 | push @{$self->ast->{block_stack}}, $block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 95 | $self->ast->{$block} = [ "LABEL::$block" ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 95 | $self->ast->{block_count}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 95 | return $block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 94 | ▶ | sub got_end_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_end_block: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 94 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # we are not capturing anything here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 94 | my $stack = $self->ast->{block_stack}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 94 | my $block = pop @$stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 94 | return $stack->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 779 | ▶ | sub got_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_name: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 779 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 779 | ▶ | if (ref $list eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 779 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 779 | return shift(@$list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 381 | ▶ | sub update_intermediate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_intermediate: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 381 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 381 | my $block = $self->ast->{block_stack}->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 381 | ▶ | push @{$self->ast->{$block}}, @_ if $block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 381 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 246 | ▶ | sub got_instruction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_instruction: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 246 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 246 | my $method = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 246 | ▶ | $self->flatten($list) if $list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 246 | my $tag = 'INS'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # check if it is a simulator method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 246 | ▶ | if ($self->simulator and $self->simulator->can($method)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->simulator and $self->simulator->can($method)
MC/DC50%1/2
$self->simulator and $self->simulator->can($method)
$self->simulator
$self->simulator->can($method)
Truth table66%2/3
A and B
A= $self->simulatorB= $self->simulator->can($method)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # this is a simulator instruction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 107 | $tag = 'SIM'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 139 | ▶ | unless ($self->pic->can($method)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | my $err = "Unsupported instruction '$method' for chip " . uc $self->pic->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | return $self->parser->throw_error($err); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 245 | my @args = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 245 | ▶ | while (scalar @$list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 355 | my $a = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 355 | ▶ | if ($a =~ /BLOCK::(\w+)::(Action|ISR)\w+::.*::(_end_\w+)::(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 11 | push @args, uc($2) . "::$1::END::$3::PARAM::$4"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 344 | push @args, $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 245 | $self->update_intermediate("${tag}::${method}::" . join ("::", @args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 245 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | sub got_unary_rhs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_unary_rhs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | return [ reverse @$list ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 8 | ▶ | sub got_unary_expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_unary_expr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 8 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 8 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 8 | my $op = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 8 | my $varname = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 8 | $self->update_intermediate("UNARY::${op}::${varname}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 85 | ▶ | sub got_assign_expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_assign_expr: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 85 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 85 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 85 | my $varname = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 85 | my $op = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 85 | my $rhsx = $self->got_expr_value($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 85 | ▶ | my $rhs = ref $rhsx eq 'ARRAY' ? join ("::", @$rhsx) : $rhsx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 85 | ▶ | if ($rhs =~ /PARAM::(\w+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ## ok now we push this as our statement and handle the rest during | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ## code generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | ## this is of the format PARAM::op::block_name::variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 5 | my $block = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 5 | $self->update_intermediate("PARAM::${op}::${block}::${varname}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 80 | $self->update_intermediate("SET::${op}::${varname}::${rhs}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 85 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | ▶ | sub got_array_element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_array_element: called CC=10 SCAR=31.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | my $var1 = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | my $rhsx = $self->got_expr_value($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | if (ref $rhsx eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | XXX $rhsx; # why would this even happen | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | my $tvref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$tvref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | my $vref = $self->ast->{variables}->{$var1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | my @ops = ('OP'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | if (exists $vref->{type} and $vref->{type} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
exists $vref->{"type"} and $vref->{"type"} eq "HASH"
MC/DC0%0/2
exists $vref->{"type"} and $vref->{"type"} eq "HASH"
exists $vref->{"type"}
$vref->{"type"} eq "HASH"
Truth table33%1/3
A and B
A= exists $vref->{"type"}B= $vref->{"type"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | push @ops, $vref->{label}, 'TBLIDX', $rhsx, $vref->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | ▶ | } elsif (exists $vref->{type} and $vref->{type} eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exists $vref->{"type"} and $vref->{"type"} eq "ARRAY"
MC/DC0%0/2
exists $vref->{"type"} and $vref->{"type"} eq "ARRAY"
exists $vref->{"type"}
$vref->{"type"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $vref->{"type"}B= $vref->{"type"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | push @ops, $vref->{label}, 'ARRIDX', $rhsx, $vref->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ▶ | } elsif (exists $vref->{type} and $vref->{type} eq 'string') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exists $vref->{"type"} and $vref->{"type"} eq "string"
MC/DC0%0/2
exists $vref->{"type"} and $vref->{"type"} eq "string"
exists $vref->{"type"}
$vref->{"type"} eq "string"
Truth table0%0/3
A and B
A= exists $vref->{"type"}B= $vref->{"type"} eq "string"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | push @ops, $vref->{label}, 'STRIDX', $rhsx, $vref->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # this must be a byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return $self->parser->throw_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | "Variable '$var1' is not an array, table or string"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | $tvref->{$tvar} = join("::", @ops); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # create a new variable here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | my $varname = sprintf "vic_el_%02d", scalar(keys %$tvref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | $varname = $self->got_variable([$varname]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | if ($varname) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | $self->update_intermediate("SET::ASSIGN::${varname}::${tvar}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | return $varname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return $self->parser->throw_error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | "Unable to create intermediary variable '$varname'") unless $varname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 5 | ▶ | sub got_parameter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_parameter: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ## ok the target variable needs a parameter here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ## this works only in block scope so we want to check which block we are in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 5 | my $block = $self->ast->{block_stack}->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 5 | return "PARAM::$block"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | ▶ | sub got_declaration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_declaration: called CC=16 SCAR=36.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 3 | my $lhs = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | my $rhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 3 | ▶ | if (scalar @$list == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | $rhs = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $rhs = $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # TODO: generate intermediate code here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | ▶ | if (ref $rhs eq 'HASH' or ref $rhs eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $rhs eq "HASH" or ref $rhs eq "ARRAY"
MC/DC0%0/2
ref $rhs eq "HASH" or ref $rhs eq "ARRAY"
ref $rhs eq "HASH"
ref $rhs eq "ARRAY"
Truth table33%1/3
A or B
A= ref $rhs eq "HASH"B= ref $rhs eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | ▶ | if (not exists $self->ast->{variables}->{$lhs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return $self->parser->throw_error("Variable '$lhs' doesn't exist"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | ▶ | if (exists $rhs->{TABLE} or ref $rhs eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
exists $rhs->{"TABLE"} or ref $rhs eq "ARRAY"
MC/DC50%1/2
exists $rhs->{"TABLE"} or ref $rhs eq "ARRAY"
exists $rhs->{"TABLE"}
ref $rhs eq "ARRAY"
Truth table66%2/3
A or B
A= exists $rhs->{"TABLE"}B= ref $rhs eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | my $label = lc "_table_$lhs" if ref $rhs eq 'HASH' and exists $rhs->{TABLE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $rhs eq "HASH" and exists $rhs->{"TABLE"}
MC/DC0%0/2
ref $rhs eq "HASH" and exists $rhs->{"TABLE"}
ref $rhs eq "HASH"
exists $rhs->{"TABLE"}
Truth table33%1/3
A and B
A= ref $rhs eq "HASH"B= exists $rhs->{"TABLE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | my $szpref = "VIC_TBLSZ_" if ref $rhs eq 'HASH' and exists $rhs->{TABLE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $rhs eq "HASH" and exists $rhs->{"TABLE"}
MC/DC0%0/2
ref $rhs eq "HASH" and exists $rhs->{"TABLE"}
ref $rhs eq "HASH"
exists $rhs->{"TABLE"}
Truth table33%1/3
A and B
A= ref $rhs eq "HASH"B= exists $rhs->{"TABLE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | $szpref = "VIC_ARRSZ_" if ref $rhs eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | $self->ast->{variables}->{$lhs}->{type} = ref $rhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | $self->ast->{variables}->{$lhs}->{data} = $rhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | $self->ast->{variables}->{$lhs}->{label} = $label || $lhs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$label || $lhs
MC/DC0%0/2
$label || $lhs
$label
$lhs
Truth table33%1/3
A || B
A= $labelB= $lhs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | if ($szpref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | $self->ast->{variables}->{$lhs}->{size} = $szpref . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | $self->ast->{variables}->{$lhs}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } elsif (exists $rhs->{string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # handle variable that are strings here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | $self->ast->{variables}->{$lhs}->{data} = $rhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | $self->ast->{variables}->{$lhs}->{type} = 'string'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | $self->ast->{variables}->{$lhs}->{size} = "VIC_STRSZ_" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | $self->ast->{variables}->{$lhs}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | $self->update_intermediate("SET::ASSIGN::${lhs}::${rhs}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | return $self->parser->throw_error("We should not be here"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # var = number | string etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ($rhs =~ /^-?\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # we just use the got_assign_expr. this should never be called in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # reality but is here in case the grammar rules change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $self->update_intermediate("SET::ASSIGN::${lhs}::${rhs}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | #VIKAS: check this! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # handle strings here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->ast->{variables}->{$lhs}->{type} = 'string'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $self->ast->{variables}->{$lhs}->{data} = $rhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $self->ast->{variables}->{$lhs}->{label} = $lhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | $self->ast->{variables}->{$lhs}->{size} = "VIC_STRSZ_" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->ast->{variables}->{$lhs}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 12 | ▶ | sub got_conditional_statement { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_conditional_statement: called CC=29 SCAR=36.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 12 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 12 | my ($type, $subject, $predicate) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 12 | ▶ | return unless scalar @$predicate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 12 | ▶ | my $is_loop = ($type eq 'while') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 12 | my ($current, $parent) = $self->stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 12 | my $subcond = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 12 | ▶ | $subcond = 1 if $parent =~ /^conditional/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 12 | ▶ | if (ref $predicate ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $predicate = [ $predicate ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 12 | my @condblocks = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 12 | ▶ | if (scalar @$predicate < 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 12 | ▶ | my $tb = $predicate->[0] || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$predicate[{sign => '+', value => ['0']}] || undef
MC/DC0%0/1
$$predicate[{sign => '+', value => ['0']}] || undef
$$predicate[{sign => '+', value => ['0']}]
Truth table50%1/2
A
A= $$predicate[{sign => '+', value => ['0']}]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 12 | ▶ | my $fb = $predicate->[1] || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$predicate[{sign => '+', value => ['1']}] || undef
MC/DC0%0/1
$$predicate[{sign => '+', value => ['1']}] || undef
$$predicate[{sign => '+', value => ['1']}]
Truth table50%1/2
A
A= $$predicate[{sign => '+', value => ['1']}]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 12 | ▶ | $self->flatten($tb) if $tb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | ▶ | $self->flatten($fb) if $fb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 12 | ▶ | my $true_block = $self->handle_named_block('True', @$tb) if $tb and scalar @$tb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$tb and scalar @$tb
MC/DC0%0/1
$tb and scalar @$tb
$tb
Truth table50%1/2
A
A= $tb
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 12 | ▶ | push @condblocks, $true_block if $true_block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 12 | ▶ | my $false_block = $self->handle_named_block('False', @$fb) if $fb and scalar @$fb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$fb and scalar @$fb
MC/DC0%0/1
$fb and scalar @$fb
$fb
Truth table50%1/2
A
A= $fb
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 12 | ▶ | push @condblocks, $false_block if $false_block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | return $self->parser->throw_error("Multiple predicate conditionals not implemented"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 12 | my $inter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 12 | ▶ | if (scalar @condblocks < 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 12 | my ($false_label, $true_label, $end_label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 12 | my ($false_name, $true_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 12 | foreach my $p (@condblocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 16 | ▶ | ($false_label, $false_name) = ($1, $2) if $p =~ /BLOCK::(\w+)::(False\d+)::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 16 | ▶ | ($true_label, $true_name) = ($1, $2) if $p =~ /BLOCK::(\w+)::(True\d+)::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 16 | ▶ | $end_label = $1 if $p =~ /BLOCK::.*::(_end_conditional\w+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 12 | ▶ | $false_label = $end_label unless defined $false_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 12 | ▶ | $true_label = $end_label unless defined $true_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 12 | my $subj = $subject; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 12 | ▶ | $subj = shift @$subject if ref $subject eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | $inter = join("::", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | COND => $self->ast->{conditionals}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 12 | SUBJ => $subj, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | FALSE => $false_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | TRUE => $true_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | END => $end_label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | LOOP => $is_loop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | SUBCOND => $subcond); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 12 | my $mapping = $self->ast->{block_mapping}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 12 | ▶ | if ($true_name and exists $mapping->{$true_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$true_name and exists $mapping->{$true_name}
MC/DC0%0/2
$true_name and exists $mapping->{$true_name}
$true_name
exists $mapping->{$true_name}
Truth table33%1/3
A and B
A= $true_nameB= exists $mapping->{$true_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 12 | $mapping->{$true_name}->{loop} = "$is_loop"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 12 | my $ab = $mapping->{$true_name}->{block}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 12 | $mapping->{$ab}->{loop} = "$is_loop"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 12 | ▶ | if ($false_name and exists $mapping->{$false_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$false_name and exists $mapping->{$false_name}
MC/DC50%1/2
$false_name and exists $mapping->{$false_name}
$false_name
exists $mapping->{$false_name}
Truth table66%2/3
A and B
A= $false_nameB= exists $mapping->{$false_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 4 | $mapping->{$false_name}->{loop} = "$is_loop"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 4 | my $ab = $mapping->{$false_name}->{block}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 4 | $mapping->{$ab}->{loop} = "$is_loop"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | return $self->parser->throw_error("Multiple predicate conditionals not implemented"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 12 | $self->update_intermediate($inter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 12 | ▶ | $self->ast->{conditionals}++ unless $subcond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | ##WARNING: do not change this function without looking at its effect on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | #got_conditional_statement() above which calls this function explicitly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # this function is identical to got_expr_value() and hence redundant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # we may need to just use the same one although precedence will be different | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # so maybe not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 16 | ▶ | sub got_conditional_subject { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_conditional_subject: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 16 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 16 | ▶ | if (ref $list eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 16 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 16 | ▶ | if (scalar @$list == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | my $var1 = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | ▶ | return $var1 if $var1 =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | my $vref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 3 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$vref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 3 | $vref->{$tvar} = "OP::${var1}::EQ::1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 3 | return $tvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } elsif (scalar @$list == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my ($op, $var) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $vref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$vref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $vref->{$tvar} = "OP::${op}::${var}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return $tvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } elsif (scalar @$list == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 11 | my ($var1, $op, $var2) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 11 | my $vref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 11 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$vref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 11 | $vref->{$tvar} = "OP::${var1}::${op}::${var2}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 11 | return $tvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # handle precedence with left-to-right association | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | my @arr = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | ▶ | my $idx = firstidx { $_ =~ /^GE|GT|LE|LT|EQ|NE$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | ▶ | while ($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | my $res = $self->got_conditional_subject([$arr[$idx - 1], $arr[$idx], $arr[$idx + 1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | $arr[$idx - 1] = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 2 | splice @arr, $idx, 2; # remove the extra elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 2 | ▶ | $idx = firstidx { $_ =~ /^GE|GT|LE|LT|EQ|NE$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | ▶ | $idx = firstidx { $_ =~ /^AND|OR$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | ▶ | while ($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | my $res = $self->got_conditional_subject([$arr[$idx - 1], $arr[$idx], $arr[$idx + 1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $arr[$idx - 1] = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | splice @arr, $idx, 2; # remove the extra elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | ▶ | $idx = firstidx { $_ =~ /^AND|OR$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # YYY $self->ast->{tmp_variables}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | return $self->got_conditional_subject([@arr]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | ##WARNING: do not change this function without looking at its effect on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | #got_assign_expr() above which calls this function explicitly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 296 | ▶ | sub got_expr_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_expr_value: called CC=11 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 296 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 296 | ▶ | if (ref $list eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 296 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 296 | ▶ | if (scalar @$list == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 236 | my $val = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 236 | ▶ | if ($val =~ /MOP::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | my $vref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$vref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 2 | $vref->{$tvar} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 2 | return $tvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 234 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } elsif (scalar @$list == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 8 | my ($op, $var) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 8 | my $vref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 8 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$vref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 8 | $vref->{$tvar} = "OP::${op}::${var}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 8 | return $tvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } elsif (scalar @$list == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 46 | my ($var1, $op, $var2) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 46 | my $vref = $self->ast->{tmp_variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 46 | my $tvar = sprintf "_vic_tmp_%02d", scalar(keys %$vref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 46 | $vref->{$tvar} = "OP::${var1}::${op}::${var2}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 46 | return $tvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } elsif (scalar @$list > 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # handle precedence with left-to-right association | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 6 | my @arr = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 6 | ▶ | my $idx = firstidx { $_ =~ /^MUL|DIV|MOD$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 6 | ▶ | while ($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 8 | my $res = $self->got_expr_value([$arr[$idx - 1], $arr[$idx], $arr[$idx + 1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 8 | $arr[$idx - 1] = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 8 | splice @arr, $idx, 2; # remove the extra elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 8 | ▶ | $idx = firstidx { $_ =~ /^MUL|DIV|MOD$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 6 | ▶ | $idx = firstidx { $_ =~ /^ADD|SUB$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 6 | ▶ | while ($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 8 | my $res = $self->got_expr_value([$arr[$idx - 1], $arr[$idx], $arr[$idx + 1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 8 | $arr[$idx - 1] = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 8 | splice @arr, $idx, 2; # remove the extra elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 8 | ▶ | $idx = firstidx { $_ =~ /^ADD|SUB$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 6 | ▶ | $idx = firstidx { $_ =~ /^SHL|SHR$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 6 | ▶ | while ($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | my $res = $self->got_expr_value([$arr[$idx - 1], $arr[$idx], $arr[$idx + 1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | $arr[$idx - 1] = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | splice @arr, $idx, 2; # remove the extra elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | $idx = firstidx { $_ =~ /^SHL|SHR$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 6 | ▶ | $idx = firstidx { $_ =~ /^BAND|BXOR|BOR$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 6 | ▶ | while ($idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | my $res = $self->got_expr_value([$arr[$idx - 1], $arr[$idx], $arr[$idx + 1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $arr[$idx - 1] = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | splice @arr, $idx, 2; # remove the extra elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | $idx = firstidx { $_ =~ /^BAND|BXOR|BOR$/ } @arr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # YYY $self->ast->{tmp_variables}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 6 | return $self->got_expr_value([@arr]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 42 | ▶ | sub got_math_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_math_operator: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 42 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 42 | ▶ | return 'ADD' if $op eq '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 26 | ▶ | return 'SUB' if $op eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 20 | ▶ | return 'MUL' if $op eq '*'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 10 | ▶ | return 'DIV' if $op eq '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 4 | ▶ | return 'MOD' if $op eq '%'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return $self->parser->throw_error("Math operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 4 | ▶ | sub got_shift_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_shift_operator: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 4 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 4 | ▶ | return 'SHL' if $op eq '<<'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 2 | ▶ | return 'SHR' if $op eq '>>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | return $self->parser->throw_error("Shift operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | sub got_bit_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_bit_operator: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | return 'BXOR' if $op eq '^'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | return 'BOR' if $op eq '|'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | return 'BAND' if $op eq '&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | return $self->parser->throw_error("Bitwise operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 2 | ▶ | sub got_logic_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_logic_operator: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 2 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 2 | ▶ | return 'AND' if $op eq '&&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 1 | ▶ | return 'OR' if $op eq '||'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | return $self->parser->throw_error("Logic operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 37 | ▶ | sub got_compare_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_compare_operator: called CC=7 SCAR=20.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 37 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 37 | ▶ | return 'LE' if $op eq '<='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 36 | ▶ | return 'LT' if $op eq '<'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 36 | ▶ | return 'GE' if $op eq '>='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 36 | ▶ | return 'GT' if $op eq '>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 35 | ▶ | return 'EQ' if $op eq '=='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 4 | ▶ | return 'NE' if $op eq '!='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | return $self->parser->throw_error("Compare operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 8 | ▶ | sub got_complement_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_complement_operator: called CC=3 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 8 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 8 | ▶ | return 'NOT' if $op eq '!'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | return 'COMP' if $op eq '~'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | return $self->parser->throw_error("Complement operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 88 | ▶ | sub got_assign_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_assign_operator: called CC=14 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 88 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 88 | ▶ | if (ref $op eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | $self->flatten($op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $op = shift @$op; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 88 | ▶ | return 'ASSIGN' if $op eq '='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 25 | ▶ | return 'ADD_ASSIGN' if $op eq '+='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 23 | ▶ | return 'SUB_ASSIGN' if $op eq '-='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 21 | ▶ | return 'MUL_ASSIGN' if $op eq '*='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 19 | ▶ | return 'DIV_ASSIGN' if $op eq '/='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 17 | ▶ | return 'MOD_ASSIGN' if $op eq '%='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 15 | ▶ | return 'BXOR_ASSIGN' if $op eq '^='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 13 | ▶ | return 'BOR_ASSIGN' if $op eq '|='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 11 | ▶ | return 'BAND_ASSIGN' if $op eq '&='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 8 | ▶ | return 'SHL_ASSIGN' if $op eq '<<='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 6 | ▶ | return 'SHR_ASSIGN' if $op eq '>>='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | ▶ | return 'CAT_ASSIGN' if $op eq '.='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | return $self->parser->throw_error("Assignment operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 8 | ▶ | sub got_unary_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_unary_operator: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 8 | my ($self, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 8 | ▶ | return 'INC' if $op eq '++'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 2 | ▶ | return 'DEC' if $op eq '--'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | return $self->parser->throw_error("Increment/Decrement operator '$op' is not supported"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 10 | ▶ | sub got_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_array: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 10 | my ($self, $arr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 10 | ▶ | $self->flatten($arr) if ref $arr eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 10 | $self->global_collections->{"$arr"} = $arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 10 | return $arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 12 | ▶ | sub got_modifier_constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_modifier_constant: called CC=13 SCAR=37.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 12 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | # we don't flatten since $value can be an array as well | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 12 | my ($modifier, $value) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 12 | $modifier = uc $modifier; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | ## first check if the modifier is an operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 12 | my $method = $self->pic->validate_modifier_operator($modifier); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 12 | ▶ | $self->flatten($value) if ($method and ref $value eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$method and ref $value eq "ARRAY"
MC/DC0%0/2
$method and ref $value eq "ARRAY"
$method
ref $value eq "ARRAY"
Truth table33%1/3
A and B
A= $methodB= ref $value eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 12 | ▶ | return $self->got_expr_value(["MOP::${modifier}::${value}"]) if $method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | ## if not then check if it is a type modifier for use by the simulator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 12 | ▶ | if ($self->simulator and $self->simulator->supports_modifier($modifier)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->simulator and $self->simulator->supports_modifier($modifier)
MC/DC0%0/2
$self->simulator and $self->simulator->supports_modifier($modifier)
$self->simulator
$self->simulator->supports_modifier($modifier)
Truth table33%1/3
A and B
A= $self->simulatorB= $self->simulator->supports_modifier($modifier)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 11 | my $hh = { $modifier => $value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 11 | $self->global_collections->{"$hh"} = $hh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 11 | return $hh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | ## ok check if the modifier is a type modifier for code generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | ## this is reallly a bad hack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 1 | ▶ | if ($modifier eq 'TABLE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | ▶ | return { TABLE => $value } if ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return { TABLE => [$value] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } elsif ($modifier eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | return $value if ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | return [$value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } elsif ($modifier eq 'STRING') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | return { STRING => $value } if ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | return { STRING => [$value] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | $self->parser->throw_error("Modifying operator '$modifier' not supported") unless $method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 2 | ▶ | sub got_modifier_variable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_modifier_variable: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 2 | my ($modifier, $varname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2 | ▶ | $self->flatten($list) if ref $list eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 2 | $modifier = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | $varname = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 2 | $modifier = uc $modifier; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 2 | my $method = $self->pic->validate_modifier_operator($modifier); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 2 | ▶ | $self->parser->throw_error("Modifying operator '$modifier' not supported") unless $method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 2 | return $self->got_expr_value(["MOP::${modifier}::${varname}"]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 207 | ▶ | sub got_validated_variable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_validated_variable: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 207 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 207 | my $varname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 207 | ▶ | if (ref $list eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 207 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 207 | $varname = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 207 | my $suffix = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 207 | ▶ | $varname .= $suffix if defined $suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | $varname = $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 207 | ▶ | return $varname if $self->pic->validate($varname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | return $self->parser->throw_error("'$varname' is not a valid part of the " . uc $self->pic->type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 419 | ▶ | sub got_variable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_variable: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 419 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 419 | ▶ | $self->flatten($list) if ref $list eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 419 | my $varname = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 419 | my ($current, $parent) = $self->stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # if the variable is used from the pragma grammar rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # we do not want to store it yet and definitely not store the size yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | # we could remove this if we set the size after the code generation or so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # but that may lead to more complexity. this is much easier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 419 | ▶ | return $varname if $parent eq 'pragmas'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | $self->ast->{variables}->{$varname} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | name => uc $varname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | scope => $self->ast->{block_stack}->[-1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | size => POSIX::ceil($self->pic->address_bits($varname) / 8), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | type => 'byte', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | data => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 419 | ▶ | } unless exists $self->ast->{variables}->{$varname}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 419 | ▶ | $self->ast->{variables}->{$varname}->{scope} = 'global' if $parent =~ /assert_/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 419 | return $varname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 11 | ▶ | sub got_boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_boolean: called CC=6 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 11 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 11 | my $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 11 | ▶ | if (ref $list eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | $b = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 11 | $b = $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 11 | ▶ | return 0 unless defined $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 11 | ▶ | return 1 if $b =~ /TRUE|true/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 5 | ▶ | return 1 if $b == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 5 | ▶ | return 0 if $b =~ /FALSE|false/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | return 0; # default boolean is false | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 43 | ▶ | sub got_double_quoted_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_double_quoted_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 43 | my $str = pop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | ## Ripped from Ingy's pegex-json-pm Pegex::JSON::Data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | ## Unicode support not implemented yet but available in Pegex::JSON::Data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 43 | my %escapes = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | '"' => '"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | '/' => '/', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | "\\" => "\\", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | b => "\b", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | f => "\x12", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | n => "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | r => "\r", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | t => "\t", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 => "\0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 43 | $str =~ s/\\(["\/\\bfnrt0])/$escapes{$1}/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 43 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 48 | ▶ | sub got_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_string: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 48 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 48 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | ##TODO: handle empty strings as initializers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # store only unique strings otherwise re-use them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 48 | foreach (%{$self->global_collections}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 591 | my $h = $self->global_collections->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 591 | ▶ | return $h if ($h->{string} eq $str); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 47 | ▶ | my $is_empty = 1 if $str eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | my $stref = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | string => $str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | block => $self->ast->{block_stack}->[-1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 47 | name => sprintf("_vic_str_%02d", $self->ast->{strings}), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | size => length($str) + 1, # trailing null byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | empty => $is_empty, # required for variable allocation later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 47 | $self->global_collections->{"$stref"} = $stref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 47 | $self->ast->{strings}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 47 | return $stref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | #return '@' . $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 400 | ▶ | sub got_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_number: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 400 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | # if it is a hexadecimal number we can just convert it to number using int() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | # since hex is returned here as a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 400 | ▶ | return hex($list) if $list =~ /0x|0X/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 344 | my $val = int($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 344 | ▶ | return $val if $val >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | ##TODO: check the negative value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | my $bits = (2 ** $self->pic->address_bits) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | $val = sprintf "0x%02X", $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | return hex($val) & $bits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | # convert the number to appropriate units | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 51 | ▶ | sub got_number_units { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_number_units: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 51 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 51 | $self->flatten($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 51 | my $num = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 51 | my $units = shift @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 51 | ▶ | return $num unless defined $units; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 51 | ▶ | $num *= 1 if $units eq 'us'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 51 | ▶ | $num *= 1000 if $units eq 'ms'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 51 | ▶ | $num *= 1e6 if $units eq 's'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 51 | ▶ | $num *= 1 if $units eq 'Hz'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 51 | ▶ | $num *= 1000 if $units eq 'kHz'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 51 | ▶ | $num *= 1e6 if $units eq 'MHz'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # ignore the '%' sign for now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 51 | return $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 5 | ▶ | sub got_real_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_real_number: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 5 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 5 | ▶ | $list .= '0' if $list =~ /\d+\.$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 5 | ▶ | $list = "0.$1" if $list =~ /^\.(\d+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 5 | ▶ | $list = "-0.$1" if $list =~ /^-\.(\d+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 5 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # remove the dumb stuff from the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 68 | ▶ | sub got_comment { return; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_comment: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 66 | ▶ | sub _update_funcs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_funcs: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 66 | my ($self, $funcs, $macros) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 66 | ▶ | if (ref $funcs eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 66 | foreach (keys %$funcs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 21 | $self->ast->{funcs}->{$_} = $funcs->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 66 | ▶ | if (ref $macros eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 66 | ▶ | return unless ref $macros eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 66 | foreach (keys %$macros) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 140 | $self->ast->{macros}->{$_} = $macros->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 66 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 18 | ▶ | sub _update_tables { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_tables: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 18 | my ($self, $tables) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 18 | ▶ | if (ref $tables eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | $tables = [ $tables ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 18 | ▶ | unless (ref $tables eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | return $self->parser->throw_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | "Code generation error. PIC methods should return strings as a HASH or ARRAY"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 18 | foreach my $s (@$tables) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 5 | ▶ | next unless defined $s->{bytes}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 5 | ▶ | next unless defined $s->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 5 | push @{$self->ast->{tables}}, $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | ## assert handling is special for now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 28 | ▶ | sub got_assert_comparison { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_assert_comparison: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 28 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 28 | ▶ | return unless $self->simulator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 28 | ▶ | $self->flatten($list) if ref $list eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 28 | ▶ | if (scalar @$list < 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | return $self->parser->throw_error("Error in assert statement"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 28 | return join("@@", @$list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 28 | ▶ | sub got_assert_statement { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
got_assert_statement: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 28 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 28 | ▶ | $self->flatten($list) if ref $list eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 28 | my ($method, $cond, $msg) = @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 28 | ▶ | $msg = '' unless defined $msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 28 | $self->ast->{asserts}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 28 | $self->update_intermediate("SIM::${method}::${cond}::${msg}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 28 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 130 | ▶ | sub generate_simulator_instruction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_simulator_instruction: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 130 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 130 | my @ins = split /::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 130 | my $tag = shift @ins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 130 | my $method = shift @ins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 130 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 130 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 130 | foreach (@ins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 188 | ▶ | next unless /HASH|ARRAY/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 50 | ▶ | next unless exists $self->global_collections->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 50 | $_ = $self->global_collections->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 130 | ▶ | return @code if $self->simulator->disable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 129 | my $code = $self->simulator->$method(@ins); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 129 | ▶ | return $self->parser->throw_error("Error in simulator intermediate code '$line'") unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 129 | ▶ | push @code, $code if $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 129 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 136 | ▶ | sub generate_code_instruction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code_instruction: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 136 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 136 | my @ins = split /::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 136 | my $tag = shift @ins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 136 | my $method = shift @ins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 136 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 136 | foreach (@ins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 269 | ▶ | if (exists $self->global_collections->{$_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 6 | $_ = $self->global_collections->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 263 | ▶ | if (exists $self->ast->{variables}->{$_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 29 | my $vhref = $self->ast->{variables}->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 29 | ▶ | if ($vhref->{type} eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # send the string variable information to the method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # and hope that the method knows how to handle it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # this is useful for I/O methods and operator methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # other methods should outright fail to use this and it should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | # make sense there.#TODO: make better error messages for that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 1 | $_ = $vhref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 136 | my ($code, $funcs, $macros, $tables) = $self->pic->$method(@ins); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 136 | ▶ | return $self->parser->throw_error("Error in intermediate code '$line'") unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 135 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 135 | ▶ | push @code, $code if $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 135 | ▶ | $self->_update_funcs($funcs, $macros) if ($funcs or $macros); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$funcs or $macros
MC/DC50%1/2
$funcs or $macros
$funcs
$macros
Truth table66%2/3
A or B
A= $funcsB= $macros
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 135 | ▶ | $self->_update_tables($tables) if $tables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 135 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 8 | ▶ | sub generate_code_unary_expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code_unary_expr: called CC=10 SCAR=26.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 8 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 8 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 8 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 8 | my ($tag, $op, $varname) = split /::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 8 | my $method = $self->pic->validate_operator($op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 8 | ▶ | $self->parser->throw_error("Invalid operator '$op' in intermediate code") unless $self->pic->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | # check if temporary variable or not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 8 | ▶ | if (exists $ast->{variables}->{$varname}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 8 | ▶ | my $nvar = $ast->{variables}->{$varname}->{name} || $varname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ast->{'variables'}{$varname}{'name'} || $varname
MC/DC0%0/2
$ast->{'variables'}{$varname}{'name'} || $varname
$ast->{'variables'}{$varname}{'name'}
$varname
Truth table33%1/3
A || B
A= $ast->{'variables'}{$varname}{'name'}B= $varname
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 8 | my ($code, $funcs, $macros, $tables) = $self->pic->$method($nvar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 8 | ▶ | return $self->parser->throw_error("Error in intermediate code '$line'") unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 8 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 8 | ▶ | push @code, $code if $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 8 | ▶ | $self->_update_funcs($funcs, $macros) if ($funcs or $macros); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$funcs or $macros
MC/DC0%0/2
$funcs or $macros
$funcs
$macros
Truth table33%1/3
A or B
A= $funcsB= $macros
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 8 | ▶ | $self->_update_tables($tables) if $tables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 0 | return $self->parser->throw_error("Error in intermediate code '$line'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 8 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 70 | ▶ | sub generate_code_operations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code_operations: called CC=19 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 70 | my ($self, $line, %extra) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 70 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 70 | my ($tag, @args) = split /::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 70 | my ($op, $var1, $var2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 70 | ▶ | if (scalar @args == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 9 | $op = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 9 | $var1 = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | } elsif (scalar @args == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 60 | $var1 = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 60 | $op = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 60 | $var2 = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } elsif (scalar @args == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 1 | $var1 = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 1 | $op = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 1 | $var2 = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 1 | my $var3 = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 1 | $extra{SIZE} = $var3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | return $self->parser->throw_error("Error in intermediate code '$line'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 70 | ▶ | if (exists $extra{STACK}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 36 | ▶ | if (defined $var1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 36 | ▶ | $var1 = $extra{STACK}->{$var1} || $var1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$extra{'STACK'}{$var1} || $var1
MC/DC0%0/2
$extra{'STACK'}{$var1} || $var1
$extra{'STACK'}{$var1}
$var1
Truth table66%2/3
A || B
A= $extra{'STACK'}{$var1}B= $var1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 36 | ▶ | if (defined $var2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 35 | ▶ | $var2 = $extra{STACK}->{$var2} || $var2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$extra{'STACK'}{$var2} || $var2
MC/DC100%2/2
$extra{'STACK'}{$var2} || $var2
$extra{'STACK'}{$var2}
$var2
Truth table100%3/3
A || B
A= $extra{'STACK'}{$var2}B= $var2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 70 | ▶ | my $method = $self->pic->validate_operator($op) if $tag eq 'OP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 70 | ▶ | $method = $self->pic->validate_modifier_operator($op) if $tag eq 'MOP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 70 | ▶ | $self->parser->throw_error("Invalid operator '$op' in intermediate code") unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$method and $self->pic->can($method)
MC/DC0%0/2
$method and $self->pic->can($method)
$method
$self->pic->can($method)
Truth table33%1/3
A and B
A= $methodB= $self->pic->can($method)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | ($method and $self->pic->can($method)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 70 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 70 | my ($code, $funcs, $macros, $tables) = $self->pic->$method($var1, $var2, %extra); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 70 | ▶ | return $self->parser->throw_error("Error in intermediate code '$line'") unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 70 | ▶ | push @code, $code if $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 70 | ▶ | $self->_update_funcs($funcs, $macros) if ($funcs or $macros); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$funcs or $macros
MC/DC50%1/2
$funcs or $macros
$funcs
$macros
Truth table66%2/3
A or B
A= $funcsB= $macros
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 70 | ▶ | $self->_update_tables($tables) if $tables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 70 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 70 | ▶ | sub find_tmpvar_dependencies { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_tmpvar_dependencies: called CC=12 SCAR=26.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 70 | my ($self, $tvar) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 70 | my $tcode = $self->ast->{tmp_variables}->{$tvar}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 70 | my ($tag, @args) = split /::/, $tcode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 70 | ▶ | return unless $tag eq 'OP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 68 | my @deps = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 68 | my $sz = scalar @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 68 | ▶ | if ($sz == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 7 | my ($op, $var) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 7 | ▶ | if (exists $self->ast->{tmp_variables}->{$var}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | push @deps, $var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | my @rdeps = $self->find_tmpvar_dependencies($var); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | push @deps, @rdeps if @rdeps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | ▶ | } elsif ($sz == 3 or $sz == 4) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) or $sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
MC/DC0%0/2
$sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) or $sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
Truth table66%2/3
A or B
A= $sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' )B= $sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 61 | my ($var1, $op, $var2) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 61 | ▶ | if (exists $self->ast->{tmp_variables}->{$var1}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 15 | push @deps, $var1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 15 | my @rdeps = $self->find_tmpvar_dependencies($var1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 15 | ▶ | push @deps, @rdeps if @rdeps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 61 | ▶ | if (exists $self->ast->{tmp_variables}->{$var2}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 13 | push @deps, $var2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 13 | my @rdeps = $self->find_tmpvar_dependencies($var2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 13 | ▶ | push @deps, @rdeps if @rdeps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | return $self->parser->throw_error("Error in intermediate code '$tcode'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 68 | ▶ | return wantarray ? @deps : \@deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 42 | ▶ | sub find_var_dependencies { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_var_dependencies: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 42 | my ($self, $tvar) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 42 | my $tcode = $self->ast->{tmp_variables}->{$tvar}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 42 | my ($tag, @args) = split /::/, $tcode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 42 | ▶ | return unless $tag eq 'OP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 40 | my @deps = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 40 | my $sz = scalar @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 40 | ▶ | if ($sz == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 6 | my ($op, $var) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 6 | ▶ | if (exists $self->ast->{variables}->{$var}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 6 | push @deps, $var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | ▶ | } elsif ($sz == 3 or $sz == 4) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) or $sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
MC/DC0%0/2
$sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) or $sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
Truth table66%2/3
A or B
A= $sz == bless( {"sign" => "+","value" => bless( [3], 'Math::BigInt::Calc' )}, 'Math::BigInt' )B= $sz == bless( {"sign" => "+","value" => bless( [4], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 34 | my ($var1, $op, $var2) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 34 | ▶ | if (exists $self->ast->{variables}->{$var1}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 27 | push @deps, $var1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 34 | ▶ | if (exists $self->ast->{variables}->{$var2}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 12 | push @deps, $var2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | return $self->parser->throw_error("Error in intermediate code '$tcode'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 40 | ▶ | return wantarray ? @deps : \@deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 34 | ▶ | sub do_i_use_stack { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_i_use_stack: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 34 | my ($self, @deps) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 34 | ▶ | return 0 unless @deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 32 | my @bits = map { $self->pic->address_bits($_) } @deps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 32 | ▶ | return 0 if max(@bits) == $self->pic->wreg_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 88 | ▶ | sub generate_code_assign_expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code_assign_expr: called CC=30 SCAR=38.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 88 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 88 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 88 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 88 | my ($tag, $op, $varname, $rhs) = split /::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 88 | ▶ | push @code, ";;; $line\n" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 88 | ▶ | if (exists $ast->{variables}->{$varname}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 88 | ▶ | if (exists $ast->{tmp_variables}->{$rhs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 31 | my $tmp_code = $ast->{tmp_variables}->{$rhs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 31 | my @deps = $self->find_tmpvar_dependencies($rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 31 | my @vdeps = $self->find_var_dependencies($rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 31 | ▶ | push @deps, $rhs if @deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 31 | ▶ | if ($self->intermediate_inline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | ▶ | push @code, "\t;; TMP_VAR DEPS - $rhs, ". join (',', @deps) if @deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 0 | ▶ | push @code, "\t;; VAR DEPS - ". join (',', @vdeps) if @vdeps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 0 | foreach (sort @deps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 0 | my $tcode = $ast->{tmp_variables}->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | push @code, "\t;; $_ = $tcode"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 0 | push @code, "\t;; $line"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 31 | ▶ | if (scalar @deps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 6 | $ast->{tmp_stack_size} = max(scalar(@deps), $ast->{tmp_stack_size}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | ## it is assumed that the dependencies and intermediate code are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | #arranged in expected order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | # TODO: bits check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 6 | my $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 6 | my %tmpstack = map { $_ => 'VIC_STACK + ' . $counter++ } sort(@deps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 6 | foreach (sort @deps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 30 | my $tcode = $ast->{tmp_variables}->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 30 | my $result = $tmpstack{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 30 | ▶ | $result = uc $varname if $_ eq $rhs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 30 | ▶ | my @newcode = $self->generate_code_operations($tcode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | STACK => \%tmpstack, RESULT => $result) if $tcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 30 | ▶ | push @code, "\t;; $_ = $tcode" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 30 | ▶ | push @code, @newcode if @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | # no tmp-var dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 25 | ▶ | my $use_stack = $self->do_i_use_stack(@vdeps) unless scalar @deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 25 | ▶ | unless ($use_stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 25 | my @newcode = $self->generate_code_operations($tmp_code, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | RESULT => uc $varname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 25 | ▶ | push @code, @newcode if @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | # TODO: stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | XXX @vdeps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 57 | ▶ | my $nvar = $ast->{variables}->{$varname}->{name} || $varname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ast->{'variables'}{$varname}{'name'} || $varname
MC/DC0%0/2
$ast->{'variables'}{$varname}{'name'} || $varname
$ast->{'variables'}{$varname}{'name'}
$varname
Truth table33%1/3
A || B
A= $ast->{'variables'}{$varname}{'name'}B= $varname
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 57 | ▶ | if ($rhs =~ /HASH|ARRAY/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 2 | ▶ | if (exists $self->global_collections->{$rhs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 2 | $rhs = $self->global_collections->{$rhs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 57 | ▶ | if (exists $self->ast->{variables}->{$varname}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 57 | my $vhref = $self->ast->{variables}->{$varname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 57 | ▶ | if ($vhref->{type} eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | # send the string variable information to the method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | # and hope that the method knows how to handle it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | # this is useful for I/O methods and operator methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | # other methods should outright fail to use this and it should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | # make sense there.#TODO: make better error messages for that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 3 | $nvar = $vhref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 57 | my $method = $self->pic->validate_operator($op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 57 | ▶ | $self->parser->throw_error("Invalid operator '$op' in intermediate code") unless $self->pic->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 57 | my ($code, $funcs, $macros, $tables) = $self->pic->$method($nvar, $rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 57 | ▶ | return $self->parser->throw_error("Error in intermediate code '$line'") unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 57 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 57 | ▶ | push @code, $code if $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 57 | ▶ | $self->_update_funcs($funcs, $macros) if ($funcs or $macros); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$funcs or $macros
MC/DC50%1/2
$funcs or $macros
$funcs
$macros
Truth table66%2/3
A or B
A= $funcsB= $macros
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 57 | ▶ | $self->_update_tables($tables) if $tables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | return $self->parser->throw_error( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | "Error in intermediate code '$line': $varname doesn't exist"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 88 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 7 | ▶ | sub find_nearest_loop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_nearest_loop: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 7 | my ($self, $mapping, $child) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 7 | ▶ | return unless exists $mapping->{$child}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 7 | ▶ | if (exists $mapping->{$child}->{loop}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 7 | ▶ | return $child if $mapping->{$child}->{loop} eq '1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 3 | ▶ | return unless $mapping->{$child}->{parent}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 3 | return $self->find_nearest_loop($mapping, $mapping->{$child}->{parent}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 43 | ▶ | sub generate_code_blocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code_blocks: called CC=42 SCAR=48.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 43 | my ($self, $line, $block) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 43 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 43 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 43 | my $mapping = $ast->{block_mapping}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 43 | ▶ | my $mapped_block = $mapping->{$block}->{block} || $block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$mapping->{$block}{'block'} || $block
MC/DC0%0/2
$mapping->{$block}{'block'} || $block
$mapping->{$block}{'block'}
$block
Truth table33%1/3
A || B
A= $mapping->{$block}{'block'}B= $block
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 43 | my ($tag, $label, $child, $parent, $parent_label, $end_label) = split/::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 43 | ▶ | return if ($child eq $block or $child eq $mapped_block or $child eq $parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$child eq $block or $child eq $mapped_block or $child eq $parent
$child eq $block or $child eq $mapped_block
MC/DC0%0/3
$child eq $block or $child eq $mapped_block or $child eq $parent
$child eq $block
$child eq $mapped_block
$child eq $parent
Truth table25%1/4
A or B or C
A= $child eq $blockB= $child eq $mapped_blockC= $child eq $parent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 43 | ▶ | return if exists $ast->{generated_blocks}->{$child}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 43 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 43 | my @newcode = $self->generate_code($ast, $child); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 43 | ▶ | my @bindexes = indexes { $_ eq 'BREAK' } @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 43 | ▶ | my @cindexes = indexes { $_ eq 'CONTINUE' } @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 43 | ▶ | if ($child =~ /^(?:True|False)/ and @newcode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$child =~ /^(?:True|False)/ and @newcode
MC/DC50%1/2
$child =~ /^(?:True|False)/ and @newcode
$child =~ /^(?:True|False)/
@newcode
Truth table66%2/3
A and B
A= $child =~ /^(?:True|False)/B= @newcode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 16 | my $cond_end = "\tgoto $end_label;; go back to end of conditional\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | # handle break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 16 | ▶ | if (@bindexes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | #find top most parent loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 2 | my $el = $self->find_nearest_loop($mapping, $child); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 2 | ▶ | $el = $mapping->{$el}->{end_label} if $el; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 2 | my $break_end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 2 | ▶ | unless ($el) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | $break_end = "\t;; break from existing block since $child not part of any loop\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | $break_end .= "\tgoto $end_label;; break from the conditional\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 2 | $break_end = "\tgoto $el;; break from the conditional\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 2 | $newcode[$_] = $break_end foreach @bindexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | # handle continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 16 | ▶ | if (@cindexes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | #find top most parent loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 2 | my $sl = $self->find_nearest_loop($mapping, $child); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 2 | ▶ | $sl = $mapping->{$sl}->{start_label} if $sl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 2 | ▶ | my $cont_start = "\tgoto $sl;; go back to start of conditional\n" if $sl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 2 | ▶ | $cont_start = "\tnop ;; $child or $parent have no start_label" unless $sl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 2 | $newcode[$_] = $cont_start foreach @cindexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | # add the end _label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | # if the current block is a loop, the end label is the start label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 16 | ▶ | if (exists $mapping->{$child}->{loop} and $mapping->{$child}->{loop} eq '1') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $mapping->{$child}{"loop"} and $mapping->{$child}{"loop"} eq 1
MC/DC50%1/2
exists $mapping->{$child}{"loop"} and $mapping->{$child}{"loop"} eq 1
exists $mapping->{$child}{"loop"}
$mapping->{$child}{"loop"} eq 1
Truth table66%2/3
A and B
A= exists $mapping->{$child}{"loop"}B= $mapping->{$child}{"loop"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 4 | ▶ | my $slabel = $mapping->{$child}->{start_label} || $end_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$mapping->{$child}{'start_label'} || $end_label
MC/DC0%0/2
$mapping->{$child}{'start_label'} || $end_label
$mapping->{$child}{'start_label'}
$end_label
Truth table33%1/3
A || B
A= $mapping->{$child}{'start_label'}B= $end_label
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 4 | ▶ | my $start_code = "\tgoto $slabel ;; go back to start of conditional\n" if $slabel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 4 | ▶ | $start_code = $cond_end unless $start_code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 4 | push @newcode, $start_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 12 | push @newcode, $cond_end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 16 | push @newcode, ";;;; end of $label"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | # hack into the function list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 16 | $ast->{funcs}->{$label} = [@newcode]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | ▶ | } elsif ($child =~ /^(?:Action|ISR)/ and @newcode) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$child =~ /^(?:Action|ISR)/ and @newcode
MC/DC50%1/2
$child =~ /^(?:Action|ISR)/ and @newcode
$child =~ /^(?:Action|ISR)/
@newcode
Truth table66%2/3
A and B
A= $child =~ /^(?:Action|ISR)/B= @newcode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 11 | my $cond_end = "\tgoto $end_label ;; go back to end of block\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 11 | ▶ | if (@bindexes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | # we just break from the current block since we are not in any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | # sub-block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | my $break_end = "\tgoto $end_label ;; break from the block\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 0 | $newcode[$_] = $break_end foreach @bindexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 11 | ▶ | if (@cindexes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | # continue gets ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | my $cont_start = ";; continue is a NOP for $child block"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | $newcode[$_] = $cont_start foreach @cindexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 11 | push @newcode, $cond_end, ";;;; end of $label"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | # hack into the function list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 11 | $ast->{funcs}->{$label} = [@newcode]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | ▶ | } elsif ($child =~ /^Loop/ and @newcode) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$child =~ /^Loop/ and @newcode
MC/DC0%0/2
$child =~ /^Loop/ and @newcode
$child =~ /^Loop/
@newcode
Truth table33%1/3
A and B
A= $child =~ /^Loop/B= @newcode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 16 | my $cond_end = "\tgoto $end_label;; go back to end of block\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 16 | ▶ | if (@bindexes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | # we just break from the current block since we are not in any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | # sub-block and are in a Loop already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | my $break_end = "\tgoto $end_label ;; break from the block\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | $newcode[$_] = $break_end foreach @bindexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 16 | ▶ | if (@cindexes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | # continue goes to start of the loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 0 | my $cont_start = "\tgoto $label ;; go back to start of loop\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 0 | $newcode[$_] = $cont_start foreach @cindexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 16 | push @code, @newcode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 16 | push @code, "\tgoto $label ;;;; end of $label\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 16 | push @code, "$end_label:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 0 | ▶ | push @code, @newcode if @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 43 | ▶ | $ast->{generated_blocks}->{$child} = 1 if @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | # parent equals block if it is the topmost of the stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | # if the child is not a loop construct it will need a goto back to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | # the parent construct. if a child is a loop construct it will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | # already have a goto back to itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 43 | ▶ | if (defined $parent and exists $ast->{$parent} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $parent and exists $ast->{$parent} and ref $ast->{$parent} eq "ARRAY" and $parent ne $mapped_block
defined $parent and exists $ast->{$parent} and ref $ast->{$parent} eq "ARRAY"
defined $parent and exists $ast->{$parent}
MC/DC0%0/4
defined $parent and exists $ast->{$parent} and ref $ast->{$parent} eq "ARRAY" and $parent ne $mapped_block
defined $parent
exists $ast->{$parent}
ref $ast->{$parent} eq "ARRAY"
$parent ne $mapped_block
Truth table20%1/5
A and B and C and D
A= defined $parentB= exists $ast->{$parent}C= ref $ast->{$parent} eq "ARRAY"D= $parent ne $mapped_block
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | ref $ast->{$parent} eq 'ARRAY' and $parent ne $mapped_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | my ($ptag, $plabel) = split /::/, $ast->{$parent}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | ▶ | push @code, "\tgoto $plabel;; $plabel" if $plabel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 43 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 9 | ▶ | sub generate_code_conditionals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code_conditionals: called CC=34 SCAR=39.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 9 | my ($self, @condblocks) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 9 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 9 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 9 | my ($start_label, $end_label, $is_loop); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 9 | my $blockcount = scalar @condblocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 9 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 9 | foreach my $line (@condblocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 12 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 12 | my %hh = split /::/, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 12 | my $subj = $hh{SUBJ}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 12 | ▶ | $index++ if $hh{SUBCOND}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | # for multiple if-else-if-else we adjust the labels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | # for single ones we do not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 12 | ▶ | $start_label = "_start_conditional_$hh{COND}" unless defined $start_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 12 | ▶ | $is_loop = $hh{LOOP} unless defined $is_loop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 12 | ▶ | $end_label = $hh{END} unless defined $end_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | # we now modify the TRUE/FALSE/END labels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 12 | ▶ | if ($blockcount > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 4 | my $el = "$hh{END}_$index"; # new label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 4 | ▶ | $hh{FALSE} = $el if $hh{FALSE} eq $hh{END}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 4 | ▶ | $hh{TRUE} = $el if $hh{TRUE} eq $hh{END}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 4 | $hh{END} = $el; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 12 | ▶ | if ($subj =~ /^\d+?$/) { # if subject is a literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 1 | ▶ | push @code, "\t;; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | 1 | ▶ | if ($subj eq 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | # is false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | ▶ | push @code, "\tgoto $hh{FALSE}" if $hh{FALSE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | # is true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 1 | ▶ | push @code, "\tgoto $hh{TRUE}" if $hh{TRUE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 1 | ▶ | push @code, "\tgoto $hh{END}" if $hh{END}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 1 | ▶ | push @code, "$hh{END}:\n" if $hh{END}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | } elsif (exists $ast->{variables}->{$subj}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | ## we will never get here actually since we have eliminated this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | #possibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | XXX \%hh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | } elsif (exists $ast->{tmp_variables}->{$subj}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 11 | my $tmp_code = $ast->{tmp_variables}->{$subj}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 11 | my @deps = $self->find_tmpvar_dependencies($subj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 11 | my @vdeps = $self->find_var_dependencies($subj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 11 | ▶ | push @deps, $subj if @deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 11 | ▶ | if ($self->intermediate_inline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | ▶ | push @code, "\t;; TMP_VAR DEPS - $subj, ". join (',', @deps) if @deps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 0 | ▶ | push @code, "\t;; VAR DEPS - ". join (',', @vdeps) if @vdeps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | push @code, "\t;; $subj = $tmp_code"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 11 | ▶ | if (scalar @deps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 2 | $ast->{tmp_stack_size} = max(scalar(@deps), $ast->{tmp_stack_size}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | ## it is assumed that the dependencies and intermediate code are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | #arranged in expected order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | # TODO: bits check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 2 | my $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 2 | my %tmpstack = map { $_ => 'VIC_STACK + ' . $counter++ } sort(@deps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 2 | $counter = 0; # reset | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 2 | foreach (sort @deps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 6 | my $tcode = $ast->{tmp_variables}->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 6 | my %extra = (%hh, COUNTER => $counter++); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 6 | ▶ | $extra{RESULT} = $tmpstack{$_} if $_ ne $subj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 6 | ▶ | my @newcode = $self->generate_code_operations($tcode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | STACK => \%tmpstack, %extra) if $tcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | 6 | ▶ | push @code, @newcode if @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | # no tmp-var dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 9 | my $use_stack = $self->do_i_use_stack(@vdeps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 9 | ▶ | unless ($use_stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 9 | my @newcode = $self->generate_code_operations($tmp_code, %hh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 9 | ▶ | push @code, @newcode if @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 9 | ▶ | return $self->parser->throw_error("Error in intermediate code '$tmp_code'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | unless @newcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | # TODO: stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | XXX \%hh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 0 | return $self->parser->throw_error("Error in intermediate code '$line'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 9 | ▶ | unshift @code, "$start_label:" if defined $start_label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 9 | ▶ | push @code, "$end_label:" if defined $end_label and $blockcount > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $end_label and $blockcount > bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
MC/DC50%1/2
defined $end_label and $blockcount > bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
defined $end_label
$blockcount > bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
Truth table66%2/3
A and B
A= defined $end_labelB= $blockcount > bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 9 | return @code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 94 | ▶ | sub generate_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_code: called CC=26 SCAR=33.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | 94 | my ($self, $ast, $block_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | 94 | my @code = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | 94 | ▶ | return wantarray ? @code : [] unless defined $ast; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 94 | ▶ | return wantarray ? @code : [] unless exists $ast->{$block_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 93 | ▶ | $ast->{generated_blocks} = {} unless defined $ast->{generated_blocks}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 93 | push @code, ";;;; generated code for $block_name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 93 | my $blocks = $ast->{$block_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 93 | ▶ | while (@$blocks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 510 | my $line = shift @$blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | 510 | ▶ | next unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 507 | ▶ | if ($line =~ /^BLOCK::\w+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 43 | ▶ | my $blockparams = $ast->{block_mapping}->{$block_name}->{params} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ast->{'block_mapping'}{$block_name}{'params'} || []
MC/DC0%0/1
$ast->{'block_mapping'}{$block_name}{'params'} || []
$ast->{'block_mapping'}{$block_name}{'params'}
Truth table50%1/2
A
A= $ast->{'block_mapping'}{$block_name}{'params'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 43 | push @code, $self->generate_code_blocks($line, $block_name, $blockparams); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | } elsif ($line =~ /^INS::\w+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 136 | push @code, $self->generate_code_instruction($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | } elsif ($line =~ /^UNARY::\w+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 8 | push @code, $self->generate_code_unary_expr($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | } elsif ($line =~ /^SET::\w+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 83 | push @code, $self->generate_code_assign_expr($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | } elsif ($line =~ /^PARAM::(\w+)::(\w+)::(\w+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 5 | ▶ | if (exists $ast->{block_mapping}->{$block_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 5 | my $op = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | 5 | my $pblock = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 5 | my $pvar = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | 5 | my $mapping = $ast->{block_mapping}->{$pblock}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | 5 | my $param_idx = scalar @{$mapping->{params}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 5 | ▶ | my $paramvar = $mapping->{param_prefix} || lc($block_name . '_param'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$mapping->{'param_prefix'} || lc $block_name . '_param'
MC/DC0%0/2
$mapping->{'param_prefix'} || lc $block_name . '_param'
$mapping->{'param_prefix'}
lc $block_name . '_param'
Truth table33%1/3
A || B
A= $mapping->{'param_prefix'}B= lc $block_name . '_param'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | 5 | $paramvar .= $param_idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 5 | push @{$mapping->{params}}, $paramvar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | # map the param index back to the other mapping too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 5 | ▶ | if ($pblock ne $block_name and $mapping->{block} eq $block_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pblock ne $block_name and $mapping->{"block"} eq $block_name
MC/DC0%0/2
$pblock ne $block_name and $mapping->{"block"} eq $block_name
$pblock ne $block_name
$mapping->{"block"} eq $block_name
Truth table33%1/3
A and B
A= $pblock ne $block_nameB= $mapping->{"block"} eq $block_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 5 | my $mapping2 = $ast->{block_mapping}->{$block_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 5 | $mapping2->{params} = $mapping->{params}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 5 | my $pline = "SET::${op}::${pvar}::${paramvar}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | #YYY [$pblock, $pvar, $block_name, $param_idx, $pline, $paramvar]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 5 | push @code, $self->generate_code_assign_expr($pline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 0 | $self->parser->throw_error("Intermediate code '$line' in block " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | . "$block_name cannot be handled"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | } elsif ($line =~ /^LABEL::(\w+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 93 | my $lbl = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | 93 | ▶ | push @code, ";; $line" if $self->intermediate_inline; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 93 | ▶ | push @code, "$lbl:\n" if $lbl ne '_vic_simulator'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | } elsif ($line =~ /^COND::(\d+)::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 9 | my $cblock = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 9 | my @condblocks = ( $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 9 | for my $i (1 .. scalar @$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 17 | ▶ | next unless $blocks->[$i - 1] =~ /^COND::${cblock}::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | 3 | push @condblocks, $blocks->[$i - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | 3 | delete $blocks->[$i - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 9 | push @code, $self->generate_code_conditionals(reverse @condblocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | } elsif ($line =~ /^SIM::\w+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 130 | push @code, $self->generate_simulator_instruction($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 0 | $self->parser->throw_error("Intermediate code '$line' cannot be handled"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | 92 | ▶ | return wantarray ? @code : [@code]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 32 | ▶ | sub final { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
final: called CC=40 SCAR=37.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 32 | my ($self, $got) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | 32 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 32 | ▶ | return $self->parser->throw_error("Missing '}'") if scalar @{$ast->{block_stack}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | 32 | ▶ | return $self->parser->throw_error("Main not defined") unless defined $ast->{Main}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | # generate main code first so that any addition to functions, macros, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | # variables during generation can be handled after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 32 | my @main_code = $self->generate_code($ast, 'Main'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 31 | push @main_code, "_end_start:\n", "\tgoto \$\t;;;; end of Main"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 31 | my $main_code = join("\n", @main_code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | # variables are part of macros and need to go first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 31 | my $variables = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 31 | my $vhref = $ast->{variables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 31 | ▶ | $variables .= "GLOBAL_VAR_UDATA udata\n" if keys %$vhref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 31 | my @global_vars = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 31 | my @tables = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 31 | my @init_vars = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 31 | foreach my $var (sort(keys %$vhref)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 42 | my $name = $vhref->{$var}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 42 | ▶ | my $typ = $vhref->{$var}->{type} || 'byte'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$vhref->{$var}{'type'} || 'byte'
MC/DC0%0/1
$vhref->{$var}{'type'} || 'byte'
$vhref->{$var}{'type'}
Truth table50%1/2
A
A= $vhref->{$var}{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 42 | my $data = $vhref->{$var}->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 42 | ▶ | my $label = $vhref->{$var}->{label} || $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$vhref->{$var}{'label'} || $name
MC/DC0%0/2
$vhref->{$var}{'label'} || $name
$vhref->{$var}{'label'}
$name
Truth table66%2/3
A || B
A= $vhref->{$var}{'label'}B= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 42 | my $szvar = $vhref->{$var}->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 42 | ▶ | if ($typ eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | ##this may need to be stored in a different location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 2 | ▶ | $data = '' unless defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | ## different PICs may have different string handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 2 | my ($scode, $szdecl)= $self->pic->store_string($data, $label, $szvar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | 2 | push @tables, $scode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 2 | ▶ | $variables .= $szdecl if $szdecl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | } elsif ($typ eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 0 | ▶ | $data = [] unless defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 0 | push @init_vars, $self->pic->store_array($data, $label, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | scalar(@$data), $szvar); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | } elsif ($typ eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 1 | ▶ | $data = {} unless defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 1 | ▶ | next unless defined $data->{TABLE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 1 | my $table = $data->{TABLE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | 1 | my ($code, $szdecl) = $self->pic->store_table($table, $label, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | scalar(@$table), $szvar); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 1 | push @tables, $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 1 | ▶ | push @init_vars, $szdecl if $szdecl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | } else {# $typ == 'byte' or any other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | # should we care about scope ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 39 | $variables .= "$name res $vhref->{$var}->{size}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 39 | ▶ | if (($vhref->{$var}->{scope} eq 'global') or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$vhref->{$var}{"scope"} eq "global" or $ast->{"code_config"}{"variable"}{"export"}
MC/DC100%2/2
$vhref->{$var}{"scope"} eq "global" or $ast->{"code_config"}{"variable"}{"export"}
$vhref->{$var}{"scope"} eq "global"
$ast->{"code_config"}{"variable"}{"export"}
Truth table100%3/3
A or B
A= $vhref->{$var}{"scope"} eq "global"B= $ast->{"code_config"}{"variable"}{"export"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | ($ast->{code_config}->{variable}->{export})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 20 | push @global_vars, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 31 | ▶ | if ($ast->{tmp_stack_size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | 3 | $variables .= "VIC_STACK res $ast->{tmp_stack_size}\t;; temporary stack\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 31 | ▶ | if (scalar @global_vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | # export the variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | 5 | $variables .= "\tglobal ". join (", ", @global_vars) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | 31 | ▶ | if (scalar @init_vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 1 | $variables .= "\nGLOBAL_VAR_IDATA idata\n"; # initialized variables | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 1 | $variables .= join("\n", @init_vars); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 31 | my $macros = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 31 | foreach my $mac (sort(keys %{$ast->{macros}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 80 | ▶ | $variables .= "\n" . $ast->{macros}->{$mac} . "\n", next if $mac =~ /_var$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | 55 | $macros .= $ast->{macros}->{$mac}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | 55 | $macros .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 31 | my $isr_checks = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 31 | my $isr_code = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 31 | my $funcs = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 31 | foreach my $fn (sort(keys %{$ast->{funcs}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | 45 | my $fn_val = $ast->{funcs}->{$fn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | # the default ISR checks to be done first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | 45 | ▶ | if ($fn =~ /^isr_\w+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | 5 | ▶ | if (ref $fn_val eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 0 | $isr_checks .= join("\n", @$fn_val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | 5 | $isr_checks .= $fn_val . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | # the user ISR code to be handled next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | } elsif ($fn =~ /^_isr_\w+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 5 | ▶ | if (ref $fn_val eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | 5 | $isr_code .= join("\n", @$fn_val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | 0 | $isr_code .= $fn_val . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 35 | ▶ | if (ref $fn_val eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 22 | $funcs .= join("\n", @$fn_val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | 13 | $funcs .= "$fn:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | 13 | ▶ | $funcs .= $fn_val unless ref $fn_val eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 35 | $funcs .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 31 | foreach my $tbl (@{$ast->{tables}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 5 | my $dt = $tbl->{bytes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | 5 | my $dn = $tbl->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | 31 | ▶ | $funcs .= join ("\n", @tables) if scalar @tables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 31 | $funcs .= $self->pic->store_bytes($ast->{tables}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 31 | ▶ | if (length $isr_code) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 5 | my $isr_entry = $self->pic->isr_entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | 5 | my $isr_exit = $self->pic->isr_exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 5 | my $isr_var = $self->pic->isr_var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | 5 | $isr_checks .= "\tgoto _isr_exit\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | 5 | $isr_code = "\tgoto _start\n$isr_entry\n$isr_checks\n$isr_code\n$isr_exit\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 5 | $variables .= "\n$isr_var\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 31 | my ($sim_include, $sim_setup_code) = ('', ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | # we need to generate simulator code if either the Simulator block is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | # present or if any asserts are present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | 31 | ▶ | if ($self->simulator and not $self->simulator->disable and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$self->simulator and not $self->simulator->disable and $ast->{"Simulator"} || $ast->{"asserts"}
$self->simulator and not $self->simulator->disable
$ast->{"Simulator"} or $ast->{"asserts"}
MC/DC25%1/4
$self->simulator and not $self->simulator->disable and $ast->{"Simulator"} || $ast->{"asserts"}
$self->simulator
not $self->simulator->disable
$ast->{"Simulator"}
$ast->{"asserts"}
Truth table40%2/5
A and not(B) and C or D
A= $self->simulatorB= not $self->simulator->disableC= $ast->{"Simulator"}D= $ast->{"asserts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | ($ast->{Simulator} or $ast->{asserts})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 19 | my $stype = $self->simulator->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | 19 | $sim_include .= ";;;; generated code for $stype header file\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 19 | $sim_include .= '#include <' . $self->simulator->include .">\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | 19 | my @setup_code = $self->generate_code($ast, 'Simulator'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | 19 | my $init_code = $self->simulator->init_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | 19 | ▶ | $sim_setup_code .= $init_code . "\n" if defined $init_code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | 19 | ▶ | $sim_setup_code .= join("\n", @setup_code) if scalar @setup_code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | 19 | ▶ | if ($self->simulator->should_autorun) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 12 | $sim_setup_code .= $self->simulator->get_autorun_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | # final get of the chip config in case it has been modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 31 | $self->ast->{chip_config} = $self->pic->get_chip_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 31 | my $pic = <<"..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | ;;;; generated code for PIC header file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | #include <$ast->{include}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | $sim_include | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | ;;;; generated code for variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | $variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | ;;;; generated code for macros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | $macros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | $ast->{chip_config} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | \torg $ast->{org} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | $sim_setup_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | $isr_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | $main_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | ;;;; generated code for functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | $funcs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | ;;;; generated code for end-of-file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | \tend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 31 | return $pic; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 33 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | VIC::Receiver | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | The Pegex::Receiver class for handling the grammar. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | INTERNAL CLASS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | Vikas N Kumar <vikas@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | Copyright (c) 2014. Vikas N Kumar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | See http://www.perl.com/perl/misc/Artistic.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||