wardite 0.9.0 → 1.1.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/LICENSE +191 -0
- data/Makefile +14 -0
- data/README.md +107 -2
- data/Rakefile +5 -0
- data/Steepfile +1 -0
- data/assets/wardite.svg +12 -0
- data/benchmark/README.md +500 -0
- data/benchmark/build_call_profile.rb +42 -0
- data/benchmark/call_cost_worker.rb +27 -0
- data/benchmark/compare.rb +93 -0
- data/benchmark/compare_call_types.rb +212 -0
- data/benchmark/compare_dispatch.rb +123 -0
- data/benchmark/compare_engines.rb +119 -0
- data/benchmark/compare_optimizations.rb +139 -0
- data/benchmark/engine_phases.rb +30 -0
- data/benchmark/figures/README.md +35 -0
- data/benchmark/figures/plot_spinel_comparison.py +137 -0
- data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
- data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
- data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
- data/benchmark/figures/spinel_new_vm_summary.json +82 -0
- data/benchmark/float_m5.wat +42 -0
- data/benchmark/i32_call_arities.wat +89 -0
- data/benchmark/i32_calls.wat +174 -0
- data/benchmark/i32_memory.wat +58 -0
- data/benchmark/i32_mix.wat +80 -0
- data/benchmark/i64_m4.wat +55 -0
- data/benchmark/investigate_calls.rb +231 -0
- data/benchmark/investigate_generated_guards.rb +218 -0
- data/benchmark/m3_call_worker.rb +38 -0
- data/benchmark/measure_m1.rb +51 -0
- data/benchmark/measure_m2.rb +55 -0
- data/benchmark/measure_m3_calls.rb +89 -0
- data/benchmark/measure_m4.rb +134 -0
- data/benchmark/measure_m5_boundary.rb +41 -0
- data/benchmark/measure_mir_cache_verify.rb +58 -0
- data/benchmark/measure_ruby_wasm_cache_hit.rb +59 -0
- data/benchmark/measure_ruby_wasm_startup.rb +43 -0
- data/benchmark/measure_wasi_write.rb +75 -0
- data/benchmark/optimization_worker.rb +23 -0
- data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
- data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
- data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
- data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
- data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
- data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
- data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
- data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
- data/benchmark/results/efflorescence-m1-cruby.json +799 -0
- data/benchmark/results/efflorescence-m1-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
- data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
- data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-memory.json +408 -0
- data/benchmark/results/efflorescence-mir2-cache-integrity.json +390 -0
- data/benchmark/results/efflorescence-unboxed-globals.json +3451 -0
- data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
- data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
- data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
- data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
- data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
- data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
- data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
- data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
- data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
- data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
- data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
- data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
- data/benchmark/summarize_call_profile.py +54 -0
- data/benchmark/validate_m1_eh.rb +34 -0
- data/benchmark/validate_m2.rb +119 -0
- data/benchmark/validate_m3.rb +44 -0
- data/benchmark/validate_m4.rb +95 -0
- data/benchmark/validate_m5.rb +108 -0
- data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
- data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
- data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
- data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
- data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
- data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
- data/docs/adr/0007-efflorescence-ruby-wasm-phase1.md +75 -0
- data/docs/adr/0008-efflorescence-ruby-wasm-phase2.md +75 -0
- data/docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md +77 -0
- data/docs/adr/0010-efflorescence-mir2-cache-function-restore.md +80 -0
- data/docs/adr/0011-efflorescence-unboxed-globals.md +89 -0
- data/docs/adr/0012-efflorescence-startup-snapshot.md +173 -0
- data/docs/adr/0013-efflorescence-frame-acquisition.md +114 -0
- data/docs/efflorescence-call-arities.md +115 -0
- data/docs/efflorescence-call-investigation.md +155 -0
- data/docs/efflorescence-call-transfer.md +128 -0
- data/docs/efflorescence-call-types.md +102 -0
- data/docs/efflorescence-coverage-ja.md +351 -0
- data/docs/efflorescence-generated-c-guards.md +410 -0
- data/docs/efflorescence-inlining.md +165 -0
- data/docs/efflorescence-ja.md +155 -0
- data/docs/efflorescence-m1.md +160 -0
- data/docs/efflorescence-m2.md +233 -0
- data/docs/efflorescence-m3.md +131 -0
- data/docs/efflorescence-m4.md +88 -0
- data/docs/efflorescence-m5.md +82 -0
- data/docs/efflorescence-m6.md +95 -0
- data/docs/efflorescence-mir2-cache.md +123 -0
- data/docs/efflorescence-operand-decoding.md +105 -0
- data/docs/efflorescence-phase2-ja.md +225 -0
- data/docs/efflorescence-phase2.md +240 -0
- data/docs/efflorescence-register-initialization.md +75 -0
- data/docs/efflorescence-ruby-wasm-phase1.md +90 -0
- data/docs/efflorescence-spinel-linear-memory.md +72 -0
- data/docs/efflorescence-startup-snapshot.md +60 -0
- data/docs/efflorescence-unboxed-globals.md +61 -0
- data/docs/efflorescence.md +144 -0
- data/docs/spinel-string-aset-inplace-proposal.md +200 -0
- data/lib/wardite/alu_f32.generated.rb +11 -2
- data/lib/wardite/alu_f64.generated.rb +11 -2
- data/lib/wardite/alu_i32.generated.rb +54 -17
- data/lib/wardite/alu_i64.generated.rb +73 -31
- data/lib/wardite/cli/cli.rb +112 -29
- data/lib/wardite/const.rb +1 -0
- data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
- data/lib/wardite/efflorescence/inspection.rb +165 -0
- data/lib/wardite/efflorescence/ir.rb +1164 -0
- data/lib/wardite/efflorescence/mir_cache.rb +657 -0
- data/lib/wardite/efflorescence/optimizer.rb +580 -0
- data/lib/wardite/efflorescence/register_validation.rb +362 -0
- data/lib/wardite/efflorescence/snapshot.rb +229 -0
- data/lib/wardite/efflorescence/store_access.rb +366 -0
- data/lib/wardite/efflorescence/translator.rb +866 -0
- data/lib/wardite/efflorescence/vm.rb +1170 -0
- data/lib/wardite/efflorescence/wasi.rb +52 -0
- data/lib/wardite/efflorescence.rb +17 -0
- data/lib/wardite/errors.rb +20 -0
- data/lib/wardite/float_bits.rb +46 -0
- data/lib/wardite/instruction.rb +35 -4
- data/lib/wardite/leb128.rb +33 -12
- data/lib/wardite/load.rb +292 -143
- data/lib/wardite/value.rb +169 -175
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi/consts.rb +1 -0
- data/lib/wardite/wasi/spinel.rb +41 -0
- data/lib/wardite/wasi.rb +483 -268
- data/lib/wardite/wasm_module.rb +6 -3
- data/lib/wardite.rb +360 -98
- data/rbs_collection.lock.yaml +36 -96
- data/scripts/gen_alu.rb +121 -21
- data/scripts/verify_ruby_wasm.rb +70 -0
- data/sig/generated/wardite/cli/cli.rbs +23 -6
- data/sig/generated/wardite/const.rbs +2 -0
- data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +888 -0
- data/sig/generated/wardite/efflorescence/mir_cache.rbs +236 -0
- data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
- data/sig/generated/wardite/efflorescence/register_validation.rbs +104 -0
- data/sig/generated/wardite/efflorescence/snapshot.rbs +83 -0
- data/sig/generated/wardite/efflorescence/store_access.rbs +145 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +218 -0
- data/sig/generated/wardite/efflorescence/vm.rbs +240 -0
- data/sig/generated/wardite/efflorescence/wasi.rbs +34 -0
- data/sig/generated/wardite/errors.rbs +12 -0
- data/sig/generated/wardite/float_bits.rbs +30 -0
- data/sig/generated/wardite/instruction.rbs +22 -1
- data/sig/generated/wardite/leb128.rbs +3 -1
- data/sig/generated/wardite/load.rbs +59 -7
- data/sig/generated/wardite/value.rbs +70 -11
- data/sig/generated/wardite/wasi/consts.rbs +2 -0
- data/sig/generated/wardite/wasi/spinel.rbs +15 -0
- data/sig/generated/wardite/wasi.rbs +111 -4
- data/sig/generated/wardite.rbs +114 -13
- data/sig/mir_cache_stdlib.rbs +5 -0
- data/sig/vernier.rbs +2 -2
- data/spinel/README.md +30 -0
- data/spinel/bin/wardite.rb +6 -0
- data/spinel/patches/0001-io-buffer-string-view.patch +699 -0
- data/spinel/patches/0002-io-buffer-allocation-error.patch +47 -0
- data/spinel/spin.toml +7 -0
- metadata +154 -3
data/lib/wardite/load.rb
CHANGED
|
@@ -24,6 +24,16 @@ module Wardite
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
class TagSection < Section
|
|
28
|
+
attr_reader :type_indices #: Array[Integer]
|
|
29
|
+
|
|
30
|
+
def initialize
|
|
31
|
+
self.name = "Tag"
|
|
32
|
+
self.code = Const::SectionTag
|
|
33
|
+
@type_indices = []
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
27
37
|
class FunctionSection < Section
|
|
28
38
|
attr_accessor :func_indices #: Array[Integer]
|
|
29
39
|
|
|
@@ -104,11 +114,16 @@ module Wardite
|
|
|
104
114
|
end
|
|
105
115
|
|
|
106
116
|
class ElemSection < Section
|
|
117
|
+
# @rbs!
|
|
118
|
+
# type indexVector = Array[Integer]
|
|
119
|
+
|
|
107
120
|
attr_accessor :table_indices #: Array[Integer]
|
|
108
121
|
|
|
109
122
|
attr_accessor :table_offsets #: Array[Integer]
|
|
110
123
|
|
|
111
|
-
|
|
124
|
+
# Rows are also shared with Store#elements. Keep the precise RBS type via
|
|
125
|
+
# an alias rather than pinning Spinel's specialized nested-array layout.
|
|
126
|
+
attr_accessor :element_indices #: Array[indexVector]
|
|
112
127
|
|
|
113
128
|
# @rbs return: void
|
|
114
129
|
def initialize
|
|
@@ -127,13 +142,73 @@ module Wardite
|
|
|
127
142
|
|
|
128
143
|
attr_accessor :locals_type #: Array[Symbol]
|
|
129
144
|
|
|
130
|
-
|
|
145
|
+
attr_writer :instruction_bytes #: String?
|
|
146
|
+
|
|
147
|
+
attr_writer :type_section #: TypeSection?
|
|
131
148
|
|
|
132
149
|
# @rbs &blk: (CodeBody) -> void
|
|
133
150
|
# @rbs return: void
|
|
134
151
|
def initialize(&blk)
|
|
152
|
+
@locals_count = []
|
|
153
|
+
@locals_type = []
|
|
154
|
+
@body = [] #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
155
|
+
@instruction_bytes = nil
|
|
156
|
+
@type_section = nil
|
|
135
157
|
blk.call(self)
|
|
136
158
|
end
|
|
159
|
+
|
|
160
|
+
# @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
161
|
+
def body
|
|
162
|
+
check_features(@type_section, false) if @instruction_bytes
|
|
163
|
+
@body
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
167
|
+
# @rbs return: void
|
|
168
|
+
def body=(instructions)
|
|
169
|
+
@body = instructions
|
|
170
|
+
@instruction_bytes = nil
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# @rbs types: TypeSection?
|
|
174
|
+
# @rbs stack: bool
|
|
175
|
+
# @rbs return: void
|
|
176
|
+
def check_features(types, stack)
|
|
177
|
+
if stack && locals_type.include?(:exnref)
|
|
178
|
+
raise LoadError, "stack engine does not support exnref"
|
|
179
|
+
end
|
|
180
|
+
bytes = @instruction_bytes
|
|
181
|
+
instructions = bytes ? BinaryLoader.code_body(StringIO.new(bytes)) : @body
|
|
182
|
+
check_instructions(instructions, types, stack)
|
|
183
|
+
self.body = instructions if bytes
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
private
|
|
187
|
+
|
|
188
|
+
# @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
189
|
+
# @rbs types: TypeSection?
|
|
190
|
+
# @rbs stack: bool
|
|
191
|
+
# @rbs return: void
|
|
192
|
+
def check_instructions(instructions, types, stack)
|
|
193
|
+
instructions.each do |instruction|
|
|
194
|
+
if stack && [:try_table, :throw, :throw_ref].include?(instruction[1])
|
|
195
|
+
raise LoadError, "stack engine does not support EH"
|
|
196
|
+
end
|
|
197
|
+
instruction[2].each do |operand|
|
|
198
|
+
next unless operand.is_a?(Block)
|
|
199
|
+
index = operand.type_index
|
|
200
|
+
if index >= 0
|
|
201
|
+
params = types&.defined_types&.[](index)
|
|
202
|
+
results = types&.defined_results&.[](index)
|
|
203
|
+
raise LoadError, "invalid block type index #{index}" unless params && results
|
|
204
|
+
operand.resolve(params, results)
|
|
205
|
+
end
|
|
206
|
+
if stack && (index >= 0 || operand.result_types.include?(:exnref))
|
|
207
|
+
raise LoadError, "stack engine does not support indexed/reference block signatures"
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
137
212
|
end
|
|
138
213
|
|
|
139
214
|
attr_accessor :func_codes #:Array[CodeBody]
|
|
@@ -251,30 +326,60 @@ module Wardite
|
|
|
251
326
|
# @rbs buf: File|StringIO
|
|
252
327
|
# @rbs import_object: Hash[Symbol, wasmModuleSrc]
|
|
253
328
|
# @rbs enable_wasi: boolish
|
|
329
|
+
# @rbs engine: Symbol
|
|
330
|
+
# @rbs disabled_optimizations: Array[Symbol]
|
|
331
|
+
# @rbs mir_profile: bool
|
|
332
|
+
# @rbs mir_cache: String?
|
|
333
|
+
# @rbs mir_cache_verify: Symbol
|
|
254
334
|
# @rbs return: Instance
|
|
255
|
-
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true)
|
|
335
|
+
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true, engine: :stack, disabled_optimizations: [], mir_profile: false, mir_cache: nil, mir_cache_verify: :checksum)
|
|
256
336
|
start = Time.now.to_f #: Float
|
|
337
|
+
unless mir_cache_verify == :checksum || mir_cache_verify == :sha256
|
|
338
|
+
raise ArgumentError, "MIR cache verification must be checksum or sha256"
|
|
339
|
+
end
|
|
257
340
|
@buf = buf
|
|
341
|
+
cache = nil #: Efflorescence::MIRCache?
|
|
342
|
+
if mir_cache
|
|
343
|
+
raise ArgumentError, "MIR cache requires Efflorescence" unless engine == :efflorescence
|
|
344
|
+
unless mir_profile
|
|
345
|
+
require "wardite/efflorescence/mir_cache" unless RUBY_ENGINE == "spinel"
|
|
346
|
+
# Hash the same bytes that the decoder will see, even if the file changes.
|
|
347
|
+
bytes = buf.read || "".b
|
|
348
|
+
configuration = Efflorescence::Configuration.new(disabled_optimizations)
|
|
349
|
+
disabled_optimizations = configuration.disabled
|
|
350
|
+
cache = Efflorescence::MIRCache.new(mir_cache, bytes, configuration, verify: mir_cache_verify)
|
|
351
|
+
@buf = StringIO.new(bytes)
|
|
352
|
+
end
|
|
353
|
+
end
|
|
258
354
|
|
|
259
355
|
version = preamble
|
|
260
|
-
sections_ = sections
|
|
356
|
+
sections_ = sections(!cache.nil?)
|
|
357
|
+
@buf = buf if cache
|
|
261
358
|
|
|
262
359
|
wasi_env = nil
|
|
263
|
-
if enable_wasi
|
|
264
|
-
|
|
265
|
-
wasi_env =
|
|
360
|
+
if enable_wasi && sections_.any? { |section| section.is_a?(ImportSection) &&
|
|
361
|
+
section.imports.any? { |import| import.module_name == "wasi_snapshot_preview1" } }
|
|
362
|
+
wasi_env = if RUBY_ENGINE == "spinel"
|
|
363
|
+
require "wardite/wasi"
|
|
364
|
+
Wardite::WasiSnapshotPreview1.new
|
|
365
|
+
elsif engine == :efflorescence
|
|
366
|
+
require "wardite/efflorescence/wasi"
|
|
367
|
+
Wardite::Efflorescence::WasiSnapshotPreview1.new
|
|
368
|
+
else
|
|
369
|
+
require "wardite/wasi"
|
|
370
|
+
Wardite::WasiSnapshotPreview1.new
|
|
371
|
+
end
|
|
266
372
|
import_object[:wasi_snapshot_preview1] = wasi_env
|
|
267
373
|
end
|
|
268
374
|
|
|
269
|
-
return Instance.new(import_object
|
|
375
|
+
return Instance.new(import_object, engine: engine, disabled_optimizations: disabled_optimizations,
|
|
376
|
+
mir_profile: mir_profile, mir_cache: cache) do |i|
|
|
270
377
|
i.version = version
|
|
271
378
|
i.sections = sections_
|
|
272
|
-
|
|
273
|
-
i.wasi = wasi_env
|
|
274
|
-
end
|
|
379
|
+
i.wasi = wasi_env
|
|
275
380
|
end
|
|
276
381
|
ensure
|
|
277
|
-
$stderr.puts "load_from_buffer: #{Time.now.to_f - start}" if ENV['
|
|
382
|
+
$stderr.puts "load_from_buffer: #{Time.now.to_f - start}" if ENV['WARDITE_TRACE']
|
|
278
383
|
end
|
|
279
384
|
|
|
280
385
|
# @rbs return: Integer
|
|
@@ -291,17 +396,16 @@ module Wardite
|
|
|
291
396
|
if !vstr
|
|
292
397
|
raise LoadError, "buffer too short"
|
|
293
398
|
end
|
|
294
|
-
version = vstr.
|
|
295
|
-
|
|
296
|
-
.inject(0) {|dest, (c, i)| dest | (c.ord << i*8) }
|
|
297
|
-
if version != 1
|
|
399
|
+
version = vstr.unpack1("V")
|
|
400
|
+
if !version.is_a?(Integer) || version != 1
|
|
298
401
|
raise LoadError, "unsupported version: #{version}"
|
|
299
402
|
end
|
|
300
403
|
version
|
|
301
404
|
end
|
|
302
405
|
|
|
406
|
+
# @rbs defer_code: bool
|
|
303
407
|
# @rbs return: Array[Section]
|
|
304
|
-
def self.sections
|
|
408
|
+
def self.sections(defer_code = false)
|
|
305
409
|
sections = [] #: Array[Section]
|
|
306
410
|
|
|
307
411
|
loop do
|
|
@@ -316,6 +420,8 @@ module Wardite
|
|
|
316
420
|
type_section
|
|
317
421
|
when Wardite::SectionImport
|
|
318
422
|
import_section
|
|
423
|
+
when Wardite::SectionTag
|
|
424
|
+
tag_section
|
|
319
425
|
when Wardite::SectionFunction
|
|
320
426
|
function_section
|
|
321
427
|
when Wardite::SectionTable
|
|
@@ -331,7 +437,7 @@ module Wardite
|
|
|
331
437
|
when Wardite::SectionElement
|
|
332
438
|
elem_section
|
|
333
439
|
when Wardite::SectionCode
|
|
334
|
-
code_section
|
|
440
|
+
code_section(defer_code)
|
|
335
441
|
when Wardite::SectionData
|
|
336
442
|
data_section
|
|
337
443
|
when Wardite::Const::SectionDataCount
|
|
@@ -368,6 +474,8 @@ module Wardite
|
|
|
368
474
|
arg = [] #: Array[Symbol]
|
|
369
475
|
arglen.times do
|
|
370
476
|
case ty = assert_read(sbuf, 1)&.ord
|
|
477
|
+
when 0x69
|
|
478
|
+
arg << :exnref
|
|
371
479
|
when 0x7f
|
|
372
480
|
arg << :i32
|
|
373
481
|
when 0x7e
|
|
@@ -377,7 +485,7 @@ module Wardite
|
|
|
377
485
|
when 0x7c
|
|
378
486
|
arg << :f64
|
|
379
487
|
else
|
|
380
|
-
raise
|
|
488
|
+
raise LoadError, "unsupported value type: #{ty.inspect}"
|
|
381
489
|
end
|
|
382
490
|
end
|
|
383
491
|
dest.defined_types << arg
|
|
@@ -386,6 +494,8 @@ module Wardite
|
|
|
386
494
|
ret = [] #: Array[Symbol]
|
|
387
495
|
retlen.times do
|
|
388
496
|
case ty = assert_read(sbuf, 1)&.ord
|
|
497
|
+
when 0x69
|
|
498
|
+
ret << :exnref
|
|
389
499
|
when 0x7f
|
|
390
500
|
ret << :i32
|
|
391
501
|
when 0x7e
|
|
@@ -395,7 +505,7 @@ module Wardite
|
|
|
395
505
|
when 0x7c
|
|
396
506
|
ret << :f64
|
|
397
507
|
else
|
|
398
|
-
raise
|
|
508
|
+
raise LoadError, "unsupported value type: #{ty.inspect}"
|
|
399
509
|
end
|
|
400
510
|
end
|
|
401
511
|
dest.defined_results << ret
|
|
@@ -404,6 +514,19 @@ module Wardite
|
|
|
404
514
|
dest
|
|
405
515
|
end
|
|
406
516
|
|
|
517
|
+
# @rbs return: TagSection
|
|
518
|
+
def self.tag_section
|
|
519
|
+
dest = TagSection.new
|
|
520
|
+
dest.size = fetch_uleb128(@buf)
|
|
521
|
+
sbuf = StringIO.new(assert_read(@buf, dest.size))
|
|
522
|
+
fetch_uleb128(sbuf).times do
|
|
523
|
+
raise LoadError, "unsupported tag attribute" unless assert_read(sbuf, 1).ord == 0
|
|
524
|
+
dest.type_indices << fetch_uleb128(sbuf)
|
|
525
|
+
end
|
|
526
|
+
raise LoadError, "trailing tag section data" unless sbuf.eof?
|
|
527
|
+
dest
|
|
528
|
+
end
|
|
529
|
+
|
|
407
530
|
# @rbs return: ImportSection
|
|
408
531
|
def self.import_section
|
|
409
532
|
dest = ImportSection.new
|
|
@@ -423,6 +546,8 @@ module Wardite
|
|
|
423
546
|
raise "[BUG] empty unpacked string" # guard rbs
|
|
424
547
|
end
|
|
425
548
|
|
|
549
|
+
raise LoadError, "tag imports are not supported" if kind == 4
|
|
550
|
+
raise LoadError, "unsupported import kind #{kind} for #{module_name}.#{name}" unless kind == 0
|
|
426
551
|
index = fetch_uleb128(sbuf)
|
|
427
552
|
dest.add_desc do |desc|
|
|
428
553
|
desc.module_name = module_name
|
|
@@ -440,22 +565,25 @@ module Wardite
|
|
|
440
565
|
dest = MemorySection.new
|
|
441
566
|
size = fetch_uleb128(@buf)
|
|
442
567
|
dest.size = size
|
|
443
|
-
sbuf = StringIO.new(@buf
|
|
568
|
+
sbuf = StringIO.new(assert_read(@buf, size))
|
|
444
569
|
|
|
445
570
|
len = fetch_uleb128(sbuf)
|
|
446
|
-
if len
|
|
447
|
-
raise LoadError, "
|
|
571
|
+
if len > 1
|
|
572
|
+
raise LoadError, "only one memory is supported: #{len}"
|
|
448
573
|
end
|
|
449
574
|
len.times do |i|
|
|
450
575
|
flags = fetch_uleb128(sbuf)
|
|
576
|
+
unless flags == 0 || flags == 1
|
|
577
|
+
raise LoadError, "shared/memory64/custom-page memory limits are not supported"
|
|
578
|
+
end
|
|
451
579
|
min = fetch_uleb128(sbuf)
|
|
452
|
-
|
|
453
|
-
max
|
|
454
|
-
|
|
455
|
-
max = fetch_uleb128(sbuf)
|
|
580
|
+
max = flags == 1 ? fetch_uleb128(sbuf) : nil
|
|
581
|
+
if min > 65536 || (max && (max > 65536 || max < min))
|
|
582
|
+
raise LoadError, "invalid memory32 limits"
|
|
456
583
|
end
|
|
457
584
|
dest.limits << [min, max]
|
|
458
585
|
end
|
|
586
|
+
raise LoadError, "trailing memory section bytes" unless sbuf.eof?
|
|
459
587
|
dest
|
|
460
588
|
end
|
|
461
589
|
|
|
@@ -480,26 +608,23 @@ module Wardite
|
|
|
480
608
|
len = fetch_uleb128(sbuf)
|
|
481
609
|
len.times do |i|
|
|
482
610
|
etype = fetch_uleb128(sbuf)
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
code = fetch_insn_while_end(sbuf)
|
|
488
|
-
ops = code_body(StringIO.new(code))
|
|
489
|
-
offset = decode_expr(ops)
|
|
490
|
-
dest.table_offsets << offset
|
|
611
|
+
unless etype == 0 || etype == 2
|
|
612
|
+
raise LoadError, "unsupported element segment kind #{etype}"
|
|
613
|
+
end
|
|
614
|
+
dest.table_indices << (etype == 0 ? 0 : fetch_uleb128(sbuf))
|
|
491
615
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
end
|
|
498
|
-
dest.element_indices << elms
|
|
499
|
-
else
|
|
500
|
-
raise NotImplementedError, "element section type #{etype} is a TODO!"
|
|
616
|
+
code = fetch_insn_while_end(sbuf)
|
|
617
|
+
ops = code_body(StringIO.new(code))
|
|
618
|
+
dest.table_offsets << decode_expr(ops)
|
|
619
|
+
if etype == 2 && assert_read(sbuf, 1).ord != 0
|
|
620
|
+
raise LoadError, "unsupported element type"
|
|
501
621
|
end
|
|
622
|
+
|
|
623
|
+
elms = [] #: Array[Integer]
|
|
624
|
+
fetch_uleb128(sbuf).times { elms << fetch_uleb128(sbuf) }
|
|
625
|
+
dest.element_indices << elms
|
|
502
626
|
end
|
|
627
|
+
raise LoadError, "trailing element section data" unless sbuf.eof?
|
|
503
628
|
dest
|
|
504
629
|
end
|
|
505
630
|
|
|
@@ -512,15 +637,25 @@ module Wardite
|
|
|
512
637
|
|
|
513
638
|
len = fetch_uleb128(sbuf)
|
|
514
639
|
len.times do |i|
|
|
515
|
-
|
|
516
|
-
gtype = Op.i2type(typeb)
|
|
640
|
+
gtype = Op.i2type(assert_read(sbuf, 1).ord)
|
|
517
641
|
mut = sbuf.read 1
|
|
518
642
|
if !mut
|
|
519
643
|
raise LoadError, "global section too short"
|
|
520
644
|
end
|
|
645
|
+
unless mut.ord == 0 || mut.ord == 1
|
|
646
|
+
raise LoadError, "unsupported global mutability flags"
|
|
647
|
+
end
|
|
521
648
|
|
|
522
649
|
code = fetch_insn_while_end(sbuf)
|
|
523
650
|
ops = code_body(StringIO.new(code))
|
|
651
|
+
expected = case gtype
|
|
652
|
+
when :i32 then :i32_const
|
|
653
|
+
when :i64 then :i64_const
|
|
654
|
+
when :f32 then :f32_const
|
|
655
|
+
when :f64 then :f64_const
|
|
656
|
+
else raise LoadError, "unsupported global type #{gtype}"
|
|
657
|
+
end
|
|
658
|
+
raise LoadError, "global initializer type mismatch" unless ops.first&.[](1) == expected
|
|
524
659
|
value = decode_global_expr(ops)
|
|
525
660
|
|
|
526
661
|
global = GlobalSection::Global.new do |g|
|
|
@@ -573,43 +708,46 @@ module Wardite
|
|
|
573
708
|
dest
|
|
574
709
|
end
|
|
575
710
|
|
|
711
|
+
# @rbs defer_code: bool
|
|
576
712
|
# @rbs return: CodeSection
|
|
577
|
-
def self.code_section
|
|
713
|
+
def self.code_section(defer_code = false)
|
|
578
714
|
dest = CodeSection.new
|
|
579
715
|
size = fetch_uleb128(@buf)
|
|
580
716
|
dest.size = size
|
|
581
|
-
sbuf = StringIO.new(@buf
|
|
717
|
+
sbuf = StringIO.new(assert_read(@buf, size))
|
|
582
718
|
|
|
583
719
|
len = fetch_uleb128(sbuf)
|
|
584
|
-
len.times
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
720
|
+
len.times { dest.func_codes << read_function_body(sbuf, defer_code) }
|
|
721
|
+
dest
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
# @rbs sbuf: StringIO
|
|
725
|
+
# @rbs defer_code: bool
|
|
726
|
+
# @rbs return: CodeSection::CodeBody
|
|
727
|
+
def self.read_function_body(sbuf, defer_code = false)
|
|
728
|
+
ilen = fetch_uleb128(sbuf)
|
|
729
|
+
code = assert_read(sbuf, ilen)
|
|
730
|
+
last_code = code[-1]
|
|
731
|
+
if ! last_code
|
|
732
|
+
raise "[BUG] empty code fetched" # guard for steep check
|
|
733
|
+
end
|
|
734
|
+
if last_code.ord != 0x0b
|
|
735
|
+
$stderr.puts "warning: instruction not ended with inst end(0x0b): 0x0#{last_code.ord}"
|
|
736
|
+
end
|
|
737
|
+
cbuf = StringIO.new(code)
|
|
738
|
+
CodeSection::CodeBody.new do |body|
|
|
597
739
|
locals_len = fetch_uleb128(cbuf)
|
|
598
|
-
locals_len
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
locals_type << Op.i2type(value_type || -1)
|
|
740
|
+
while locals_len > 0
|
|
741
|
+
body.locals_count << fetch_uleb128(cbuf)
|
|
742
|
+
body.locals_type << Op.i2type(assert_read(cbuf, 1).ord)
|
|
743
|
+
locals_len -= 1
|
|
603
744
|
end
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
b.locals_type = locals_type
|
|
609
|
-
b.body = body
|
|
745
|
+
if defer_code
|
|
746
|
+
body.instruction_bytes = (cbuf.read || "".b).freeze
|
|
747
|
+
else
|
|
748
|
+
body.body = code_body(cbuf)
|
|
610
749
|
end
|
|
611
750
|
end
|
|
612
|
-
dest
|
|
613
751
|
end
|
|
614
752
|
|
|
615
753
|
# @rbs buf: StringIO
|
|
@@ -631,44 +769,38 @@ module Wardite
|
|
|
631
769
|
end
|
|
632
770
|
operand << ope.ord
|
|
633
771
|
when :u32
|
|
634
|
-
|
|
772
|
+
value = fetch_uleb128(buf)
|
|
773
|
+
if operand.empty? && c.ord >= 0x28 && c.ord <= 0x3e && value >= 64
|
|
774
|
+
raise LoadError, "multi-memory memargs are not supported"
|
|
775
|
+
end
|
|
776
|
+
operand << value
|
|
635
777
|
when :u32_vec
|
|
636
778
|
len = fetch_uleb128(buf)
|
|
637
779
|
vec = [] #: Array[Integer]
|
|
638
780
|
len.times do
|
|
639
781
|
vec << fetch_uleb128(buf)
|
|
640
782
|
end
|
|
641
|
-
operand << vec
|
|
783
|
+
operand << OperandVector.new(vec)
|
|
642
784
|
when :i32
|
|
643
|
-
operand << fetch_sleb128(buf)
|
|
785
|
+
operand << fetch_sleb128(buf, width: 32)
|
|
644
786
|
when :i64
|
|
645
|
-
operand << fetch_sleb128(buf,
|
|
646
|
-
when :f32
|
|
647
|
-
data = buf
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
raise "String#unpack is broken" if !v.is_a?(Float)
|
|
661
|
-
operand << v
|
|
662
|
-
when :u8_block
|
|
663
|
-
block_ope = buf.read 1
|
|
664
|
-
if ! block_ope
|
|
665
|
-
raise LoadError, "buffer too short for if"
|
|
666
|
-
end
|
|
667
|
-
if block_ope.ord == 0x40
|
|
668
|
-
operand << Block.void
|
|
669
|
-
else
|
|
670
|
-
operand << Block.new([block_ope.ord])
|
|
787
|
+
operand << fetch_sleb128(buf, width: 64)
|
|
788
|
+
when :f32, :f64
|
|
789
|
+
data = assert_read(buf, typ == :f32 ? 4 : 8)
|
|
790
|
+
operand << FloatImmediate.new(typ, FloatBits.read(typ, data))
|
|
791
|
+
when :u8_block, :blocktype
|
|
792
|
+
value = read_blocktype(buf)
|
|
793
|
+
operand << value
|
|
794
|
+
when :catches
|
|
795
|
+
clauses = [] #: Array[Integer]
|
|
796
|
+
fetch_uleb128(buf).times do
|
|
797
|
+
kind = assert_read(buf, 1).ord
|
|
798
|
+
raise LoadError, "invalid catch kind #{kind}" unless kind <= 3
|
|
799
|
+
tag = kind <= 1 ? fetch_uleb128(buf) : -1
|
|
800
|
+
depth = fetch_uleb128(buf)
|
|
801
|
+
clauses << kind << tag << depth
|
|
671
802
|
end
|
|
803
|
+
operand << OperandVector.new(clauses)
|
|
672
804
|
else
|
|
673
805
|
$stderr.puts "warning: unknown type #{typ.inspect}. defaulting to u32"
|
|
674
806
|
operand << fetch_uleb128(buf)
|
|
@@ -677,7 +809,7 @@ module Wardite
|
|
|
677
809
|
|
|
678
810
|
# HINT: [namespace, code, operand, else_pos, end_pos]
|
|
679
811
|
dest << [namespace, code, operand, nil, nil]
|
|
680
|
-
if code == :block || code == :loop || code == :if
|
|
812
|
+
if code == :block || code == :loop || code == :if || code == :try_table
|
|
681
813
|
branching_stack << [code, dest.size - 1, -1, -1]
|
|
682
814
|
elsif code == :else
|
|
683
815
|
if branching_stack.empty?
|
|
@@ -697,12 +829,13 @@ module Wardite
|
|
|
697
829
|
end
|
|
698
830
|
end
|
|
699
831
|
|
|
832
|
+
raise LoadError, "unterminated structured control" unless branching_stack.empty?
|
|
700
833
|
fixed_stack.each do |(sym, begin_idx, else_idx, end_idx)|
|
|
701
834
|
if end_idx == -1
|
|
702
835
|
raise "broken sequence: branching without end"
|
|
703
836
|
end
|
|
704
837
|
case sym
|
|
705
|
-
when :block, :loop
|
|
838
|
+
when :block, :loop, :try_table
|
|
706
839
|
dest[begin_idx][-1] = end_idx
|
|
707
840
|
when :if
|
|
708
841
|
dest[begin_idx][-2] = else_idx == -1 ? end_idx : else_idx
|
|
@@ -720,6 +853,24 @@ module Wardite
|
|
|
720
853
|
raise e
|
|
721
854
|
end
|
|
722
855
|
|
|
856
|
+
# Decode s33, distinguishing the one-byte value/void forms from indices.
|
|
857
|
+
# @rbs buf: StringIO
|
|
858
|
+
# @rbs return: Block
|
|
859
|
+
def self.read_blocktype(buf)
|
|
860
|
+
first = buf.pos
|
|
861
|
+
value = fetch_sleb128(buf, max_level: 4)
|
|
862
|
+
raise LoadError, "blocktype exceeds s33" unless value >= -4294967296 && value <= 4294967295
|
|
863
|
+
if value < 0 && buf.pos - first != 1
|
|
864
|
+
raise LoadError, "value/void blocktypes must use their single-byte encoding"
|
|
865
|
+
end
|
|
866
|
+
return Block.void if value == -64
|
|
867
|
+
return Block.new(nil, type_index: value) if value >= 0
|
|
868
|
+
raise LoadError, "invalid block value type" if value < -64
|
|
869
|
+
code = value & 0x7f
|
|
870
|
+
Op.i2type(code) # Reject unsupported/nonnullable reference declarations.
|
|
871
|
+
Block.new([code])
|
|
872
|
+
end
|
|
873
|
+
|
|
723
874
|
# @rbs c: String
|
|
724
875
|
# @rbs buf: StringIO
|
|
725
876
|
# @rbs return: [Symbol, Symbol, Array[Symbol]]
|
|
@@ -732,8 +883,8 @@ module Wardite
|
|
|
732
883
|
namespace = Op::FC_OPERANDS[lower] || :default
|
|
733
884
|
return [namespace, sym, Op.operand_of(sym)]
|
|
734
885
|
end
|
|
735
|
-
namespace = Op::NAMESPACES[ord] || raise("unsupported code: #{ord}")
|
|
736
|
-
return [namespace, code, Op
|
|
886
|
+
namespace = Op::NAMESPACES[ord] || raise(LoadError, "unsupported code: #{ord}")
|
|
887
|
+
return [namespace, code, Op.operand_of(code)]
|
|
737
888
|
end
|
|
738
889
|
|
|
739
890
|
# @rbs return: DataSection
|
|
@@ -741,36 +892,32 @@ module Wardite
|
|
|
741
892
|
dest = DataSection.new
|
|
742
893
|
size = fetch_uleb128(@buf)
|
|
743
894
|
dest.size = size
|
|
744
|
-
sbuf = StringIO.new(@buf
|
|
895
|
+
sbuf = StringIO.new(assert_read(@buf, size))
|
|
745
896
|
|
|
746
897
|
len = fetch_uleb128(sbuf)
|
|
747
898
|
len.times do |i|
|
|
748
899
|
data_type = fetch_uleb128(sbuf)
|
|
749
900
|
case data_type
|
|
750
|
-
when 0x0
|
|
751
|
-
#
|
|
901
|
+
when 0x0, 0x2
|
|
902
|
+
# Active explicit-memory segments still target memory 0 in M2.
|
|
903
|
+
memory_index = data_type == 2 ? fetch_uleb128(sbuf) : 0
|
|
904
|
+
raise LoadError, "only memory 0 is supported" unless memory_index == 0
|
|
752
905
|
code = fetch_insn_while_end(sbuf)
|
|
753
906
|
ops = code_body(StringIO.new(code))
|
|
754
907
|
offset = decode_expr(ops)
|
|
755
908
|
len = fetch_uleb128(sbuf)
|
|
756
|
-
data = sbuf
|
|
757
|
-
if !data
|
|
758
|
-
raise LoadError, "buffer too short"
|
|
759
|
-
end
|
|
909
|
+
data = assert_read(sbuf, len).b
|
|
760
910
|
segment = DataSection::Segment.new do |seg|
|
|
761
911
|
seg.mode = :active
|
|
762
|
-
seg.mem_index =
|
|
763
|
-
seg.offset = offset
|
|
912
|
+
seg.mem_index = memory_index
|
|
913
|
+
seg.offset = offset & 0xffffffff
|
|
764
914
|
seg.data = data
|
|
765
915
|
end
|
|
766
916
|
dest.segments << segment
|
|
767
917
|
when 0x1
|
|
768
918
|
# passive
|
|
769
919
|
dsize = fetch_uleb128(sbuf)
|
|
770
|
-
data = sbuf
|
|
771
|
-
if !data
|
|
772
|
-
raise LoadError, "data too short"
|
|
773
|
-
end
|
|
920
|
+
data = assert_read(sbuf, dsize).b
|
|
774
921
|
segment = DataSection::Segment.new do |seg|
|
|
775
922
|
seg.mode = :passive
|
|
776
923
|
seg.mem_index = 0 # unused
|
|
@@ -778,17 +925,21 @@ module Wardite
|
|
|
778
925
|
seg.data = data
|
|
779
926
|
end
|
|
780
927
|
dest.segments << segment
|
|
928
|
+
else
|
|
929
|
+
raise LoadError, "unsupported data segment flags #{data_type}"
|
|
781
930
|
end
|
|
782
931
|
end
|
|
932
|
+
raise LoadError, "trailing data section bytes" unless sbuf.eof?
|
|
783
933
|
dest
|
|
784
934
|
end
|
|
785
935
|
|
|
786
936
|
# @rbs return: DataCountSection
|
|
787
937
|
def self.data_count_section
|
|
788
938
|
size = fetch_uleb128(@buf)
|
|
789
|
-
sbuf = StringIO.new(@buf
|
|
939
|
+
sbuf = StringIO.new(assert_read(@buf, size))
|
|
790
940
|
count = fetch_uleb128(sbuf)
|
|
791
941
|
dest = DataCountSection.new(count)
|
|
942
|
+
raise LoadError, "trailing data count bytes" unless sbuf.eof?
|
|
792
943
|
dest.size = size
|
|
793
944
|
dest
|
|
794
945
|
end
|
|
@@ -796,18 +947,19 @@ module Wardite
|
|
|
796
947
|
# @rbs sbuf: StringIO
|
|
797
948
|
# @rbs return: String
|
|
798
949
|
def self.fetch_insn_while_end(sbuf)
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
950
|
+
first = sbuf.pos
|
|
951
|
+
opcode = assert_read(sbuf, 1).ord
|
|
952
|
+
case opcode
|
|
953
|
+
when 0x41 then fetch_sleb128(sbuf, width: 32)
|
|
954
|
+
when 0x42 then fetch_sleb128(sbuf, width: 64)
|
|
955
|
+
when 0x43 then assert_read(sbuf, 4)
|
|
956
|
+
when 0x44 then assert_read(sbuf, 8)
|
|
957
|
+
else raise LoadError, "unsupported constant expression"
|
|
958
|
+
end
|
|
959
|
+
raise LoadError, "constant expression requires end" unless assert_read(sbuf, 1).ord == 0x0b
|
|
960
|
+
length = sbuf.pos - first
|
|
961
|
+
sbuf.pos = first
|
|
962
|
+
assert_read(sbuf, length)
|
|
811
963
|
end
|
|
812
964
|
|
|
813
965
|
# @rbs ops: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
@@ -853,16 +1005,12 @@ module Wardite
|
|
|
853
1005
|
return I64(arg)
|
|
854
1006
|
when :f32_const
|
|
855
1007
|
arg = op[2][0]
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
end
|
|
859
|
-
return F32(arg)
|
|
1008
|
+
raise "Invalid definition of operand" unless arg.is_a?(FloatImmediate)
|
|
1009
|
+
return F32.from_bits(arg.bits)
|
|
860
1010
|
when :f64_const
|
|
861
1011
|
arg = op[2][0]
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
end
|
|
865
|
-
return F64(arg)
|
|
1012
|
+
raise "Invalid definition of operand" unless arg.is_a?(FloatImmediate)
|
|
1013
|
+
return F64.from_bits(arg.bits)
|
|
866
1014
|
else
|
|
867
1015
|
raise "Unimplemented offset op: #{op.inspect}"
|
|
868
1016
|
end
|
|
@@ -885,6 +1033,7 @@ module Wardite
|
|
|
885
1033
|
raise "[BUG] empty unpacked string" # guard rbs
|
|
886
1034
|
end
|
|
887
1035
|
|
|
1036
|
+
raise LoadError, "tag exports are not supported" if kind == 4
|
|
888
1037
|
index = fetch_uleb128(sbuf)
|
|
889
1038
|
dest.add_desc do |desc|
|
|
890
1039
|
desc.name = name
|
|
@@ -905,7 +1054,7 @@ module Wardite
|
|
|
905
1054
|
nil
|
|
906
1055
|
end
|
|
907
1056
|
|
|
908
|
-
# @rbs sbuf: StringIO
|
|
1057
|
+
# @rbs sbuf: File|StringIO
|
|
909
1058
|
# @rbs n: Integer
|
|
910
1059
|
# @rbs return: String
|
|
911
1060
|
def self.assert_read(sbuf, n)
|
|
@@ -913,10 +1062,10 @@ module Wardite
|
|
|
913
1062
|
if !ret
|
|
914
1063
|
raise LoadError, "too short section size"
|
|
915
1064
|
end
|
|
916
|
-
if ret.
|
|
1065
|
+
if ret.bytesize != n
|
|
917
1066
|
raise LoadError, "too short section size"
|
|
918
1067
|
end
|
|
919
1068
|
ret
|
|
920
1069
|
end
|
|
921
1070
|
end
|
|
922
|
-
end
|
|
1071
|
+
end
|