Module Ruva::Utils::CodeDumper
In: lib/ruva/utils/code_dumper.rb

Methods

dump   print  

Public Class methods

Debug utility. Splits the code into opcodes with their operands, and passes each complete set to the supplied block.

[Source]

    # File lib/ruva/utils/code_dumper.rb, line 13
13:         def dump(code, opmap = Ruva::VM::OPMAP)
14:           code = code.dup
15:           pc = 0
16:           seq = -1
17:           
18:           h = {}
19:           
20:           while op = code.shift
21:             start_pc, pc = pc, pc += 1
22:             opname, (blk, noperands, impoperands) = *opmap[op]            
23:             operands = (0...noperands).map { pc += 1 and code.shift }
24:             
25:             yield seq += 1, start_pc, pc - 1, opname, operands
26:           end
27:         end

Convenience wrapper for dump when you just want to see some code. Output looks like:

   seq |     bytes      |        mnemonic | operands
 ----------------------------------------------------------
     0 | 0x0000..0x0002 |          SIPUSH | [3, 233]
     1 | 0x0003..0x0005 |       PUTSTATIC | [0, 2]
     2 | 0x0006..0x0006 |          RETURN | []
 ----------------------------------------------------------

[Source]

    # File lib/ruva/utils/code_dumper.rb, line 39
39:         def print(code, opmap = Ruva::VM::OPMAP)
40:           printf("%5s | %-14s | %15s | %s\n", 'seq', '    bytes    ', 'mnemonic', 'operands')
41:           printf("----------------------------------------------------------\n")
42:           dump(code, opmap) do |seq, start_pc, end_pc, opname, operands|
43:             printf("%5d | 0x%04x..0x%0-4x | %15s | %s\n", seq, start_pc, end_pc, opname, operands.inspect)
44:           end
45:           printf("----------------------------------------------------------\n")
46:         end

[Validate]