line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wasm::Wasmtime::Linker; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
3274
|
use strict; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
272
|
|
4
|
9
|
|
|
9
|
|
44
|
use warnings; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
226
|
|
5
|
9
|
|
|
9
|
|
146
|
use 5.008004; |
|
9
|
|
|
|
|
31
|
|
6
|
9
|
|
|
9
|
|
461
|
use Wasm::Wasmtime::FFI; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
1075
|
|
7
|
9
|
|
|
9
|
|
563
|
use Wasm::Wasmtime::Store; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
213
|
|
8
|
9
|
|
|
9
|
|
471
|
use Wasm::Wasmtime::Extern; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
274
|
|
9
|
9
|
|
|
9
|
|
496
|
use Wasm::Wasmtime::Instance; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
251
|
|
10
|
9
|
|
|
9
|
|
3861
|
use Wasm::Wasmtime::WasiInstance; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
334
|
|
11
|
9
|
|
|
9
|
|
69
|
use Wasm::Wasmtime::Func; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
186
|
|
12
|
9
|
|
|
9
|
|
46
|
use Wasm::Wasmtime::Trap; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
268
|
|
13
|
9
|
|
|
9
|
|
52
|
use Ref::Util qw( is_blessed_ref ); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
423
|
|
14
|
9
|
|
|
9
|
|
53
|
use Carp (); |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
8033
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: Wasmtime linker class |
17
|
|
|
|
|
|
|
our $VERSION = '0.21'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$ffi_prefix = 'wasmtime_linker_'; |
21
|
|
|
|
|
|
|
$ffi->load_custom_type('::PtrObject' => 'wasmtime_linker_t' => __PACKAGE__); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$ffi->attach( new => ['wasm_store_t'] => 'wasmtime_linker_t' => sub { |
25
|
|
|
|
|
|
|
my($xsub, $class, $store) = @_; |
26
|
|
|
|
|
|
|
my $self = $xsub->($store); |
27
|
|
|
|
|
|
|
$self->{store} = $store; |
28
|
|
|
|
|
|
|
$self; |
29
|
|
|
|
|
|
|
}); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$ffi->attach( allow_shadowing => [ 'wasmtime_linker_t', 'bool' ] => sub { |
33
|
|
|
|
|
|
|
my($xsub, $self, $value) = @_; |
34
|
|
|
|
|
|
|
$xsub->($self, $value); |
35
|
|
|
|
|
|
|
$self; |
36
|
|
|
|
|
|
|
}); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$ffi->attach( define => ['wasmtime_linker_t', 'wasm_byte_vec_t*', 'wasm_byte_vec_t*', 'opaque'] => 'wasmtime_error_t' => sub { |
40
|
|
|
|
|
|
|
my $xsub = shift; |
41
|
|
|
|
|
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
my $module = Wasm::Wasmtime::ByteVec->new(shift); |
43
|
|
|
|
|
|
|
my $name = Wasm::Wasmtime::ByteVec->new(shift); |
44
|
|
|
|
|
|
|
my $extern = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Fix this sillyness when/if ::Extern becomes a base class for extern classes |
47
|
|
|
|
|
|
|
if(is_blessed_ref($extern) && ( $extern->isa('Wasm::Wasmtime::Extern') |
48
|
|
|
|
|
|
|
|| $extern->isa('Wasm::Wasmtime::Func') |
49
|
|
|
|
|
|
|
|| $extern->isa('Wasm::Wasmtime::Memory') |
50
|
|
|
|
|
|
|
|| $extern->isa('Wasm::Wasmtime::Global') |
51
|
|
|
|
|
|
|
|| $extern->isa('Wasm::Wasmtime::Table'))) |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
my $error = $xsub->($self, $module, $name, $extern->{ptr}); |
54
|
|
|
|
|
|
|
Carp::croak($error->message) if $error; |
55
|
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
Carp::croak("not an extern: $extern"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$ffi->attach( define_wasi => ['wasmtime_linker_t', 'wasi_instance_t'] => 'wasmtime_error_t' => sub { |
65
|
|
|
|
|
|
|
my($xsub, $self, $wasi) = @_; |
66
|
|
|
|
|
|
|
my $error = $xsub->($self, $wasi); |
67
|
|
|
|
|
|
|
Carp::croak($error->message) if $error; |
68
|
|
|
|
|
|
|
$self; |
69
|
|
|
|
|
|
|
}); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$ffi->attach( define_instance => ['wasmtime_linker_t', 'wasm_byte_vec_t*', 'wasm_instance_t'] => 'wasmtime_error_t' => sub { |
73
|
|
|
|
|
|
|
my($xsub, $self, $name, $instance) = @_; |
74
|
|
|
|
|
|
|
my $vname = Wasm::Wasmtime::ByteVec->new($name); |
75
|
|
|
|
|
|
|
my $error = $xsub->($self, $vname, $instance); |
76
|
|
|
|
|
|
|
Carp::croak($error->message) if $error; |
77
|
|
|
|
|
|
|
$self; |
78
|
|
|
|
|
|
|
}); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$ffi->attach( instantiate => ['wasmtime_linker_t','wasm_module_t','opaque*','opaque*'] => 'wasmtime_error_t' => sub { |
82
|
|
|
|
|
|
|
my($xsub, $self, $module) = @_; |
83
|
|
|
|
|
|
|
my $trap; |
84
|
|
|
|
|
|
|
my $ptr; |
85
|
|
|
|
|
|
|
my $error = $xsub->($self, $module, \$ptr, \$trap); |
86
|
|
|
|
|
|
|
Carp::croak($error->message) if $error; |
87
|
|
|
|
|
|
|
if($trap) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
$trap = Wasm::Wasmtime::Trap->new($trap); |
90
|
|
|
|
|
|
|
die $trap; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif($ptr) |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
return Wasm::Wasmtime::Instance->new( |
95
|
|
|
|
|
|
|
$module, $self->store, $ptr, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
Carp::croak("unknown instantiate error"); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
}); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$ffi->attach( get_one_by_name => ['wasmtime_linker_t','wasm_byte_vec_t*','wasm_byte_vec_t*','opaque*'] => 'wasmtime_error_t' => sub { |
106
|
|
|
|
|
|
|
my($xsub, $self, $module, $name) = @_; |
107
|
|
|
|
|
|
|
my $vmodule = Wasm::Wasmtime::ByteVec->new($module); |
108
|
|
|
|
|
|
|
my $vname = Wasm::Wasmtime::ByteVec->new($name); |
109
|
|
|
|
|
|
|
my $ptr; |
110
|
|
|
|
|
|
|
if(my $error = $xsub->($self, $vmodule, $vname, \$ptr)) |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
Carp::croak($error->message); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
else |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
$ptr |
117
|
|
|
|
|
|
|
? $ffi->cast('opaque','wasm_extern_t',$ptr) |
118
|
|
|
|
|
|
|
: undef; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
}); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$ffi->attach( get_default => ['wasmtime_linker_t','wasm_byte_vec_t*','opaque*'] => 'wasmtime_error_t' => sub { |
124
|
|
|
|
|
|
|
my($xsub, $self, $name) = @_; |
125
|
|
|
|
|
|
|
my $vname = Wasm::Wasmtime::ByteVec->new($name); |
126
|
|
|
|
|
|
|
my $ptr; |
127
|
|
|
|
|
|
|
if(my $error = $xsub->($self, $vname, \$ptr)) |
128
|
|
|
|
|
|
|
{ |
129
|
|
|
|
|
|
|
Carp::croak($error->message); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else |
132
|
|
|
|
|
|
|
{ |
133
|
|
|
|
|
|
|
return $ptr ? Wasm::Wasmtime::Func->new($ptr, $self) : undef; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
}); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
46
|
|
|
46
|
1
|
408
|
sub store { shift->{store} } |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
_generate_destroy(); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |