Class: Fisk::UnresolvedInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/fisk.rb

Instance Method Summary collapse

Constructor Details

#initialize(insn, form, operand) ⇒ UnresolvedInstruction

Returns a new instance of UnresolvedInstruction.



232
233
234
235
236
237
# File 'lib/fisk.rb', line 232

def initialize insn, form, operand
  @insn      = insn
  @form      = form
  @operand   = operand
  @saved_pos = nil
end

Instance Method Details

#encode(buffer, labels) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/fisk.rb', line 249

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

#has_temp_registers?Boolean

Returns:

  • (Boolean)


247
# File 'lib/fisk.rb', line 247

def has_temp_registers?; false; end

#jump?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/fisk.rb', line 239

def jump?
  true
end

#label?Boolean

Returns:

  • (Boolean)


283
# File 'lib/fisk.rb', line 283

def label?; false; end

#targetObject



243
244
245
# File 'lib/fisk.rb', line 243

def target
  @operand.name
end