line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SPVM::Builder::CompileInfo; |
2
|
|
|
|
|
|
|
|
3
|
279
|
|
|
279
|
|
2009
|
use strict; |
|
279
|
|
|
|
|
625
|
|
|
279
|
|
|
|
|
8378
|
|
4
|
279
|
|
|
279
|
|
1553
|
use warnings; |
|
279
|
|
|
|
|
611
|
|
|
279
|
|
|
|
|
6407
|
|
5
|
279
|
|
|
279
|
|
1393
|
use Config; |
|
279
|
|
|
|
|
642
|
|
|
279
|
|
|
|
|
11076
|
|
6
|
279
|
|
|
279
|
|
1787
|
use Carp 'confess'; |
|
279
|
|
|
|
|
673
|
|
|
279
|
|
|
|
|
14458
|
|
7
|
279
|
|
|
279
|
|
1905
|
use File::Basename 'dirname'; |
|
279
|
|
|
|
|
707
|
|
|
279
|
|
|
|
|
217231
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Fields |
10
|
|
|
|
|
|
|
sub source_file { |
11
|
678
|
|
|
678
|
1
|
1629
|
my $self = shift; |
12
|
678
|
50
|
|
|
|
2113
|
if (@_) { |
13
|
0
|
|
|
|
|
0
|
$self->{source_file} = $_[0]; |
14
|
0
|
|
|
|
|
0
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
else { |
17
|
678
|
|
|
|
|
2122
|
return $self->{source_file}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub output_file { |
22
|
447
|
|
|
447
|
1
|
2292
|
my $self = shift; |
23
|
447
|
50
|
|
|
|
3047
|
if (@_) { |
24
|
0
|
|
|
|
|
0
|
$self->{output_file} = $_[0]; |
25
|
0
|
|
|
|
|
0
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
447
|
|
|
|
|
2308
|
return $self->{output_file}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub config { |
33
|
1017
|
|
|
1017
|
1
|
3313
|
my $self = shift; |
34
|
1017
|
50
|
|
|
|
3366
|
if (@_) { |
35
|
0
|
|
|
|
|
0
|
$self->{config} = $_[0]; |
36
|
0
|
|
|
|
|
0
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
1017
|
|
|
|
|
3758
|
return $self->{config}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Class methods |
44
|
|
|
|
|
|
|
sub new { |
45
|
468
|
|
|
468
|
1
|
1873
|
my $class = shift; |
46
|
|
|
|
|
|
|
|
47
|
468
|
|
|
|
|
2790
|
my $self = {@_}; |
48
|
|
|
|
|
|
|
|
49
|
468
|
|
|
|
|
1626
|
bless $self, $class; |
50
|
|
|
|
|
|
|
|
51
|
468
|
|
|
|
|
1590
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Instance Methods |
55
|
|
|
|
|
|
|
sub create_compile_command { |
56
|
339
|
|
|
339
|
1
|
1429
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
339
|
|
|
|
|
2140
|
my $config = $self->config; |
59
|
|
|
|
|
|
|
|
60
|
339
|
|
|
|
|
2784
|
my $cc = $config->cc; |
61
|
339
|
|
|
|
|
2341
|
my $output_file = $self->output_file; |
62
|
339
|
|
|
|
|
1456
|
my $source_file = $self->source_file; |
63
|
|
|
|
|
|
|
|
64
|
339
|
|
|
|
|
2477
|
my $compile_command_args = $self->create_compile_command_args; |
65
|
|
|
|
|
|
|
|
66
|
339
|
|
|
|
|
3213
|
my @compile_command = ($cc, '-c', '-o', $output_file, @$compile_command_args, $source_file); |
67
|
|
|
|
|
|
|
|
68
|
339
|
|
|
|
|
1955
|
return \@compile_command; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub create_compile_command_args { |
72
|
339
|
|
|
339
|
1
|
1269
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
339
|
|
|
|
|
1206
|
my $config = $self->config; |
75
|
|
|
|
|
|
|
|
76
|
339
|
|
|
|
|
1103
|
my @compile_command_args; |
77
|
|
|
|
|
|
|
|
78
|
339
|
|
|
|
|
2358
|
my $std = $config->std; |
79
|
339
|
50
|
|
|
|
1983
|
if (defined $std) { |
80
|
339
|
|
|
|
|
1840
|
push @compile_command_args, "-std=$std"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
339
|
|
|
|
|
2107
|
my $optimize = $config->optimize; |
84
|
339
|
50
|
|
|
|
1450
|
if (defined $optimize) { |
85
|
339
|
|
|
|
|
2311
|
push @compile_command_args, split(/ +/, $optimize); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
339
|
|
|
|
|
1046
|
push @compile_command_args, @{$config->ccflags}; |
|
339
|
|
|
|
|
1744
|
|
89
|
|
|
|
|
|
|
|
90
|
339
|
|
|
|
|
894
|
push @compile_command_args, @{$config->thread_ccflags}; |
|
339
|
|
|
|
|
1925
|
|
91
|
|
|
|
|
|
|
|
92
|
339
|
|
|
|
|
2030
|
my $output_type = $config->output_type; |
93
|
|
|
|
|
|
|
|
94
|
339
|
50
|
|
|
|
1739
|
if ($output_type eq 'dynamic_lib') { |
95
|
339
|
|
|
|
|
821
|
push @compile_command_args, @{$config->dynamic_lib_ccflags}; |
|
339
|
|
|
|
|
1442
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# include directories |
99
|
|
|
|
|
|
|
{ |
100
|
339
|
|
|
|
|
780
|
my @all_include_dirs; |
|
339
|
|
|
|
|
744
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# SPVM core native directory |
103
|
339
|
|
|
|
|
1572
|
my $spvm_core_include_dir = $config->spvm_core_include_dir; |
104
|
339
|
|
|
|
|
1456
|
push @all_include_dirs, $spvm_core_include_dir; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Native include directory |
107
|
339
|
|
|
|
|
1823
|
my $native_include_dir = $config->native_include_dir; |
108
|
339
|
100
|
|
|
|
1551
|
if (defined $native_include_dir) { |
109
|
37
|
|
|
|
|
128
|
push @all_include_dirs, $native_include_dir; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Resource include directories |
113
|
339
|
|
|
|
|
3106
|
my $disable_resource = $config->disable_resource; |
114
|
339
|
100
|
|
|
|
3817
|
unless ($disable_resource) { |
115
|
318
|
|
|
|
|
3014
|
my $resource_names = $config->get_resource_names; |
116
|
318
|
|
|
|
|
3172
|
for my $resource_name (@$resource_names) { |
117
|
8
|
|
|
|
|
56
|
my $resource = $config->get_resource($resource_name); |
118
|
8
|
|
|
|
|
35
|
my $config = $resource->config; |
119
|
8
|
|
|
|
|
29
|
my $resource_include_dir = $config->native_include_dir; |
120
|
8
|
50
|
|
|
|
28
|
if (defined $resource_include_dir) { |
121
|
8
|
|
|
|
|
38
|
push @all_include_dirs, $resource_include_dir; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# include directories |
127
|
339
|
|
|
|
|
2159
|
my $include_dirs = $config->include_dirs; |
128
|
339
|
|
|
|
|
2082
|
push @all_include_dirs, @$include_dirs; |
129
|
|
|
|
|
|
|
|
130
|
339
|
|
|
|
|
2112
|
my @all_include_dirs_args = map { "-I$_" } @all_include_dirs; |
|
418
|
|
|
|
|
3588
|
|
131
|
|
|
|
|
|
|
|
132
|
339
|
|
|
|
|
1886
|
push @compile_command_args, @all_include_dirs_args; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
339
|
|
|
|
|
1765
|
return \@compile_command_args; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub to_cmd { |
139
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $compile_command = $self->create_compile_command; |
142
|
0
|
|
|
|
|
|
my $compile_command_string = "@$compile_command"; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $compile_command_string; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 Name |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
SPVM::Builder::CompileInfo - Compilation Information |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 Description |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The SPVM::Builder::CompileInfo class has methods to manipulate compilation information. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 Fields |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 config |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $config = $compile_info->config; |
162
|
|
|
|
|
|
|
$compile_info->config($config); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Gets and sets the C field. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This is a L object used to compile the source file. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 source_file |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $source_file = $compile_info->source_file; |
171
|
|
|
|
|
|
|
$compile_info->source_file($source_file); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Gets and sets the C field. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This field is a source file. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 output_file |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $output_file = $compile_info->output_file; |
180
|
|
|
|
|
|
|
$compile_info->output_file($output_file); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Gets and sets the C field. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This field is an output file. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 Class Methods |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 new |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my $compile_info = SPVM::Builder::CompileInfo->new(%fields); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Creates a new L object with L"Fields">. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Default Field Values: |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
If a field is not defined, the field is set to the following default value. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over 2 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * L"source_file"> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
undef |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * L"output_file"> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
undef |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * L"config"> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
undef |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 Instance Methods |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 create_compile_command |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
my $compile_command = $compile_info->create_compile_command; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Creates the compilation command, and returns it. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The return value is an array reference. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
The following one is an example of the return value. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
[qw(cc -o foo.o -c -O2 -Ipath/include foo.c)] |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 create_compile_command_args |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
my $config_args = $compile_info->create_compile_command_args; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Creates the parts of the arguments of the compilation command from the information of the L"config"> field, and returns it. The return value is an array reference. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
The C<-c> option, the C<-o> option and the source file name are not contained. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
The following one is an example of the return value. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
[qw(-O2 -Ipath/include)] |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 to_cmd |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
my $compile_command_string = $compile_info->to_cmd; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Calls the L method and joins all elements of the returned array reference with a space, and returns it. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
The following one is an example of the return value. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
"cc -c -o foo.o -O2 -Ipath/include foo.c" |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 Copyright & License |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Copyright (c) 2023 Yuki Kimoto |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
MIT License |