Class: Disasm
- Inherits:
-
Object
- Object
- Disasm
- Defined in:
- lib/rmarshal/disasm.rb
Instance Method Summary collapse
- #byte ⇒ Object
-
#initialize(code, consts, varnames, names) ⇒ Disasm
constructor
A new instance of Disasm.
- #insts ⇒ Object
- #parse ⇒ Object
- #short ⇒ Object
Constructor Details
#initialize(code, consts, varnames, names) ⇒ Disasm
Returns a new instance of Disasm.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rmarshal/disasm.rb', line 4 def initialize(code, consts, varnames, names) @code = code @consts = consts @varnames = varnames @names = names @insts = [] @off = 0 while @off != @code.size @insts[@insts.size] = parse end end |
Instance Method Details
#byte ⇒ Object
18 19 20 21 22 |
# File 'lib/rmarshal/disasm.rb', line 18 def byte() val = @code[@off].ord @off += 1 val end |
#insts ⇒ Object
17 |
# File 'lib/rmarshal/disasm.rb', line 17 def insts() @insts end |
#parse ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rmarshal/disasm.rb', line 29 def parse off = @off opcd = byte if not $opcodes.has_key? opcd raise "Unknown opcode #{opcd}" end name, arg = $opcodes[opcd] if arg == nil [off, name] else val = short arg = case arg when :const then @consts[val] when :name then @names[val] when :jrel then @off + val when :local then @varnames[val] else val end [off, name, arg] end end |
#short ⇒ Object
23 24 25 26 27 |
# File 'lib/rmarshal/disasm.rb', line 23 def short() val = @code[@off...@off+2].unpack('s')[0] @off += 2 val end |