Class: Fisk::UnresolvedJumpInstruction
Instance Method Summary
collapse
#comment?, #has_temp_registers?, #label?, #lazy?
Constructor Details
Returns a new instance of UnresolvedJumpInstruction.
448
449
450
451
452
453
|
# File 'lib/fisk.rb', line 448
def initialize insn, form, operand
@insn = insn
@form = form
@operand = operand
@must_retry = false
end
|
Instance Method Details
#encode(buffer, labels) ⇒ Object
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
# File 'lib/fisk.rb', line 467
def encode buffer, labels
form = find_form "rel32"
encoding = form.encodings.first
operand_klass = Rel32
if labels.key? target
unless @must_retry
estimated_offset = labels[target] - (buffer.pos + 6)
if estimated_offset >= -128 && estimated_offset <= 127
operand_klass = Rel8
form = find_form "rel8"
encoding = form.encodings.first
end
end
pos = buffer.pos
encoding.encode buffer, [operand_klass.new(0xFE)]
jump_len = -(buffer.pos - labels[target])
buffer.seek pos, IO::SEEK_SET
encoding.encode buffer, [operand_klass.new(jump_len)]
else
if @must_retry
raise Errors::MissingLabel, "Label `#{target}` was used, but not defined"
end
@must_retry = true
encoding.encode buffer, [operand_klass.new(0x0CAFE)]
end
end
|
#jump? ⇒ Boolean
455
456
457
|
# File 'lib/fisk.rb', line 455
def jump?
true
end
|
#retry? ⇒ Boolean
463
464
465
|
# File 'lib/fisk.rb', line 463
def retry?
true
end
|
#target ⇒ Object
459
460
461
|
# File 'lib/fisk.rb', line 459
def target
@operand.name
end
|