Class: Ragweed::Rasm::Subprogram
Overview
A code fragment. Push instructions into it. You can push Label objects to create jump targets.
Instance Method Summary collapse
-
#assemble ⇒ Object
Patch code offsets into the instructions to replace abstract labels.
-
#disassemble ⇒ Object
Produce an array of insns.
- #dump_disassembly ⇒ Object
Methods included from Array::ArrayExtensions
Instance Method Details
#assemble ⇒ Object
Patch code offsets into the instructions to replace abstract labels. Produces raw instruction stream.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ragweed/rasm/isa.rb', line 175 def assemble patches = {} buf = Ragweed::Sbuf.new each do |i| if i.kind_of? Instruction i.locate(buf.size) buf.straw i.to_s else patches[i] = buf.size end end select {|i| i.kind_of? Instruction}.each {|i| i.patch(patches)} buf.clear! select {|i| i.kind_of? Instruction}.each {|i| buf.straw(i.to_s) } buf.content end |
#disassemble ⇒ Object
Produce an array of insns. This is pretty much broken, because it doesn’t pre-patch the instructions.
199 200 201 |
# File 'lib/ragweed/rasm/isa.rb', line 199 def disassemble select {|i| i.kind_of? Ragweed::Rasm::Instruction}.map {|i| i.decode} end |
#dump_disassembly ⇒ Object
203 204 205 206 207 |
# File 'lib/ragweed/rasm/isa.rb', line 203 def dump_disassembly disassemble.each_with_index do |insn, i| puts "#{ i } #{ insn.mnem }" end end |