File Coverage

blib/lib/Wasm/Wasmtime/Config.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::Config;
2              
3 27     27   462731 use strict;
  27         103  
  27         824  
4 27     27   140 use warnings;
  27         56  
  27         637  
5 27     27   499 use 5.008004;
  27         114  
6 27     27   1026 use Wasm::Wasmtime::FFI;
  27         145  
  27         29803  
7              
8             # ABSTRACT: Global configuration for Wasm::Wasmtime::Engine
9             our $VERSION = '0.22'; # VERSION
10              
11              
12             $ffi_prefix = 'wasm_config_';
13             $ffi->load_custom_type('::PtrObject' => 'wasm_config_t' => __PACKAGE__);
14              
15              
16             $ffi->attach( new => [] => 'wasm_config_t' );
17              
18             _generate_destroy();
19              
20              
21             foreach my $prop (qw(
22             cranelift_debug_verifier
23             debug_info
24             interruptable
25             wasm_bulk_memory
26             wasm_reference_types
27             wasm_multi_value
28             wasm_simd
29             wasm_threads
30             ))
31             {
32             $ffi->attach( [ "wasmtime_config_${prop}_set" => $prop ] => [ 'wasm_config_t', 'bool' ] => sub {
33             my($xsub, $self, $value) = @_;
34             $xsub->($self, $value);
35             $self;
36             });
37             }
38              
39             foreach my $prop (qw(
40             max_wasm_stack
41             ))
42             {
43             $ffi->attach( [ "wasmtime_config_${prop}_set" => $prop ] => [ 'wasm_config_t', 'size_t' ] => sub {
44             my($xsub, $self, $value) = @_;
45             $xsub->($self, $value);
46             $self;
47             });
48             }
49              
50              
51             outer:
52             foreach my $prop (qw( static_memory_maximum_size static_memory_guard_size dynamic_memory_guard_size ))
53             {
54             $ffi->attach( [ "wasmtime_config_${prop}_set" => $prop ] => [ 'wasm_config_t', 'uint64' ] => 'void' => sub {
55             my($xsub, $self, $value) = @_;
56             $xsub->($self, $value);
57             $self;
58             });
59             }
60              
61              
62             my %strategy = (
63             auto => 0,
64             cranelift => 1,
65             lightbeam => 2,
66             );
67              
68             $ffi->attach( [ 'wasmtime_config_strategy_set' => 'strategy' ] => [ 'wasm_config_t', 'uint8' ] => 'wasmtime_error_t' => sub {
69             my($xsub, $self, $value) = @_;
70             if(defined $strategy{$value})
71             {
72             if(my $error = $xsub->($self, $strategy{$value}))
73             {
74             Carp::croak($error->message);
75             }
76             }
77             else
78             {
79             Carp::croak("unknown strategy: $value");
80             }
81             $self;
82             });
83              
84              
85             my %cranelift_opt_level = (
86             none => 0,
87             speed => 1,
88             speed_and_size => 2,
89             );
90              
91             $ffi->attach( ['wasmtime_config_cranelift_opt_level_set' => 'cranelift_opt_level' ] => ['wasm_config_t', 'uint8' ] => sub {
92             my($xsub, $self, $value) = @_;
93             if(defined $cranelift_opt_level{$value})
94             {
95             $xsub->($self, $cranelift_opt_level{$value});
96             }
97             else
98             {
99             Carp::croak("unknown cranelift_opt_level: $value");
100             }
101             $self;
102             });
103              
104              
105             my %profiler = (
106             none => 0,
107             jitdump => 1,
108             vtune => 2,
109             );
110              
111             $ffi->attach( ['wasmtime_config_profiler_set' => 'profiler' ] => ['wasm_config_t', 'uint8'] => 'wasmtime_error_t' => sub {
112             my($xsub, $self, $value) = @_;
113             if(defined $profiler{$value})
114             {
115             if(my $error = $xsub->($self, $profiler{$value}))
116             {
117             Carp::croak($error->message);
118             }
119             }
120             else
121             {
122             Carp::croak("unknown profiler: $value");
123             }
124             $self;
125             });
126              
127              
128             $ffi->attach( [ 'wasmtime_config_cache_config_load' => 'cache_config_load' ] => [ 'wasm_config_t', 'string' ] => sub {
129             my($xsub, $self, $value) = @_;
130             Carp::croak("undef passed in as cache config") unless defined $value;
131             $xsub->($self, $value);
132             $self;
133             });
134              
135             $ffi->attach( [ 'wasmtime_config_cache_config_load' => 'cache_config_default' ] => [ 'wasm_config_t', 'string' ] => sub {
136             my($xsub, $self) = @_;
137             $xsub->($self, undef);
138             $self;
139             });
140              
141              
142             if(_v0_23_0())
143             {
144             $ffi->attach( ['wasmtime_config_consume_fuel_set' => 'consume_fuel' ] => [ 'wasm_config_t', 'bool' ] => sub {
145             my($xsub, $self, $value) = @_;
146             $xsub->($self, $value);
147             $self;
148             });
149             $ffi->attach( ['wasmtime_config_max_instances_set' => 'max_instances' ] => [ 'wasm_config_t', 'size_t' ] => sub {
150             my($xsub, $self, $value) = @_;
151             $xsub->($self, $value);
152             $self;
153             });
154             }
155             else
156             {
157             *consume_fuel = sub {
158 1     1   427 Carp::croak("unimplemented, upgrade wasmtime to 0.23.0");
159             };
160             *max_instances = sub {
161 1     1   755 Carp::croak("unimplemented, upgrade wasmtime to 0.23.0");
162             };
163             }
164              
165             1;
166              
167             __END__