wardite 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/load_perf.rb +24 -0
- data/lib/wardite/alu_f32.generated.rb +12 -10
- data/lib/wardite/alu_f64.generated.rb +12 -10
- data/lib/wardite/alu_i32.generated.rb +24 -22
- data/lib/wardite/alu_i64.generated.rb +30 -28
- data/lib/wardite/cli/cli.rb +18 -0
- data/lib/wardite/convert.generated.rb +7 -5
- data/lib/wardite/instruction.rb +424 -64
- data/lib/wardite/leb128.rb +3 -6
- data/lib/wardite/load.rb +62 -26
- data/lib/wardite/revisitor.rb +12 -4
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite.rb +37 -36
- data/scripts/gen_alu.rb +24 -24
- data/scripts/templates/alu_module.rb.tmpl +7 -5
- data/scripts/templates/conv_module.rb.tmpl +7 -5
- data/sig/generated/wardite/alu_f32.generated.rbs +4 -3
- data/sig/generated/wardite/alu_f64.generated.rbs +4 -3
- data/sig/generated/wardite/alu_i32.generated.rbs +4 -3
- data/sig/generated/wardite/alu_i64.generated.rbs +4 -3
- data/sig/generated/wardite/cli/cli.rbs +5 -0
- data/sig/generated/wardite/convert.generated.rbs +4 -3
- data/sig/generated/wardite/instruction.rbs +13 -9
- data/sig/generated/wardite/load.rbs +9 -9
- data/sig/generated/wardite.rbs +7 -7
- data/sig/vernier.rbs +3 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed01a146affa721cec03c8751baded66418e2f62d6b42a878c6a8a60d8bdf270
|
4
|
+
data.tar.gz: 84fdcdfb8127d32a40f95f629065b6ce9c65f30e9f79c854003b9de05ee45b14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 538b3e0a4b50fc5b4e109a39d1c243a5751d877859d1fe9942e8e5e52633ecf62ba55b2a99b0ffd80102c3b5cb7de258c8d0e878a8738b0bced8d4c9823e4052
|
7
|
+
data.tar.gz: 343459f70f34ebe76916058adc10d4db338d2594a39c4dca364fa8387b6c72393939e827517364965a8da14cf64ebf129198c9dbcfab9cf89dc0f17c766a752a
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "wardite"
|
2
|
+
require "optparse"
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
$options = OpenStruct.new
|
6
|
+
|
7
|
+
opt = OptionParser.new
|
8
|
+
opt.on('--wasm-file [FILE]') {|v| $options.wasm_file = v }
|
9
|
+
opt.parse!
|
10
|
+
|
11
|
+
f = File.open($options.wasm_file)
|
12
|
+
|
13
|
+
require "vernier"
|
14
|
+
RubyVM::YJIT.enable
|
15
|
+
puts "YJIT enabled: #{RubyVM::YJIT.enabled?}"
|
16
|
+
|
17
|
+
Vernier.profile(out: "./tmp/load_perf.json") do
|
18
|
+
start = Time.now
|
19
|
+
_instance = Wardite::BinaryLoader::load_from_buffer(f);
|
20
|
+
puts "Profile saved to ./tmp/load_perf.json"
|
21
|
+
puts "Load time: #{Time.now.to_f - start.to_f} seconds"
|
22
|
+
end
|
23
|
+
|
24
|
+
p "OK"
|
@@ -5,14 +5,15 @@ module Wardite
|
|
5
5
|
module Evaluator
|
6
6
|
# @rbs runtime: Runtime
|
7
7
|
# @rbs frame: Frame
|
8
|
-
# @rbs
|
9
|
-
# @rbs
|
10
|
-
|
11
|
-
|
8
|
+
# @rbs code: Symbol
|
9
|
+
# @rbs operand: Array[operandItem]
|
10
|
+
# @rbs return: bool?
|
11
|
+
def self.f32_eval_insn(runtime, frame, code, operand)
|
12
|
+
case code
|
12
13
|
|
13
14
|
when :f32_load
|
14
|
-
_align =
|
15
|
-
offset =
|
15
|
+
_align = operand[0] # TODO: alignment support?
|
16
|
+
offset = operand[1]
|
16
17
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
17
18
|
|
18
19
|
addr = runtime.stack.pop
|
@@ -31,8 +32,8 @@ module Wardite
|
|
31
32
|
|
32
33
|
|
33
34
|
when :f32_store
|
34
|
-
_align =
|
35
|
-
offset =
|
35
|
+
_align = operand[0] # TODO: alignment support?
|
36
|
+
offset = operand[1]
|
36
37
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
37
38
|
|
38
39
|
value = runtime.stack.pop
|
@@ -48,7 +49,7 @@ module Wardite
|
|
48
49
|
|
49
50
|
|
50
51
|
when :f32_const
|
51
|
-
const =
|
52
|
+
const = operand[0]
|
52
53
|
if !const.is_a?(Float)
|
53
54
|
raise EvalError, "invalid type of operand"
|
54
55
|
end
|
@@ -243,8 +244,9 @@ module Wardite
|
|
243
244
|
|
244
245
|
|
245
246
|
else
|
246
|
-
|
247
|
+
return
|
247
248
|
end
|
249
|
+
return true
|
248
250
|
end
|
249
251
|
end
|
250
252
|
end
|
@@ -5,14 +5,15 @@ module Wardite
|
|
5
5
|
module Evaluator
|
6
6
|
# @rbs runtime: Runtime
|
7
7
|
# @rbs frame: Frame
|
8
|
-
# @rbs
|
9
|
-
# @rbs
|
10
|
-
|
11
|
-
|
8
|
+
# @rbs code: Symbol
|
9
|
+
# @rbs operand: Array[operandItem]
|
10
|
+
# @rbs return: bool?
|
11
|
+
def self.f64_eval_insn(runtime, frame, code, operand)
|
12
|
+
case code
|
12
13
|
|
13
14
|
when :f64_load
|
14
|
-
_align =
|
15
|
-
offset =
|
15
|
+
_align = operand[0] # TODO: alignment support?
|
16
|
+
offset = operand[1]
|
16
17
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
17
18
|
|
18
19
|
addr = runtime.stack.pop
|
@@ -31,8 +32,8 @@ module Wardite
|
|
31
32
|
|
32
33
|
|
33
34
|
when :f64_store
|
34
|
-
_align =
|
35
|
-
offset =
|
35
|
+
_align = operand[0] # TODO: alignment support?
|
36
|
+
offset = operand[1]
|
36
37
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
37
38
|
|
38
39
|
value = runtime.stack.pop
|
@@ -48,7 +49,7 @@ module Wardite
|
|
48
49
|
|
49
50
|
|
50
51
|
when :f64_const
|
51
|
-
const =
|
52
|
+
const = operand[0]
|
52
53
|
if !const.is_a?(Float)
|
53
54
|
raise EvalError, "invalid type of operand"
|
54
55
|
end
|
@@ -243,8 +244,9 @@ module Wardite
|
|
243
244
|
|
244
245
|
|
245
246
|
else
|
246
|
-
|
247
|
+
return
|
247
248
|
end
|
249
|
+
return true
|
248
250
|
end
|
249
251
|
end
|
250
252
|
end
|
@@ -5,14 +5,15 @@ module Wardite
|
|
5
5
|
module Evaluator
|
6
6
|
# @rbs runtime: Runtime
|
7
7
|
# @rbs frame: Frame
|
8
|
-
# @rbs
|
9
|
-
# @rbs
|
10
|
-
|
11
|
-
|
8
|
+
# @rbs code: Symbol
|
9
|
+
# @rbs operand: Array[operandItem]
|
10
|
+
# @rbs return: bool?
|
11
|
+
def self.i32_eval_insn(runtime, frame, code, operand)
|
12
|
+
case code
|
12
13
|
|
13
14
|
when :i32_load
|
14
|
-
_align =
|
15
|
-
offset =
|
15
|
+
_align = operand[0] # TODO: alignment support?
|
16
|
+
offset = operand[1]
|
16
17
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
17
18
|
|
18
19
|
addr = runtime.stack.pop
|
@@ -31,8 +32,8 @@ module Wardite
|
|
31
32
|
|
32
33
|
|
33
34
|
when :i32_load8_s
|
34
|
-
_align =
|
35
|
-
offset =
|
35
|
+
_align = operand[0] # TODO: alignment support?
|
36
|
+
offset = operand[1]
|
36
37
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
37
38
|
|
38
39
|
addr = runtime.stack.pop
|
@@ -51,8 +52,8 @@ module Wardite
|
|
51
52
|
|
52
53
|
|
53
54
|
when :i32_load8_u
|
54
|
-
_align =
|
55
|
-
offset =
|
55
|
+
_align = operand[0] # TODO: alignment support?
|
56
|
+
offset = operand[1]
|
56
57
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
57
58
|
|
58
59
|
addr = runtime.stack.pop
|
@@ -71,8 +72,8 @@ module Wardite
|
|
71
72
|
|
72
73
|
|
73
74
|
when :i32_load16_s
|
74
|
-
_align =
|
75
|
-
offset =
|
75
|
+
_align = operand[0] # TODO: alignment support?
|
76
|
+
offset = operand[1]
|
76
77
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
77
78
|
|
78
79
|
addr = runtime.stack.pop
|
@@ -91,8 +92,8 @@ module Wardite
|
|
91
92
|
|
92
93
|
|
93
94
|
when :i32_load16_u
|
94
|
-
_align =
|
95
|
-
offset =
|
95
|
+
_align = operand[0] # TODO: alignment support?
|
96
|
+
offset = operand[1]
|
96
97
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
97
98
|
|
98
99
|
addr = runtime.stack.pop
|
@@ -111,8 +112,8 @@ module Wardite
|
|
111
112
|
|
112
113
|
|
113
114
|
when :i32_store
|
114
|
-
_align =
|
115
|
-
offset =
|
115
|
+
_align = operand[0] # TODO: alignment support?
|
116
|
+
offset = operand[1]
|
116
117
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
117
118
|
|
118
119
|
value = runtime.stack.pop
|
@@ -128,8 +129,8 @@ module Wardite
|
|
128
129
|
|
129
130
|
|
130
131
|
when :i32_store8
|
131
|
-
_align =
|
132
|
-
offset =
|
132
|
+
_align = operand[0] # TODO: alignment support?
|
133
|
+
offset = operand[1]
|
133
134
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
134
135
|
|
135
136
|
value = runtime.stack.pop
|
@@ -145,8 +146,8 @@ module Wardite
|
|
145
146
|
|
146
147
|
|
147
148
|
when :i32_store16
|
148
|
-
_align =
|
149
|
-
offset =
|
149
|
+
_align = operand[0] # TODO: alignment support?
|
150
|
+
offset = operand[1]
|
150
151
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
151
152
|
|
152
153
|
value = runtime.stack.pop
|
@@ -162,7 +163,7 @@ module Wardite
|
|
162
163
|
|
163
164
|
|
164
165
|
when :i32_const
|
165
|
-
const =
|
166
|
+
const = operand[0]
|
166
167
|
if !const.is_a?(Integer)
|
167
168
|
raise EvalError, "invalid type of operand"
|
168
169
|
end
|
@@ -464,8 +465,9 @@ module Wardite
|
|
464
465
|
|
465
466
|
|
466
467
|
else
|
467
|
-
|
468
|
+
return
|
468
469
|
end
|
470
|
+
return true
|
469
471
|
end
|
470
472
|
end
|
471
473
|
end
|
@@ -5,14 +5,15 @@ module Wardite
|
|
5
5
|
module Evaluator
|
6
6
|
# @rbs runtime: Runtime
|
7
7
|
# @rbs frame: Frame
|
8
|
-
# @rbs
|
9
|
-
# @rbs
|
10
|
-
|
11
|
-
|
8
|
+
# @rbs code: Symbol
|
9
|
+
# @rbs operand: Array[operandItem]
|
10
|
+
# @rbs return: bool?
|
11
|
+
def self.i64_eval_insn(runtime, frame, code, operand)
|
12
|
+
case code
|
12
13
|
|
13
14
|
when :i64_load
|
14
|
-
_align =
|
15
|
-
offset =
|
15
|
+
_align = operand[0] # TODO: alignment support?
|
16
|
+
offset = operand[1]
|
16
17
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
17
18
|
|
18
19
|
addr = runtime.stack.pop
|
@@ -31,8 +32,8 @@ module Wardite
|
|
31
32
|
|
32
33
|
|
33
34
|
when :i64_load8_s
|
34
|
-
_align =
|
35
|
-
offset =
|
35
|
+
_align = operand[0] # TODO: alignment support?
|
36
|
+
offset = operand[1]
|
36
37
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
37
38
|
|
38
39
|
addr = runtime.stack.pop
|
@@ -51,8 +52,8 @@ module Wardite
|
|
51
52
|
|
52
53
|
|
53
54
|
when :i64_load8_u
|
54
|
-
_align =
|
55
|
-
offset =
|
55
|
+
_align = operand[0] # TODO: alignment support?
|
56
|
+
offset = operand[1]
|
56
57
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
57
58
|
|
58
59
|
addr = runtime.stack.pop
|
@@ -71,8 +72,8 @@ module Wardite
|
|
71
72
|
|
72
73
|
|
73
74
|
when :i64_load16_s
|
74
|
-
_align =
|
75
|
-
offset =
|
75
|
+
_align = operand[0] # TODO: alignment support?
|
76
|
+
offset = operand[1]
|
76
77
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
77
78
|
|
78
79
|
addr = runtime.stack.pop
|
@@ -91,8 +92,8 @@ module Wardite
|
|
91
92
|
|
92
93
|
|
93
94
|
when :i64_load16_u
|
94
|
-
_align =
|
95
|
-
offset =
|
95
|
+
_align = operand[0] # TODO: alignment support?
|
96
|
+
offset = operand[1]
|
96
97
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
97
98
|
|
98
99
|
addr = runtime.stack.pop
|
@@ -111,8 +112,8 @@ module Wardite
|
|
111
112
|
|
112
113
|
|
113
114
|
when :i64_load32_s
|
114
|
-
_align =
|
115
|
-
offset =
|
115
|
+
_align = operand[0] # TODO: alignment support?
|
116
|
+
offset = operand[1]
|
116
117
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
117
118
|
|
118
119
|
addr = runtime.stack.pop
|
@@ -131,8 +132,8 @@ module Wardite
|
|
131
132
|
|
132
133
|
|
133
134
|
when :i64_load32_u
|
134
|
-
_align =
|
135
|
-
offset =
|
135
|
+
_align = operand[0] # TODO: alignment support?
|
136
|
+
offset = operand[1]
|
136
137
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
137
138
|
|
138
139
|
addr = runtime.stack.pop
|
@@ -151,8 +152,8 @@ module Wardite
|
|
151
152
|
|
152
153
|
|
153
154
|
when :i64_store
|
154
|
-
_align =
|
155
|
-
offset =
|
155
|
+
_align = operand[0] # TODO: alignment support?
|
156
|
+
offset = operand[1]
|
156
157
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
157
158
|
|
158
159
|
value = runtime.stack.pop
|
@@ -168,8 +169,8 @@ module Wardite
|
|
168
169
|
|
169
170
|
|
170
171
|
when :i64_store8
|
171
|
-
_align =
|
172
|
-
offset =
|
172
|
+
_align = operand[0] # TODO: alignment support?
|
173
|
+
offset = operand[1]
|
173
174
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
174
175
|
|
175
176
|
value = runtime.stack.pop
|
@@ -185,8 +186,8 @@ module Wardite
|
|
185
186
|
|
186
187
|
|
187
188
|
when :i64_store16
|
188
|
-
_align =
|
189
|
-
offset =
|
189
|
+
_align = operand[0] # TODO: alignment support?
|
190
|
+
offset = operand[1]
|
190
191
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
191
192
|
|
192
193
|
value = runtime.stack.pop
|
@@ -202,8 +203,8 @@ module Wardite
|
|
202
203
|
|
203
204
|
|
204
205
|
when :i64_store32
|
205
|
-
_align =
|
206
|
-
offset =
|
206
|
+
_align = operand[0] # TODO: alignment support?
|
207
|
+
offset = operand[1]
|
207
208
|
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
208
209
|
|
209
210
|
value = runtime.stack.pop
|
@@ -219,7 +220,7 @@ module Wardite
|
|
219
220
|
|
220
221
|
|
221
222
|
when :i64_const
|
222
|
-
const =
|
223
|
+
const = operand[0]
|
223
224
|
if !const.is_a?(Integer)
|
224
225
|
raise EvalError, "invalid type of operand"
|
225
226
|
end
|
@@ -521,8 +522,9 @@ module Wardite
|
|
521
522
|
|
522
523
|
|
523
524
|
else
|
524
|
-
|
525
|
+
return
|
525
526
|
end
|
527
|
+
return true
|
526
528
|
end
|
527
529
|
end
|
528
530
|
end
|
data/lib/wardite/cli/cli.rb
CHANGED
@@ -13,6 +13,8 @@ module Wardite
|
|
13
13
|
attr_reader :wasi #: bool
|
14
14
|
attr_reader :yjit #: bool
|
15
15
|
|
16
|
+
attr_reader :profile_file_path #: String?
|
17
|
+
|
16
18
|
# @rbs args: Array[String]
|
17
19
|
# @rbs return: void
|
18
20
|
def initialize(args)
|
@@ -37,6 +39,9 @@ module Wardite
|
|
37
39
|
opts.on("--yjit", "Enable yjit if available; setting WARDITE_YJIT_ON=1 has the same effect") {|_v|
|
38
40
|
@yjit = true
|
39
41
|
}
|
42
|
+
opts.on("--out-profile [file]", "Enable Vernier profiling and save to the file") {|v|
|
43
|
+
@profile_file_path = v
|
44
|
+
}
|
40
45
|
opts.on("FILE.wasm") { }
|
41
46
|
end
|
42
47
|
options.parse!(args)
|
@@ -77,6 +82,19 @@ module Wardite
|
|
77
82
|
|
78
83
|
# @rbs return: void
|
79
84
|
def run
|
85
|
+
if profile_file_path
|
86
|
+
require "vernier"
|
87
|
+
$stderr.puts "Activated Vernier profiling"
|
88
|
+
Vernier.profile(out: profile_file_path) do
|
89
|
+
__run
|
90
|
+
end
|
91
|
+
else
|
92
|
+
__run
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# @rbs return: void
|
97
|
+
def __run
|
80
98
|
if invoke
|
81
99
|
invoke_function
|
82
100
|
else
|
@@ -5,10 +5,11 @@ module Wardite
|
|
5
5
|
module Evaluator
|
6
6
|
# @rbs runtime: Runtime
|
7
7
|
# @rbs frame: Frame
|
8
|
-
# @rbs
|
9
|
-
# @rbs
|
10
|
-
|
11
|
-
|
8
|
+
# @rbs code: Symbol
|
9
|
+
# @rbs operand: Array[operandItem]
|
10
|
+
# @rbs return: bool?
|
11
|
+
def self.convert_eval_insn(runtime, frame, code, operand)
|
12
|
+
case code
|
12
13
|
|
13
14
|
when :i32_wrap_i64
|
14
15
|
from = runtime.stack.pop
|
@@ -331,8 +332,9 @@ module Wardite
|
|
331
332
|
|
332
333
|
|
333
334
|
else
|
334
|
-
|
335
|
+
return
|
335
336
|
end
|
337
|
+
return true
|
336
338
|
end
|
337
339
|
end
|
338
340
|
end
|