line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::plasm; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
860702
|
use strict; |
|
4
|
|
|
|
|
31
|
|
|
4
|
|
|
|
|
105
|
|
4
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
103
|
|
5
|
4
|
|
|
4
|
|
83
|
use 5.008001; |
|
4
|
|
|
|
|
12
|
|
6
|
4
|
|
|
4
|
|
1936
|
use Pod::Usage qw( pod2usage ); |
|
4
|
|
|
|
|
128627
|
|
|
4
|
|
|
|
|
386
|
|
7
|
4
|
|
|
4
|
|
2739
|
use Getopt::Long qw( GetOptions ); |
|
4
|
|
|
|
|
34656
|
|
|
4
|
|
|
|
|
18
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Perl WebAssembly command line tool |
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub main |
14
|
|
|
|
|
|
|
{ |
15
|
14
|
|
|
14
|
0
|
137960
|
my $class = shift; # unused |
16
|
|
|
|
|
|
|
|
17
|
14
|
|
|
|
|
83
|
Getopt::Long::Configure('permute'); |
18
|
|
|
|
|
|
|
|
19
|
14
|
50
|
66
|
|
|
590
|
if(defined $_[0] && $_[0] =~ /\.wasm$/) |
20
|
|
|
|
|
|
|
{ |
21
|
0
|
|
|
|
|
0
|
unshift @_, 'run'; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
14
|
100
|
100
|
|
|
107
|
if(defined $_[0] && $_[0] !~ /^-/) |
25
|
|
|
|
|
|
|
{ |
26
|
9
|
|
|
|
|
22
|
my $cmd = shift; |
27
|
9
|
|
|
|
|
25
|
my $class = "App::plasm::$cmd"; |
28
|
9
|
|
|
|
|
88
|
my $main = $class->can('main'); |
29
|
9
|
100
|
|
|
|
49
|
pod2usage({ |
30
|
|
|
|
|
|
|
-message => "no subcommand '$cmd'", |
31
|
|
|
|
|
|
|
-exitval => 2, |
32
|
|
|
|
|
|
|
}) unless defined $main; |
33
|
8
|
|
|
|
|
29
|
return $main->(@_); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else |
36
|
|
|
|
|
|
|
{ |
37
|
5
|
|
|
|
|
20
|
local @ARGV = @_; |
38
|
|
|
|
|
|
|
GetOptions( |
39
|
1
|
|
|
1
|
|
280
|
'help|h' => sub { pod2usage({ -exitval => 0 }) }, |
40
|
1
|
|
50
|
1
|
|
413
|
'version|v' => sub { print "plasm version @{[ App::plasm->VERSION || 'dev' ]} Wasm.pm @{[ Wasm->VERSION ]}\n"; exit 0 }, |
|
1
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
57
|
|
|
1
|
|
|
|
|
9
|
|
41
|
5
|
100
|
|
|
|
41
|
) or pod2usage({ -exitval => 2 }); |
42
|
2
|
|
|
|
|
371
|
pod2usage({ -exitval => 2 }); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
package App::plasm::run; |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
4
|
|
1544
|
use Pod::Usage qw( pod2usage ); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
164
|
|
49
|
4
|
|
|
4
|
|
22
|
use Getopt::Long qw( GetOptions ); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
13
|
|
50
|
4
|
|
|
4
|
|
2323
|
use Wasm 0.08; |
|
4
|
|
|
|
|
14660
|
|
|
4
|
|
|
|
|
33
|
|
51
|
4
|
|
|
4
|
|
1533
|
use Wasm::Hook; |
|
4
|
|
|
|
|
117069
|
|
|
4
|
|
|
|
|
22
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $sandbox; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub main |
56
|
|
|
|
|
|
|
{ |
57
|
5
|
|
|
5
|
|
17
|
local @ARGV = @_; |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
|
|
13
|
Getopt::Long::Configure('require_order'); |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
117
|
my @pod = (-verbose => 99, -sections => "SUBCOMMANDS/run"); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
GetOptions( |
64
|
1
|
|
|
1
|
|
276
|
'help|h' => sub { pod2usage({ -exitval => 0, @pod }) }, |
65
|
5
|
100
|
|
|
|
35
|
) or pod2usage({ -exitval => 2, @pod }); |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
556
|
my $filename = shift @ARGV; |
68
|
|
|
|
|
|
|
|
69
|
3
|
50
|
|
|
|
8
|
pod2usage({ @pod, |
70
|
|
|
|
|
|
|
-exitval => 2, |
71
|
|
|
|
|
|
|
}) unless defined $filename; |
72
|
|
|
|
|
|
|
|
73
|
3
|
100
|
|
|
|
130
|
pod2usage({ @pod, |
74
|
|
|
|
|
|
|
-message => "File not found: $filename", |
75
|
|
|
|
|
|
|
-exitval => 2, |
76
|
|
|
|
|
|
|
}) unless -f $filename; |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
7
|
my $class = "App::plasm::run::sandbox@{[ $sandbox++ ]}"; |
|
2
|
|
|
|
|
11
|
|
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
23
|
local $0 = $filename; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
26
|
Wasm->import( |
83
|
|
|
|
|
|
|
-api => 0, |
84
|
|
|
|
|
|
|
-package => $class, |
85
|
|
|
|
|
|
|
-file => $filename, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
297319
|
my $start = $class->can('_start'); |
89
|
2
|
|
|
|
|
9
|
$start->(); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# TODO: detect exit value and pass that on... |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
759
|
return 0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package App::plasm::dump; |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
4
|
|
1037
|
use Pod::Usage qw( pod2usage ); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
236
|
|
99
|
4
|
|
|
4
|
|
22
|
use Getopt::Long qw( GetOptions ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
26
|
|
100
|
4
|
|
|
4
|
|
2285
|
use Wasm::Wasmtime 0.08; |
|
4
|
|
|
|
|
815332
|
|
|
4
|
|
|
|
|
765
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub main |
103
|
|
|
|
|
|
|
{ |
104
|
2
|
|
|
2
|
|
7
|
local @ARGV = @_; |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
10
|
my @pod = (-verbose => 99, -sections => "SUBCOMMANDS/run"); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
GetOptions( |
109
|
0
|
|
|
0
|
|
0
|
'help|h' => sub { pod2usage({ -exitval => 0, @pod }) }, |
110
|
2
|
50
|
|
|
|
15
|
) or pod2usage({ -exitval => 2, @pod }); |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
428
|
my $filename = shift @ARGV; |
113
|
|
|
|
|
|
|
|
114
|
2
|
50
|
|
|
|
5
|
pod2usage({ @pod, |
115
|
|
|
|
|
|
|
-exitval => 2, |
116
|
|
|
|
|
|
|
}) unless defined $filename; |
117
|
|
|
|
|
|
|
|
118
|
2
|
50
|
|
|
|
38
|
pod2usage({ @pod, |
119
|
|
|
|
|
|
|
-message => "File not found: $filename", |
120
|
|
|
|
|
|
|
-exitval => 2, |
121
|
|
|
|
|
|
|
}) unless -f $filename; |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
26
|
my $module = Wasm::Wasmtime::Module->new( |
124
|
|
|
|
|
|
|
file => $filename, |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
|
|
110250
|
print $module->to_string; |
128
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
3853
|
return 0; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
package App::plasm::wat; |
133
|
|
|
|
|
|
|
|
134
|
4
|
|
|
4
|
|
36
|
use Pod::Usage qw( pod2usage ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
184
|
|
135
|
4
|
|
|
4
|
|
23
|
use Getopt::Long qw( GetOptions ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
40
|
|
136
|
4
|
|
|
4
|
|
2544
|
use Wasm::Wasmtime::Wat2Wasm qw( wat2wasm ); |
|
4
|
|
|
|
|
2522
|
|
|
4
|
|
|
|
|
212
|
|
137
|
4
|
|
|
4
|
|
25
|
use Path::Tiny qw( path ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1099
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub main |
140
|
|
|
|
|
|
|
{ |
141
|
1
|
|
|
1
|
|
4
|
local @ARGV = @_; |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
3
|
my @pod = (-verbose => 99, -sections => "SUBCOMMANDS/wat"); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
GetOptions( |
146
|
0
|
|
|
0
|
|
0
|
'help|h' => sub { pod2usage({ -exitval => 0, @pod }) }, |
147
|
1
|
50
|
|
|
|
8
|
) or pod2usage({ -exitval => 2, @pod }); |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
224
|
my $filename = shift @ARGV; |
150
|
|
|
|
|
|
|
|
151
|
1
|
50
|
|
|
|
3
|
pod2usage({ @pod, |
152
|
|
|
|
|
|
|
-exitval => 2, |
153
|
|
|
|
|
|
|
}) unless defined $filename; |
154
|
|
|
|
|
|
|
|
155
|
1
|
50
|
|
|
|
19
|
pod2usage({ @pod, |
156
|
|
|
|
|
|
|
-message => "File not found: $filename", |
157
|
|
|
|
|
|
|
-exitval => 2, |
158
|
|
|
|
|
|
|
}) unless -f $filename; |
159
|
|
|
|
|
|
|
|
160
|
1
|
|
|
|
|
14
|
my $in = path($filename); |
161
|
1
|
|
|
|
|
47
|
my $out = $in->parent->child(do { |
162
|
1
|
|
|
|
|
96
|
my $basename = $in->basename; |
163
|
1
|
|
|
|
|
14
|
$basename =~ s/\.wat$//; |
164
|
1
|
|
|
|
|
4
|
$basename . '.wasm'; |
165
|
|
|
|
|
|
|
}); |
166
|
|
|
|
|
|
|
|
167
|
1
|
50
|
|
|
|
35
|
pod2usage({ @pod, |
168
|
|
|
|
|
|
|
-message => "Output file already exists: $out", |
169
|
|
|
|
|
|
|
-exitval => 2, |
170
|
|
|
|
|
|
|
}) if -e $out; |
171
|
|
|
|
|
|
|
|
172
|
1
|
|
|
|
|
21
|
$out->spew_raw(wat2wasm($in->slurp_utf8)); |
173
|
|
|
|
|
|
|
|
174
|
1
|
|
|
|
|
1748
|
return 0; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |