line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Upp::Reader;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30866
|
use 5.012004;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
188
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter;
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export
|
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead.
|
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants.
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Upp::Reader ':all';
|
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
17
|
|
|
|
|
|
|
# will save memory.
|
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
) ] );
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw(
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
);
|
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1940
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$VERSION = '0.1';
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub remove_escapes {
|
33
|
0
|
|
|
0
|
0
|
|
my $s = shift;
|
34
|
0
|
|
|
|
|
|
$s =~ s/\\(.)/$1/g;
|
35
|
0
|
|
|
|
|
|
return $s;
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub read_upp {
|
39
|
0
|
|
|
0
|
1
|
|
my $filename = shift;
|
40
|
0
|
0
|
|
|
|
|
open my $in, $filename or die "could not open upp file";
|
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $content = join "", <$in>;
|
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my ( $file, $options, $link ) = extract($content);
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub extract
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
{
|
51
|
0
|
|
|
0
|
1
|
|
my $content = shift;
|
52
|
0
|
|
|
|
|
|
my @file;
|
53
|
|
|
|
|
|
|
my %options;
|
54
|
0
|
|
|
|
|
|
my %link;
|
55
|
0
|
|
|
|
|
|
while ( $content =~ /((?:[^";]+|\"(?:\\.|.)*?\")+?)\s*;/sg ) {
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#print ">>$1<<\n";
|
58
|
0
|
|
|
|
|
|
my $statement = $1;
|
59
|
0
|
|
|
|
|
|
my $first = 1;
|
60
|
0
|
0
|
|
|
|
|
if ( $statement =~ /\s*([^\s(]+)(?:\((.+?)\))?/gc ) {
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#print ">>>>>>>$1 $2\n";
|
63
|
0
|
|
|
|
|
|
my ( $section, $options ) = ( $1, $2 );
|
64
|
0
|
0
|
0
|
|
|
|
if ( $section eq "options" or $section eq "link" ) {
|
|
|
0
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ( $statement =~ /\G\s*\"((?:\\.|.)*?)\"|\s*(.+)/gc ) {
|
66
|
0
|
|
|
|
|
|
my @configuration = split /\s*\|\s*/, $options;
|
67
|
0
|
0
|
|
|
|
|
if ( $section eq "options" ) {
|
68
|
0
|
|
|
|
|
|
for my $c (@configuration) {
|
69
|
0
|
0
|
|
|
|
|
push @{ $options{$c} }, defined $1 ? remove_escapes($1) : $2;
|
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
}
|
72
|
0
|
0
|
|
|
|
|
if ( $section eq "link" ) {
|
73
|
0
|
|
|
|
|
|
for my $c (@configuration) {
|
74
|
0
|
0
|
|
|
|
|
push @{ $link{$c} }, defined $1 ? remove_escapes($1) : $2;
|
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
elsif ( $section eq "file" ) {
|
80
|
0
|
0
|
|
|
|
|
if ( $statement =~ /\G\s*(.+)/gcs ) {
|
81
|
0
|
|
|
|
|
|
my $filelist = $1;
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#my @filelist;
|
84
|
0
|
|
|
|
|
|
while ( $filelist
|
85
|
|
|
|
|
|
|
=~ /((?:[^",]+|\"(?:\\.|.)*?\")+?)\s*,\s*|((?:[^",]+|\"(?:\\.|.)*?\")+?)\s*/gs )
|
86
|
|
|
|
|
|
|
{
|
87
|
0
|
|
|
|
|
|
my $file_and_options = $1 . $2;
|
88
|
0
|
0
|
|
|
|
|
if ( $file_and_options =~ /s*\"((?:\\.|.)*?)\"|\s*(.+)/g ) {
|
89
|
0
|
0
|
|
|
|
|
my $filename = defined $1 ? remove_escapes($1) : $2;
|
90
|
0
|
|
|
|
|
|
my %options;
|
91
|
0
|
0
|
|
|
|
|
if ( $file_and_options =~ /\s*([^\s(]+)(?:\((.+?)\))?/gc ) {
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#print ">>>>>>>$1 $2\n";
|
94
|
0
|
|
|
|
|
|
my ( $section, $options ) = ( $1, $2 );
|
95
|
0
|
0
|
|
|
|
|
if ( $section eq "options" ) {
|
96
|
0
|
0
|
|
|
|
|
if ( $file_and_options =~ /\G\s*\"((?:\\.|.)*?)\"|\s*(.+)/gc ) {
|
97
|
0
|
|
|
|
|
|
my @configuration = split /\s*\|\s*/, $options;
|
98
|
0
|
0
|
|
|
|
|
if ( $section eq "options" ) {
|
99
|
0
|
|
|
|
|
|
for my $c (@configuration) {
|
100
|
0
|
0
|
|
|
|
|
push @{ $options{$c} }, defined $1 ? remove_escapes($1) : $2;
|
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
}
|
106
|
0
|
|
|
|
|
|
push @file, [ $filename, \%options ];
|
107
|
|
|
|
|
|
|
}
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# while (/\s+|\"((?:\\.|.)+?)\")|([^\s]+)/sg)
|
114
|
|
|
|
|
|
|
# {
|
115
|
|
|
|
|
|
|
# if (defined $2 && $first)
|
116
|
|
|
|
|
|
|
# {
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# $first = 1;
|
119
|
|
|
|
|
|
|
# }
|
120
|
|
|
|
|
|
|
# }
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# for my $k (%options) {
|
125
|
|
|
|
|
|
|
# print "$k $options{$k}\n";
|
126
|
|
|
|
|
|
|
# }
|
127
|
0
|
|
|
|
|
|
return ( \@file, \%options, \%link );
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub format_filelist {
|
131
|
0
|
|
|
0
|
0
|
|
my ($filelist) = @_;
|
132
|
0
|
|
|
|
|
|
my $outstr;
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
#print "$f->[0]\n";
|
135
|
0
|
|
|
|
|
|
$outstr = join " ", @$filelist;
|
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $outstr;
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub add_switch {
|
141
|
0
|
|
|
0
|
0
|
|
my $sw = shift;
|
142
|
0
|
0
|
|
|
|
|
return " " . $sw if ($sw);
|
143
|
0
|
|
|
|
|
|
return "";
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub make_compilation {
|
147
|
0
|
|
|
0
|
1
|
|
my ( $filelist, $options, $link, $target, $compiler_exe, $linker_exe, $compiler_flags, $link_flags ) = @_;
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# -Ic:\mingw\include -IC:\mingw\include\c++\3.4.5 -IC:\mingw\include\c++\3.4.5\mingw32\bits
|
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $commandlist;
|
152
|
|
|
|
|
|
|
my @objs;
|
153
|
0
|
|
|
|
|
|
my $o_ext = ".o";
|
154
|
0
|
|
|
|
|
|
my $o_sw = "-o ";
|
155
|
0
|
0
|
|
|
|
|
if ( $target =~ /^msc/i ) {
|
156
|
0
|
|
|
|
|
|
$o_ext = ".obj";
|
157
|
0
|
|
|
|
|
|
$o_sw = "-Fo";
|
158
|
|
|
|
|
|
|
}
|
159
|
0
|
|
|
|
|
|
for my $f (@$filelist) {
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
#print "$f->[0]\n";
|
162
|
0
|
0
|
|
|
|
|
if ( $f->[0] =~ /^\.cpp|\.c$/ ) {
|
163
|
0
|
|
|
|
|
|
my $out_filename = $f->[0];
|
164
|
0
|
|
|
|
|
|
$out_filename =~ s/\.\w+$/$o_ext/;
|
165
|
0
|
|
|
|
|
|
$commandlist
|
166
|
|
|
|
|
|
|
.= $compiler_exe . " -c "
|
167
|
|
|
|
|
|
|
. $f->[0]
|
168
|
|
|
|
|
|
|
. " $o_sw"
|
169
|
|
|
|
|
|
|
. $out_filename
|
170
|
|
|
|
|
|
|
. add_switch( $f->[1]->{$target} )
|
171
|
0
|
|
|
|
|
|
. add_switch( join " ", @{ $options->{$target} } )
|
172
|
|
|
|
|
|
|
. add_switch($compiler_flags) . "\n";
|
173
|
0
|
|
|
|
|
|
push @objs, $out_filename;
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
}
|
177
|
0
|
|
|
|
|
|
$commandlist .= $linker_exe;
|
178
|
0
|
|
|
|
|
|
for my $obj (@objs) {
|
179
|
0
|
|
|
|
|
|
$commandlist .= " " . $obj;
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
}
|
182
|
0
|
|
|
|
|
|
$commandlist .= add_switch( join "", @{ $link->{$target} } ) . add_switch($link_flags);
|
|
0
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
return $commandlist;
|
185
|
|
|
|
|
|
|
}
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub example1 {
|
188
|
0
|
|
|
0
|
0
|
|
print Upp::Reader::make_compilation (
|
189
|
|
|
|
|
|
|
Upp::Reader::read_upp('D:\m\upp\extractor\extractor.upp'),
|
190
|
|
|
|
|
|
|
'GCC', 'gcc.exe', 'ld.exe', '-DRELEASE', ''
|
191
|
|
|
|
|
|
|
);
|
192
|
|
|
|
|
|
|
}
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1;
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
__END__
|