VIC/PIC/Functions/CodeGen.pm

filter: Statementstmt 98.4% 65 / 66 Branchbran 68.9% 40 / 58 Conditioncond 44.4% 8 / 18 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 73.8% 127 / 172 SCAR 38.5
CC
36
Cov
80%
update_code_config
20.6
validate
13.2
address_bits
4.5
CRAP 47.0
« VIC/PIC/Functions/ISR.pm ↑ Summary VIC/PIC/Any.pm »
1 package VIC::PIC::Functions::CodeGen;
2 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 our $VERSION = '0.29';
5 31 $VERSION = eval $VERSION;
6 31 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 31 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # default
11 31 has org => (is => 'ro', default => 0);
12 has code_config => (is => 'rw', default => sub {
13 {
14 51 ▶ debounce => {
Subroutine __ANON__: called CC=1 SCAR=0.0
15 count => 5,
16 delay => 1000, # in microseconds
17 },
18 adc => {
19 right_justify => 1,
20 vref => 0,
21 internal => 0,
22 },
23 variable => {
24 bits => 8, # bits. same as register_size
25 export => 0, # do not export variables
26 },
27 string => {
28 size => 32, # character allocation of null strings
29 },
30 uart => {
31 baud => 9600, # baud rate
32 bit9 => 0, # allow 9 bits
33 },
34 usart => {
35 baud => 9600, # baud rate
36 bit9 => 0, # allow 9 bits
37 },
38 }
39 31 });
40  
41 sub validate {
42 227 ▶ my ($self, $var) = @_;
Subroutine validate: called CC=12 SCAR=25.8
Pod undocumented
43 227 ▶ return undef unless defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 0 227 227
44 227 ▶ return 0 if $var =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $var =~ /^\d+$/ 11 216 227
45 216 ▶ return 0 unless $self->doesrole('Chip');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesrole("Chip") 0 216 216
46 216 ▶ return 1 if exists $self->pins->{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->pins->{$var} 141 75 216
47 75 ▶ return 1 if exists $self->registers->{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->registers->{$var} 45 30 75
48 30 ▶ return 1 if ($self->doesrole('Timer', 1) and exists $self->timer_pins->{$var});
Branch: 1 branch
BranchTrueFalseTotal
if $self->doesrole("Timer", 1) and exists $self->timer_pins->{$var} 0 30 30
Condition33%1/3
$self->doesrole("Timer", 1) and exists $self->timer_pins->{$var}
!ll&&!rl&&r
0300
MC/DC0%0/2
$self->doesrole("Timer", 1) and exists $self->timer_pins->{$var}
$self->doesrole("Timer", 1) exists $self->timer_pins->{$var}
Truth table33%1/3
A and B
A= $self->doesrole("Timer", 1)B= exists $self->timer_pins->{$var}
ABresult
0X0
100
111
49 30 ▶ return 1 if ($self->doesrole('Timer', 1) and exists $self->wdt_prescaler->{$var});
Branch: 1 branch
BranchTrueFalseTotal
if $self->doesrole("Timer", 1) and exists $self->wdt_prescaler->{$var} 1 29 30
Condition66%2/3
$self->doesrole("Timer", 1) and exists $self->wdt_prescaler->{$var}
!ll&&!rl&&r
0291
MC/DC50%1/2
$self->doesrole("Timer", 1) and exists $self->wdt_prescaler->{$var}
$self->doesrole("Timer", 1) exists $self->wdt_prescaler->{$var}
Truth table66%2/3
A and B
A= $self->doesrole("Timer", 1)B= exists $self->wdt_prescaler->{$var}
ABresult
0X0
100
111
50 29 ▶ return 1 if ($self->doesrole('USART', 1) and exists $self->usart_pins->{$var});
Branch: 1 branch
BranchTrueFalseTotal
if $self->doesrole("USART", 1) and exists $self->usart_pins->{$var} 20 9 29
Condition66%2/3
$self->doesrole("USART", 1) and exists $self->usart_pins->{$var}
!ll&&!rl&&r
0920
MC/DC50%1/2
$self->doesrole("USART", 1) and exists $self->usart_pins->{$var}
$self->doesrole("USART", 1) exists $self->usart_pins->{$var}
Truth table66%2/3
A and B
A= $self->doesrole("USART", 1)B= exists $self->usart_pins->{$var}
ABresult
0X0
100
111
51 9 return 0;
52 }
53  
54 sub validate_operator {
55 133 ▶ my ($self, $op) = @_;
Subroutine validate_operator: called CC=3 SCAR=11.7
Pod undocumented
56 133 ▶ my $vop = "op_$op" if $op =~ /^
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ /^ LE | GE | GT | LT | EQ | NE | ADD | SUB | MUL | DIV | MOD | BXOR | BOR | BAND | AND | OR | SHL | SHR | ASSIGN | INC | DEC | NOT | COMP | TBLIDX | ARRIDX | STRIDX /x 133 0 133
57 LE | GE | GT | LT | EQ | NE |
58 ADD | SUB | MUL | DIV | MOD |
59 BXOR | BOR | BAND | AND | OR | SHL | SHR |
60 ASSIGN | INC | DEC | NOT | COMP |
61 TBLIDX | ARRIDX | STRIDX
62 /x;
63 133 ▶ return lc $vop if defined $vop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $vop 133 0 133
64 }
65  
66 sub validate_modifier_operator {
67 16 ▶ my ($self, $mod) = @_;
Subroutine validate_modifier_operator: called CC=3 SCAR=11.0
Pod undocumented
68 16 ▶ my $vmod = "op_$mod" if $mod =~ /^
Branch: 1 branch
BranchTrueFalseTotal
if $mod =~ /^ SQRT | HIGH | LOW /x 4 12 16
69 SQRT | HIGH | LOW
70 /x;
71 16 ▶ return lc $vmod if defined $vmod;
Branch: 1 branch
BranchTrueFalseTotal
if defined $vmod 4 12 16
72 }
73  
74 sub update_code_config {
75 20 ▶ my ($self, $grp, $key, $val) = @_;
Subroutine update_code_config: called CC=15 SCAR=30.2
Pod undocumented
76 20 ▶ return unless $self->doesrole('CodeGen');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesrole("CodeGen") 0 20 20
77 20 ▶ return unless defined $grp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $grp 0 20 20
78 20 $grp = lc $grp; # force lower case in case of usage for things like SPI/UART/I2C
79 20 ▶ $self->code_config->{$grp} = {} unless exists $self->code_config->{$grp};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->code_config->{$grp} 3 17 20
80 20 my $grpref = $self->code_config->{$grp};
81 20 ▶ if ($key eq 'bits') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "bits") 2 18 20
82 2 ▶ $val = 8 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 2 2
83 2 ▶ $val = 8 if $val <= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $val <= 8 2 0 2
84 2 ▶ $val = 16 if ($val > 8 and $val <= 16);
Branch: 1 branch
BranchTrueFalseTotal
if $val > 8 and $val <= 16 0 2 2
Condition33%1/3
$val > 8 and $val <= 16
!ll&&!rl&&r
200
MC/DC0%0/2
$val > 8 and $val <= 16
$val > 8 $val <= 16
Truth table33%1/3
A and B
A= $val > 8B= $val <= 16
ABresult
0X0
100
111
85 2 ▶ $val = 32 if ($val > 16 and $val <= 32);
Branch: 1 branch
BranchTrueFalseTotal
if $val > 16 and $val <= 32 0 2 2
Condition33%1/3
$val > 16 and $val <= 32
!ll&&!rl&&r
200
MC/DC0%0/2
$val > 16 and $val <= 32
$val > 16 $val <= 32
Truth table33%1/3
A and B
A= $val > 16B= $val <= 32
ABresult
0X0
100
111
86 2 ▶ carp "$val-bits is not supported. Maximum supported size is 64-bit"
Branch: 1 branch
BranchTrueFalseTotal
if $val > 64 0 2 2
87 if $val > 64;
88 2 ▶ $val = 64 if $val > 32;
Branch: 1 branch
BranchTrueFalseTotal
if $val > 32 0 2 2
89 }
90 20 ▶ $val = 1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 6 14 20
91 20 ▶ if (ref $grpref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $grpref eq 'HASH') { } 20 0 20
92 20 $grpref->{$key} = $val;
93 } else {
94 0 $self->code_config->{$grp} = { $key => $val };
95 }
96 20 1;
97 }
98  
99 sub address_bits {
100 257 ▶ my ($self, $varname) = @_;
Subroutine address_bits: called CC=4 SCAR=15.0
Pod undocumented
101 257 ▶ return unless $self->doesrole('CodeGen');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesrole("CodeGen") 0 257 257
102 257 my $bits = $self->code_config->{variable}->{bits};
103 257 ▶ return $bits unless $varname;
Branch: 1 branch
BranchTrueFalseTotal
unless $varname 0 257 257
104 257 ▶ $bits = $self->code_config->{lc $varname}->{bits} || $bits;
Condition33%1/3
$self->code_config->{lc $varname}{'bits'} || $bits
l!l&&r!l&&!r
02570
MC/DC0%0/2
$self->code_config->{lc $varname}{'bits'} || $bits
$self->code_config->{lc $varname}{'bits'} $bits
Truth table33%1/3
A || B
A= $self->code_config->{lc $varname}{'bits'}B= $bits
ABresult
1X1
011
000
105 257 return $bits;
106 }
107  
108 sub is_variable {
109 5 ▶ my ($self, $varname) = @_;
Subroutine is_variable: called CC=4 SCAR=14.1
Pod undocumented
110 5 ▶ return unless $varname;
Branch: 1 branch
BranchTrueFalseTotal
unless $varname 0 5 5
111 5 ▶ return unless $self->doesrole('CodeGen');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesrole("CodeGen") 0 5 5
112 5 ▶ return 1 if defined $self->code_config->{lc $varname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->code_config->{lc $varname} 4 1 5
113 1 return 0;
114 }
115  
116  
117 31 1;
118 __END__
« VIC/PIC/Functions/ISR.pm ↑ Summary VIC/PIC/Any.pm »