Class: Fisk::UnresolvedInstruction
- Inherits:
-
Object
- Object
- Fisk::UnresolvedInstruction
- Defined in:
- lib/fisk.rb
Instance Method Summary collapse
- #encode(buffer, labels) ⇒ Object
-
#initialize(insn, form, operand) ⇒ UnresolvedInstruction
constructor
A new instance of UnresolvedInstruction.
- #label? ⇒ Boolean
Constructor Details
#initialize(insn, form, operand) ⇒ UnresolvedInstruction
Returns a new instance of UnresolvedInstruction.
181 182 183 184 185 186 |
# File 'lib/fisk.rb', line 181 def initialize insn, form, operand @insn = insn @form = form @operand = operand @saved_pos = nil end |
Instance Method Details
#encode(buffer, labels) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/fisk.rb', line 188 def encode buffer, labels # Estimate by using a rel32 offset form = find_form "rel32" encoding = form.encodings.first operand_klass = Rel32 if labels.key? @operand.name if @saved_pos # Only use rel32 if we saved the position buffer.seek @saved_pos, IO::SEEK_SET else estimated_offset = labels[@operand.name] - (buffer.pos + encoding.bytesize) if estimated_offset >= -128 && estimated_offset <= 127 # fits in a rel8 operand_klass = Rel8 form = find_form "rel8" encoding = form.encodings.first end end jump_len = -(buffer.pos + encoding.bytesize - labels[@operand.name]) encoding.encode buffer, [operand_klass.new(jump_len)] true else # We've hit a label that doesn't exist yet # Save the buffer position so we can seek back to it later @saved_pos = buffer.pos # Write 5 bytes to reserve our spot encoding.bytesize.times { buffer.putc 0 } false end end |
#label? ⇒ Boolean
222 |
# File 'lib/fisk.rb', line 222 def label?; false; end |