Class: Fisk::UnresolvedJumpInstruction
Instance Method Summary
collapse
#comment?, #has_temp_registers?, #label?, #lazy?
Constructor Details
Returns a new instance of UnresolvedJumpInstruction.
474
475
476
477
478
479
|
# File 'lib/fisk.rb', line 474
def initialize insn, form, operand
@insn = insn
@form = form
@operand = operand
@must_retry = false
end
|
Instance Method Details
#encode(buffer, labels) ⇒ Object
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
# File 'lib/fisk.rb', line 493
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
481
482
483
|
# File 'lib/fisk.rb', line 481
def jump?
true
end
|
#retry? ⇒ Boolean
489
490
491
|
# File 'lib/fisk.rb', line 489
def retry?
true
end
|
#target ⇒ Object
485
486
487
|
# File 'lib/fisk.rb', line 485
def target
@operand.name
end
|