wardite 1.2.0 → 1.2.1

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/benchmark/README.md +8 -0
  3. data/benchmark/compare_mir_generation_builds.rb +66 -0
  4. data/benchmark/generate_mir_generation_fixtures.rb +44 -0
  5. data/benchmark/measure_mir_generation.rb +52 -0
  6. data/benchmark/mir_copy_worker.rb +29 -0
  7. data/benchmark/mir_generation_worker.rb +50 -0
  8. data/benchmark/prepare_mir_generation_profile.rb +80 -0
  9. data/benchmark/profile_inline_snapshots.rb +63 -0
  10. data/benchmark/profile_mir_generation_allocations.rb +73 -0
  11. data/benchmark/results/mir-generation-adr0014.json +1779 -0
  12. data/benchmark/results/mir-generation-adr0015.json +3132 -0
  13. data/benchmark/results/mir-generation-allocations.json +236 -0
  14. data/benchmark/results/mir-generation-coarse.json +909 -0
  15. data/benchmark/results/mir-generation-control.json +463 -0
  16. data/benchmark/results/mir-generation-detail.json +387 -0
  17. data/benchmark/results/mir-generation-scaling.json +2945 -0
  18. data/docs/adr/0014-efflorescence-mir-build-validation-and-decoding.md +136 -0
  19. data/docs/adr/0015-efflorescence-selective-inline-snapshots.md +150 -0
  20. data/docs/adr/0016-efflorescence-generation-tagged-copy-propagation.md +163 -0
  21. data/docs/efflorescence-mir-build-validation-and-decoding-results.md +93 -0
  22. data/docs/efflorescence-mir-generation-implementation.md +77 -0
  23. data/docs/efflorescence-mir-generation-performance.md +184 -0
  24. data/docs/efflorescence-selective-inline-snapshots-results.md +92 -0
  25. data/lib/wardite/efflorescence/ir.rb +119 -37
  26. data/lib/wardite/efflorescence/optimizer.rb +65 -15
  27. data/lib/wardite/efflorescence/register_validation.rb +162 -32
  28. data/lib/wardite/instruction.rb +42 -1
  29. data/lib/wardite/leb128.rb +2 -5
  30. data/lib/wardite/load.rb +151 -73
  31. data/lib/wardite/version.rb +1 -1
  32. data/sig/generated/wardite/efflorescence/ir.rbs +29 -1
  33. data/sig/generated/wardite/efflorescence/optimizer.rbs +27 -3
  34. data/sig/generated/wardite/efflorescence/register_validation.rbs +45 -4
  35. data/sig/generated/wardite/instruction.rbs +23 -0
  36. data/sig/generated/wardite/load.rbs +61 -8
  37. metadata +23 -1
data/lib/wardite/load.rb CHANGED
@@ -136,14 +136,28 @@ module Wardite
136
136
  end
137
137
  end
138
138
 
139
+ # The loader owns this result until a CodeBody exposes its mutable instructions.
140
+ class DecodedBody
141
+ attr_reader :instructions #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
142
+ attr_reader :blocks #: Array[Block]
143
+ attr_reader :has_eh_instructions #: bool
144
+
145
+ # @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
146
+ # @rbs blocks: Array[Block]
147
+ # @rbs has_eh_instructions: bool
148
+ def initialize(instructions, blocks, has_eh_instructions)
149
+ @instructions = instructions
150
+ @blocks = blocks
151
+ @has_eh_instructions = has_eh_instructions
152
+ end
153
+ end
154
+
139
155
  class CodeSection < Section
140
156
  class CodeBody
141
157
  attr_accessor :locals_count #: Array[Integer]
142
158
 
143
159
  attr_accessor :locals_type #: Array[Symbol]
144
160
 
145
- attr_writer :instruction_bytes #: String?
146
-
147
161
  attr_writer :type_section #: TypeSection?
148
162
 
149
163
  # @rbs &blk: (CodeBody) -> void
@@ -153,6 +167,7 @@ module Wardite
153
167
  @locals_type = []
154
168
  @body = [] #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
155
169
  @instruction_bytes = nil
170
+ @decoded = nil #: DecodedBody?
156
171
  @type_section = nil
157
172
  blk.call(self)
158
173
  end
@@ -160,6 +175,8 @@ module Wardite
160
175
  # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
161
176
  def body
162
177
  check_features(@type_section, false) if @instruction_bytes
178
+ # The caller can mutate both the array and the Block objects in it.
179
+ @decoded = nil
163
180
  @body
164
181
  end
165
182
 
@@ -168,6 +185,20 @@ module Wardite
168
185
  def body=(instructions)
169
186
  @body = instructions
170
187
  @instruction_bytes = nil
188
+ @decoded = nil
189
+ end
190
+
191
+ # @rbs bytes: String?
192
+ # @rbs return: void
193
+ def instruction_bytes=(bytes)
194
+ @instruction_bytes = bytes
195
+ @decoded = nil
196
+ end
197
+
198
+ # @rbs buf: File|StringIO
199
+ # @rbs return: void
200
+ def decode_from(buf)
201
+ install_decoded(BinaryLoader.decode_body(buf))
171
202
  end
172
203
 
173
204
  # @rbs types: TypeSection?
@@ -177,38 +208,69 @@ module Wardite
177
208
  if stack && locals_type.include?(:exnref)
178
209
  raise LoadError, "stack engine does not support exnref"
179
210
  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
211
+ if (bytes = @instruction_bytes)
212
+ decoded = BinaryLoader.decode_body(StringIO.new(bytes))
213
+ check_decoded(decoded, types, stack)
214
+ install_decoded(decoded)
215
+ elsif (decoded = @decoded)
216
+ check_decoded(decoded, types, stack)
217
+ else
218
+ check_instructions(@body, types, stack)
219
+ end
184
220
  end
185
221
 
186
222
  private
187
223
 
224
+ # @rbs decoded: DecodedBody
225
+ # @rbs return: void
226
+ def install_decoded(decoded)
227
+ @body = decoded.instructions
228
+ @instruction_bytes = nil
229
+ @decoded = decoded
230
+ end
231
+
232
+ # @rbs decoded: DecodedBody
233
+ # @rbs types: TypeSection?
234
+ # @rbs stack: bool
235
+ # @rbs return: void
236
+ def check_decoded(decoded, types, stack)
237
+ if stack && decoded.has_eh_instructions
238
+ raise LoadError, "stack engine does not support EH"
239
+ end
240
+ decoded.blocks.each { |block| check_block(block, types, stack) }
241
+ end
242
+
188
243
  # @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
189
244
  # @rbs types: TypeSection?
190
245
  # @rbs stack: bool
191
246
  # @rbs return: void
192
247
  def check_instructions(instructions, types, stack)
193
248
  instructions.each do |instruction|
194
- if stack && [:try_table, :throw, :throw_ref].include?(instruction[1])
249
+ if stack && BinaryLoader.eh_instruction?(instruction[1])
195
250
  raise LoadError, "stack engine does not support EH"
196
251
  end
197
252
  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
253
+ check_block(operand, types, stack) if operand.is_a?(Block)
209
254
  end
210
255
  end
211
256
  end
257
+
258
+ # @rbs block: Block
259
+ # @rbs types: TypeSection?
260
+ # @rbs stack: bool
261
+ # @rbs return: void
262
+ def check_block(block, types, stack)
263
+ index = block.type_index
264
+ if index >= 0
265
+ params = types&.defined_types&.[](index)
266
+ results = types&.defined_results&.[](index)
267
+ raise LoadError, "invalid block type index #{index}" unless params && results
268
+ block.resolve(params, results)
269
+ end
270
+ if stack && (index >= 0 || block.result_types.include?(:exnref))
271
+ raise LoadError, "stack engine does not support indexed/reference block signatures"
272
+ end
273
+ end
212
274
  end
213
275
 
214
276
  attr_accessor :func_codes #:Array[CodeBody]
@@ -410,11 +472,8 @@ module Wardite
410
472
  sections = [] #: Array[Section]
411
473
 
412
474
  loop do
413
- byte = @buf.read(1)
414
- if !byte
415
- break
416
- end
417
- code = byte.ord
475
+ code = @buf.getbyte
476
+ break unless code
418
477
 
419
478
  section = case code
420
479
  when Wardite::SectionType
@@ -466,15 +525,15 @@ module Wardite
466
525
 
467
526
  len = fetch_uleb128(sbuf)
468
527
  len.times do |i|
469
- fncode = assert_read(sbuf, 1)
470
- if fncode != "\x60"
528
+ fncode = assert_byte(sbuf)
529
+ if fncode != 0x60
471
530
  raise LoadError, "not a function definition"
472
531
  end
473
532
 
474
533
  arglen = fetch_uleb128(sbuf)
475
534
  arg = [] #: Array[Symbol]
476
535
  arglen.times do
477
- case ty = assert_read(sbuf, 1)&.ord
536
+ case ty = assert_byte(sbuf)
478
537
  when 0x69
479
538
  arg << :exnref
480
539
  when 0x7f
@@ -494,7 +553,7 @@ module Wardite
494
553
  retlen = fetch_uleb128(sbuf)
495
554
  ret = [] #: Array[Symbol]
496
555
  retlen.times do
497
- case ty = assert_read(sbuf, 1)&.ord
556
+ case ty = assert_byte(sbuf)
498
557
  when 0x69
499
558
  ret << :exnref
500
559
  when 0x7f
@@ -521,7 +580,7 @@ module Wardite
521
580
  dest.size = fetch_uleb128(@buf)
522
581
  sbuf = StringIO.new(assert_read(@buf, dest.size))
523
582
  fetch_uleb128(sbuf).times do
524
- raise LoadError, "unsupported tag attribute" unless assert_read(sbuf, 1).ord == 0
583
+ raise LoadError, "unsupported tag attribute" unless assert_byte(sbuf) == 0
525
584
  dest.type_indices << fetch_uleb128(sbuf)
526
585
  end
527
586
  raise LoadError, "trailing tag section data" unless sbuf.eof?
@@ -541,11 +600,7 @@ module Wardite
541
600
  module_name = assert_read(sbuf, mlen)
542
601
  nlen = fetch_uleb128(sbuf)
543
602
  name = assert_read(sbuf, nlen)
544
- kind_ = assert_read(sbuf, 1)
545
- kind = kind_[0]&.ord
546
- if !kind
547
- raise "[BUG] empty unpacked string" # guard rbs
548
- end
603
+ kind = assert_byte(sbuf)
549
604
 
550
605
  raise LoadError, "tag imports are not supported" if kind == 4
551
606
  raise LoadError, "unsupported import kind #{kind} for #{module_name}.#{name}" unless kind == 0
@@ -617,7 +672,7 @@ module Wardite
617
672
  code = fetch_insn_while_end(sbuf)
618
673
  ops = code_body(StringIO.new(code))
619
674
  dest.table_offsets << decode_expr(ops)
620
- if etype == 2 && assert_read(sbuf, 1).ord != 0
675
+ if etype == 2 && assert_byte(sbuf) != 0
621
676
  raise LoadError, "unsupported element type"
622
677
  end
623
678
 
@@ -638,12 +693,12 @@ module Wardite
638
693
 
639
694
  len = fetch_uleb128(sbuf)
640
695
  len.times do |i|
641
- gtype = Op.i2type(assert_read(sbuf, 1).ord)
642
- mut = sbuf.read 1
696
+ gtype = Op.i2type(assert_byte(sbuf))
697
+ mut = sbuf.getbyte
643
698
  if !mut
644
699
  raise LoadError, "global section too short"
645
700
  end
646
- unless mut.ord == 0 || mut.ord == 1
701
+ unless mut == 0 || mut == 1
647
702
  raise LoadError, "unsupported global mutability flags"
648
703
  end
649
704
 
@@ -661,7 +716,7 @@ module Wardite
661
716
 
662
717
  global = GlobalSection::Global.new do |g|
663
718
  g.type = gtype
664
- g.mutable = (mut.ord == 0x01)
719
+ g.mutable = (mut == 0x01)
665
720
  g.shared = false # always
666
721
  g.value = value
667
722
  end
@@ -728,50 +783,58 @@ module Wardite
728
783
  def self.read_function_body(sbuf, defer_code = false)
729
784
  ilen = fetch_uleb128(sbuf)
730
785
  code = assert_read(sbuf, ilen)
731
- last_code = code[-1]
786
+ last_code = code.getbyte(-1)
732
787
  if ! last_code
733
788
  raise "[BUG] empty code fetched" # guard for steep check
734
789
  end
735
- if last_code.ord != 0x0b
736
- $stderr.puts "warning: instruction not ended with inst end(0x0b): 0x0#{last_code.ord}"
790
+ if last_code != 0x0b
791
+ $stderr.puts "warning: instruction not ended with inst end(0x0b): 0x0#{last_code}"
737
792
  end
738
793
  cbuf = StringIO.new(code)
739
794
  CodeSection::CodeBody.new do |body|
740
795
  locals_len = fetch_uleb128(cbuf)
741
796
  while locals_len > 0
742
797
  body.locals_count << fetch_uleb128(cbuf)
743
- body.locals_type << Op.i2type(assert_read(cbuf, 1).ord)
798
+ body.locals_type << Op.i2type(assert_byte(cbuf))
744
799
  locals_len -= 1
745
800
  end
746
801
  if defer_code
747
802
  body.instruction_bytes = (cbuf.read || "".b).freeze
748
803
  else
749
- body.body = code_body(cbuf)
804
+ body.decode_from(cbuf)
750
805
  end
751
806
  end
752
807
  end
753
808
 
754
- # @rbs buf: StringIO
809
+ # @rbs buf: File|StringIO
755
810
  # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
756
811
  def self.code_body(buf)
812
+ decode_body(buf).instructions
813
+ end
814
+
815
+ # @rbs buf: File|StringIO
816
+ # @rbs return: DecodedBody
817
+ def self.decode_body(buf)
757
818
  dest = [] #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
819
+ blocks = [] #: Array[Block]
820
+ has_eh_instructions = false
758
821
  # HINT: [symname, index of op, index of else, index of end]
759
822
  branching_stack = [] #: Array[[Symbol, Integer, Integer, Integer]]
760
823
  fixed_stack = [] #: Array[[Symbol, Integer, Integer, Integer]]
761
- while c = buf.read(1)
762
- namespace, code, operand_types = resolve_code(c, buf)
824
+ while opcode = buf.getbyte
825
+ spec = resolve_spec(opcode, buf)
826
+ code = spec.code
827
+ has_eh_instructions ||= eh_instruction?(code)
763
828
  operand = [] #: Array[operandItem]
764
- operand_types.each do |typ|
829
+ spec.operand_types.each do |typ|
765
830
  case typ
766
831
  when :u8
767
- ope = buf.read 1
768
- if ! ope
769
- raise LoadError, "buffer too short"
770
- end
771
- operand << ope.ord
832
+ byte = buf.getbyte
833
+ raise LoadError, "buffer too short" unless byte
834
+ operand << byte
772
835
  when :u32
773
836
  value = fetch_uleb128(buf)
774
- if operand.empty? && c.ord >= 0x28 && c.ord <= 0x3e && value >= 64
837
+ if operand.empty? && opcode >= 0x28 && opcode <= 0x3e && value >= 64
775
838
  raise LoadError, "multi-memory memargs are not supported"
776
839
  end
777
840
  operand << value
@@ -791,11 +854,12 @@ module Wardite
791
854
  operand << FloatImmediate.new(typ, FloatBits.read(typ, data))
792
855
  when :u8_block, :blocktype
793
856
  value = read_blocktype(buf)
857
+ blocks << value
794
858
  operand << value
795
859
  when :catches
796
860
  clauses = [] #: Array[Integer]
797
861
  fetch_uleb128(buf).times do
798
- kind = assert_read(buf, 1).ord
862
+ kind = assert_byte(buf)
799
863
  raise LoadError, "invalid catch kind #{kind}" unless kind <= 3
800
864
  tag = kind <= 1 ? fetch_uleb128(buf) : -1
801
865
  depth = fetch_uleb128(buf)
@@ -809,7 +873,7 @@ module Wardite
809
873
  end
810
874
 
811
875
  # HINT: [namespace, code, operand, else_pos, end_pos]
812
- dest << [namespace, code, operand, nil, nil]
876
+ dest << [spec.namespace, code, operand, nil, nil]
813
877
  if code == :block || code == :loop || code == :if || code == :try_table
814
878
  branching_stack << [code, dest.size - 1, -1, -1]
815
879
  elsif code == :else
@@ -845,7 +909,7 @@ module Wardite
845
909
  raise "[BUG] unknown sym #{sym.inspect}"
846
910
  end
847
911
  end
848
- dest
912
+ DecodedBody.new(dest, blocks, has_eh_instructions)
849
913
  rescue => e
850
914
  require "pp"
851
915
  $stderr.puts "parsed:::"
@@ -854,8 +918,14 @@ module Wardite
854
918
  raise e
855
919
  end
856
920
 
921
+ # @rbs code: Symbol
922
+ # @rbs return: bool
923
+ def self.eh_instruction?(code)
924
+ code == :try_table || code == :throw || code == :throw_ref
925
+ end
926
+
857
927
  # Decode s33, distinguishing the one-byte value/void forms from indices.
858
- # @rbs buf: StringIO
928
+ # @rbs buf: File|StringIO
859
929
  # @rbs return: Block
860
930
  def self.read_blocktype(buf)
861
931
  first = buf.pos
@@ -873,20 +943,26 @@ module Wardite
873
943
  end
874
944
 
875
945
  # @rbs c: String
876
- # @rbs buf: StringIO
946
+ # @rbs buf: File|StringIO
877
947
  # @rbs return: [Symbol, Symbol, Array[Symbol]]
878
948
  def self.resolve_code(c, buf)
879
- ord = c.ord
880
- code = Op::SYMS[ord]
881
- if code == :fc
949
+ spec = resolve_spec(c.ord, buf)
950
+ [spec.namespace, spec.code, spec.operand_types.dup]
951
+ end
952
+
953
+ # @rbs opcode: Integer
954
+ # @rbs buf: File|StringIO
955
+ # @rbs return: Op::DecodeSpec
956
+ def self.resolve_spec(opcode, buf)
957
+ if opcode == 0xfc
882
958
  lower = fetch_uleb128(buf)
883
- sym = Op::FC_SYMS[lower]
884
- namespace = Op::FC_OPERANDS[lower] || :default
885
- return [namespace, sym, Op.operand_of(sym)]
959
+ # Preserve the unresolved opcode for the engine's unsupported-op check.
960
+ Op::FC_SPECS[lower] || Op::DecodeSpec.new(:default, Op::FC_SYMS[lower], [])
961
+ else
962
+ Op::OPCODE_SPECS[opcode] || raise(LoadError, "unsupported code: #{opcode}")
886
963
  end
887
- namespace = Op::NAMESPACES[ord] || raise(LoadError, "unsupported code: #{ord}")
888
- return [namespace, code, Op.operand_of(code)]
889
964
  end
965
+ private_class_method :resolve_spec
890
966
 
891
967
  # @rbs return: DataSection
892
968
  def self.data_section
@@ -949,7 +1025,7 @@ module Wardite
949
1025
  # @rbs return: String
950
1026
  def self.fetch_insn_while_end(sbuf)
951
1027
  first = sbuf.pos
952
- opcode = assert_read(sbuf, 1).ord
1028
+ opcode = assert_byte(sbuf)
953
1029
  case opcode
954
1030
  when 0x41 then fetch_sleb128(sbuf, width: 32)
955
1031
  when 0x42 then fetch_sleb128(sbuf, width: 64)
@@ -957,7 +1033,7 @@ module Wardite
957
1033
  when 0x44 then assert_read(sbuf, 8)
958
1034
  else raise LoadError, "unsupported constant expression"
959
1035
  end
960
- raise LoadError, "constant expression requires end" unless assert_read(sbuf, 1).ord == 0x0b
1036
+ raise LoadError, "constant expression requires end" unless assert_byte(sbuf) == 0x0b
961
1037
  length = sbuf.pos - first
962
1038
  sbuf.pos = first
963
1039
  assert_read(sbuf, length)
@@ -1028,11 +1104,7 @@ module Wardite
1028
1104
  len.times do |i|
1029
1105
  nlen = fetch_uleb128(sbuf)
1030
1106
  name = assert_read(sbuf, nlen)
1031
- kind_ = assert_read(sbuf, 1)
1032
- kind = kind_[0]&.ord
1033
- if !kind
1034
- raise "[BUG] empty unpacked string" # guard rbs
1035
- end
1107
+ kind = assert_byte(sbuf)
1036
1108
 
1037
1109
  raise LoadError, "tag exports are not supported" if kind == 4
1038
1110
  index = fetch_uleb128(sbuf)
@@ -1055,6 +1127,12 @@ module Wardite
1055
1127
  nil
1056
1128
  end
1057
1129
 
1130
+ # @rbs sbuf: File|StringIO
1131
+ # @rbs return: Integer
1132
+ def self.assert_byte(sbuf)
1133
+ sbuf.getbyte || raise(LoadError, "too short section size")
1134
+ end
1135
+
1058
1136
  # @rbs sbuf: File|StringIO
1059
1137
  # @rbs n: Integer
1060
1138
  # @rbs return: String
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Wardite
5
- VERSION = "1.2.0" #: String
5
+ VERSION = "1.2.1" #: String
6
6
  end
@@ -418,7 +418,22 @@ module Wardite
418
418
 
419
419
  EXTENDED_GLOBAL_SET_TYPES: Hash[Integer, Symbol]
420
420
 
421
- # These are semantic register accesses, excluding frame initialization.
421
+ # Semantic register operand positions, excluding frame initialization.
422
+ READ_POSITIONS: Array[Array[Integer]?]
423
+
424
+ # @rbs instruction: Wardite::Efflorescence::Instruction
425
+ # @rbs return: Integer
426
+ def self.read_count: (Wardite::Efflorescence::Instruction instruction) -> Integer
427
+
428
+ # @rbs instruction: Wardite::Efflorescence::Instruction
429
+ # @rbs ordinal: Integer
430
+ # @rbs return: Integer
431
+ def self.read_position: (Wardite::Efflorescence::Instruction instruction, Integer ordinal) -> Integer
432
+
433
+ # @rbs opcode: Integer
434
+ # @rbs return: Array[Integer]
435
+ def self.fixed_read_positions: (Integer opcode) -> Array[Integer]
436
+
422
437
  # @rbs instruction: Wardite::Efflorescence::Instruction
423
438
  # @rbs return: Array[Integer]
424
439
  def self.read_positions: (Wardite::Efflorescence::Instruction instruction) -> Array[Integer]
@@ -703,6 +718,19 @@ module Wardite
703
718
  # @rbs return: void
704
719
  def replace_register_references!: (Array[Integer] mapping) -> void
705
720
 
721
+ # @rbs instruction: Wardite::Efflorescence::Instruction
722
+ # @rbs return: Integer
723
+ def read_count: (Wardite::Efflorescence::Instruction instruction) -> Integer
724
+
725
+ # @rbs instruction: Wardite::Efflorescence::Instruction
726
+ # @rbs ordinal: Integer
727
+ # @rbs return: Integer
728
+ def read_at: (Wardite::Efflorescence::Instruction instruction, Integer ordinal) -> Integer
729
+
730
+ # @rbs instruction: Wardite::Efflorescence::Instruction
731
+ # @rbs return: Array[Integer]?
732
+ def side_reads: (Wardite::Efflorescence::Instruction instruction) -> Array[Integer]?
733
+
706
734
  # @rbs instruction: Wardite::Efflorescence::Instruction
707
735
  # @rbs return: Array[Integer]
708
736
  def reads: (Wardite::Efflorescence::Instruction instruction) -> Array[Integer]
@@ -73,7 +73,7 @@ module Wardite
73
73
  end
74
74
 
75
75
  module Passes
76
- # Expand only small, straight-line leaves from a snapshot of the IR.
76
+ # Expand only small, straight-line leaves from pre-rewrite snapshots.
77
77
  # One round avoids transitive/exponential expansion and keeps recursion
78
78
  # on the ordinary CALL path. Existing local passes clean up the copies.
79
79
  class Inlining
@@ -98,9 +98,33 @@ module Wardite
98
98
  def eligible?: (Wardite::Efflorescence::Function function) -> bool
99
99
 
100
100
  # @rbs function: Wardite::Efflorescence::Function
101
- # @rbs callees: Wardite::Efflorescence::IR
101
+ # @rbs ir: Wardite::Efflorescence::IR
102
+ # @rbs callees: Hash[Integer, Wardite::Efflorescence::Function]
102
103
  # @rbs return: bool
103
- def expand_calls: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::IR callees) -> bool
104
+ def expand_calls: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::IR ir, Hash[Integer, Wardite::Efflorescence::Function] callees) -> bool
105
+
106
+ # @rbs function: Wardite::Efflorescence::Function
107
+ # @rbs ir: Wardite::Efflorescence::IR
108
+ # @rbs callees: Hash[Integer, Wardite::Efflorescence::Function]
109
+ # @rbs return: bool
110
+ def expandable_call?: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::IR ir, Hash[Integer, Wardite::Efflorescence::Function] callees) -> bool
111
+
112
+ # Count the expansion before copy cleanup, conservatively.
113
+ # @rbs callee: Wardite::Efflorescence::Function
114
+ # @rbs call: Wardite::Efflorescence::Instruction
115
+ # @rbs return: Integer
116
+ def instruction_growth: (Wardite::Efflorescence::Function callee, Wardite::Efflorescence::Instruction call) -> Integer
117
+
118
+ # @rbs callee: Wardite::Efflorescence::Function
119
+ # @rbs return: Integer
120
+ def register_growth: (Wardite::Efflorescence::Function callee) -> Integer
121
+
122
+ # Check the module index even when there are no inline candidates.
123
+ # @rbs ir: Wardite::Efflorescence::IR
124
+ # @rbs callees: Hash[Integer, Wardite::Efflorescence::Function]
125
+ # @rbs call: Wardite::Efflorescence::Instruction
126
+ # @rbs return: Wardite::Efflorescence::Function?
127
+ def callee_for: (Wardite::Efflorescence::IR ir, Hash[Integer, Wardite::Efflorescence::Function] callees, Wardite::Efflorescence::Instruction call) -> Wardite::Efflorescence::Function?
104
128
 
105
129
  # @rbs caller: Wardite::Efflorescence::Function
106
130
  # @rbs callee: Wardite::Efflorescence::Function
@@ -43,14 +43,39 @@ module Wardite
43
43
 
44
44
  private
45
45
 
46
- # Visit predecessors before joins where possible, then revisit changed
47
- # states across backedges until the worklist is empty.
46
+ # @rbs instructions: Array[Wardite::Efflorescence::Instruction]
47
+ # @rbs return: Array[Integer]?
48
+ def plain_leaders: (Array[Wardite::Efflorescence::Instruction] instructions) -> Array[Integer]?
49
+
50
+ # @rbs leaders: Array[Integer]
51
+ # @rbs return: [Array[Wardite::Efflorescence::RegisterValidation::Block], Array[Integer]]
52
+ def build_blocks: (Array[Integer] leaders) -> [ Array[Wardite::Efflorescence::RegisterValidation::Block], Array[Integer] ]
53
+
54
+ # @rbs function: Wardite::Efflorescence::Function
55
+ # @rbs leaders: Array[Integer]
56
+ # @rbs return: void
57
+ def validate_plain: (Wardite::Efflorescence::Function function, Array[Integer] leaders) -> void
58
+
59
+ # @rbs function: Wardite::Efflorescence::Function
60
+ # @rbs blocks: Array[Wardite::Efflorescence::RegisterValidation::Block]
61
+ # @rbs order: Array[Integer]
62
+ # @rbs block_for_pc: Array[Integer]
63
+ # @rbs flow: Wardite::Efflorescence::FlowGraph?
64
+ # @rbs return: void
65
+ def validate_blocks: (Wardite::Efflorescence::Function function, Array[Wardite::Efflorescence::RegisterValidation::Block] blocks, Array[Integer] order, Array[Integer] block_for_pc, Wardite::Efflorescence::FlowGraph? flow) -> void
66
+
48
67
  # @rbs blocks: Array[Wardite::Efflorescence::RegisterValidation::Block]
49
68
  # @rbs block_for_pc: Array[Integer]
50
69
  # @rbs flow: Wardite::Efflorescence::FlowGraph
51
70
  # @rbs return: Array[Integer]
52
71
  def reverse_postorder: (Array[Wardite::Efflorescence::RegisterValidation::Block] blocks, Array[Integer] block_for_pc, Wardite::Efflorescence::FlowGraph flow) -> Array[Integer]
53
72
 
73
+ # Visit predecessors before joins where possible, then revisit changed
74
+ # states across backedges until the worklist is empty.
75
+ # @rbs blocks: Array[Wardite::Efflorescence::RegisterValidation::Block]
76
+ # @rbs return: Array[Integer]
77
+ def block_reverse_postorder: (Array[Wardite::Efflorescence::RegisterValidation::Block] blocks) -> Array[Integer]
78
+
54
79
  # @rbs words: Array[Integer]
55
80
  # @rbs register: Integer
56
81
  # @rbs return: void
@@ -71,10 +96,26 @@ module Wardite
71
96
 
72
97
  # @rbs function: Wardite::Efflorescence::Function
73
98
  # @rbs instruction: Wardite::Efflorescence::Instruction
74
- # @rbs reads: Array[Integer]
99
+ # @rbs read_count: Integer
75
100
  # @rbs destination: Integer
76
101
  # @rbs return: void
77
- def validate_extended_instruction: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::Instruction instruction, Array[Integer] reads, Integer destination) -> void
102
+ def validate_extended_instruction: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::Instruction instruction, Integer read_count, Integer destination) -> void
103
+
104
+ # @rbs function: Wardite::Efflorescence::Function
105
+ # @rbs instruction: Wardite::Efflorescence::Instruction
106
+ # @rbs types: Array[Symbol]
107
+ # @rbs first: Integer
108
+ # @rbs limit: Integer
109
+ # @rbs type_offset: Integer
110
+ # @rbs return: void
111
+ def check_reads: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::Instruction instruction, Array[Symbol] types, Integer first, Integer limit, ?Integer type_offset) -> void
112
+
113
+ # @rbs function: Wardite::Efflorescence::Function
114
+ # @rbs instruction: Wardite::Efflorescence::Instruction
115
+ # @rbs type: Symbol
116
+ # @rbs limit: Integer
117
+ # @rbs return: void
118
+ def check_reads_of_type: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::Instruction instruction, Symbol type, Integer limit) -> void
78
119
 
79
120
  # @rbs tags: Array[Wardite::Efflorescence::Tag]?
80
121
  # @rbs index: Integer
@@ -62,6 +62,29 @@ module Wardite
62
62
  # @rbs return: Symbol
63
63
  def self.resolve_fc_sym: (Integer lower) -> Symbol
64
64
 
65
+ # @rbs code: Symbol
66
+ # @rbs return: Array[Symbol]
67
+ def self.build_operand_types: (Symbol code) -> Array[Symbol]
68
+
69
+ class DecodeSpec
70
+ attr_reader namespace: Symbol
71
+
72
+ attr_reader code: Symbol
73
+
74
+ attr_reader operand_types: Array[Symbol]
75
+
76
+ # @rbs namespace: Symbol
77
+ # @rbs code: Symbol
78
+ # @rbs operand_types: Array[Symbol]
79
+ def initialize: (Symbol namespace, Symbol code, Array[Symbol] operand_types) -> untyped
80
+ end
81
+
82
+ OPERAND_TYPES_BY_CODE: Hash[Symbol, Array[Symbol]]
83
+
84
+ OPCODE_SPECS: Array[DecodeSpec]
85
+
86
+ FC_SPECS: Array[DecodeSpec]
87
+
65
88
  # @rbs code: Symbol
66
89
  # @rbs return: Array[Symbol]
67
90
  def self.operand_of: (Symbol code) -> Array[Symbol]