File Coverage

blib/lib/SystemC/Vregs/Subclass.pm
Criterion Covered Total %
statement 39 94 41.4
branch 7 40 17.5
condition 0 12 0.0
subroutine 8 15 53.3
pod 3 11 27.2
total 57 172 33.1


line stmt bran cond sub pod time code
1             # See copyright, etc in below POD section.
2             ######################################################################
3              
4             package SystemC::Vregs::Subclass;
5              
6 3     3   14 use strict;use vars qw($Errors $VERSION);
  3     3   7  
  3         108  
  3         15  
  3         4  
  3         186  
7 3     3   16 use Carp;
  3         3  
  3         6967  
8             $VERSION = '1.470';
9              
10             $Errors = 0;
11              
12             sub new {
13 53     53 1 69 my $class = shift;
14 53         388 my $self = {@_};
15 53 50       144 defined $self->{name} or croak ("No name=> parameter passed");
16 53         120 bless $self, $class;
17 53         119 return $self;
18             }
19              
20             sub attributes_parse {
21 48     48 0 56 my $self = shift;
22 48         62 my $flags = shift;
23              
24 48         78 $flags = " $flags ";
25 48         136 $self->{attributes}{$1} = $2 while ($flags =~ s/\s-([a-zA-Z][a-zA-Z0-9_]*)=([^ \t]*)\s/ /);
26 48         152 $self->{attributes}{$1} = 1 while ($flags =~ s/\s-([a-zA-Z][a-zA-Z0-9_]*)\s/ /);
27 48 50       1222 ($flags =~ /^\s*$/) or $self->warn ("Unparsable attributes setting: '$flags'");
28             }
29              
30             sub attributes_string {
31 0     0 0 0 my $self = shift;
32 0         0 my $text = "";
33 0         0 foreach my $var (sort keys %{$self->{attributes}}) {
  0         0  
34 0         0 my $val = $self->{attributes}{$var};
35 0 0       0 $text .= " " if $text ne "";
36 0 0       0 if ($val eq '1') {
37 0         0 $text .= "-$var";
38             } else {
39 0         0 $text .= "-$var=$val";
40             }
41             }
42 0         0 return $text;
43             }
44             sub copy_attributes_from {
45 16     16 0 18 my $self = shift;
46 16 50       34 my $from = shift or return;
47              
48 16         16 foreach my $key (keys %{$from->{attributes}}) {
  16         60  
49 0 0       0 if (!defined $self->{attributes}{$key}) {
50 0         0 $self->{attributes}{$key} = $from->{attributes}{$key}
51             }
52             }
53             }
54              
55             sub at_text {
56 0     0 0 0 my $self = shift;
57 0 0       0 if (ref $_[0]) { $self = shift; } # Use the class provided, if passed
  0         0  
58              
59 0         0 my $at = "";
60 0 0       0 if ($self) {
61 0   0     0 my $typeref = $self->{class} || $self->{typeref};
62 0 0       0 if ($typeref) {
63 0   0     0 $at = ($typeref->{name}||$typeref->{Register}||$typeref->{at}||"");
64 0         0 $at .= "::";
65             }
66 0   0     0 $at .= ($self->{name}||$self->{Register}||$self->{Mnemonic}||$self->{at}||"");
67             # If the name has non-printing or strange chars, quote it and show them.
68 0 0       0 if ($at !~ /^[\w\-\:]+$/) {
69 0         0 $at =~ s/(.)/substchar($1)/egs;
  0         0  
70 0         0 $at = "'". $at ."'";
71             }
72 0         0 $at .= ": ";
73             }
74              
75 0 0 0     0 $at .= ($self->{at}||"").":" if $SystemC::Vregs::Debug;
76 0         0 return $at;
77             }
78              
79             sub substchar {
80 0     0 0 0 my $c = shift;
81 0         0 my $n = ord $c;
82 0 0 0     0 if ($n >= 33 && $n <= 126) {
83 0 0       0 return "\\\'" if ($c eq "'");
84 0 0       0 return "\\\\" if ($c eq "\\");
85 0         0 return $c;
86             }
87 0         0 return sprintf("\\x%02x", $n);
88             }
89              
90             sub info {
91 0     0 0 0 my $self = shift;
92 0 0       0 if (ref $_[0]) { $self = shift; } # Use the class provided, if passed
  0         0  
93              
94             # Make a warning based on the bit being processed
95 0         0 my $at = at_text($self);
96 0         0 my $atblank = " " x length($at);
97 0         0 my $text = join('',@_);
98 0         0 $text =~ s/\n(.)/\n-Info: $atblank$1/g;
99 0         0 CORE::warn "-Info: $at$text";
100             }
101              
102             sub warn {
103 0     0 1 0 my $self = shift;
104 0 0       0 if (ref $_[0]) { $self = shift; } # Use the class provided, if passed
  0         0  
105              
106             # Make a warning based on the bit being processed
107 0         0 my $at = at_text($self);
108 0         0 my $atblank = " " x length($at);
109 0         0 my $text = join('',@_);
110 0         0 $text =~ s/\n(.)/\n%Warning: $atblank$1/g;
111 0         0 CORE::warn "%Warning: $at$text";
112 0         0 $Errors++;
113             }
114              
115             sub exit_if_error {
116 0 0   0 1 0 exit(10) if $Errors;
117             }
118              
119             sub clean_sentence {
120 51     51 0 60 my $self = shift;
121 51         62 my $field = shift;
122              
123             # Make it reasonably small, or the first sentence
124 51         65 my $out = $field;
125 51         89 $out =~ s/^\s+//g;
126 51         79 $out =~ s/\s*\bthis bit\b//g;
127 51         71 $out =~ s/[\"\'\`]+/ /g;
128 51         226 $out =~ s/\s+/ /g;
129 51         97 $out = substr $out,0,80;
130 51 100       164 if ($out =~ /[.,;]/) {
131 3         12 $out =~ s/\..*$//;
132             }
133 51         90 $out = ucfirst $out;
134 51         127 $out =~ s/\s+$//;
135              
136 51         202 return $out;
137             }
138              
139             END {
140 3 50   3   27 $? = 10 if $Errors;
141 3 50       71 CORE::warn "Exiting due to errors\n" if $?;
142             }
143              
144 0     0 0   sub check {}
145              
146             ######################################################################
147             #### Package return
148             1;
149             __END__