rubyx/lib/risc/instructions/label.rb

58 lines
1.1 KiB
Ruby
Raw Normal View History

module Risc
# A label is a placeholder for it's next Instruction
# It's function is not to turn into code, but to be a valid brnch target
#
# So branches and Labels are pairs, fan out, fan in
#
#
class Label < Instruction
def initialize( source , name , nekst = nil)
super(source , nekst)
@name = name
end
attr_reader :name
def to_cpu(translator)
@cpu_label ||= super
end
def to_s
2018-03-22 17:38:19 +01:00
class_source "#{@name} (next: #{self.next.class.name.split("::").last})"
end
2016-12-28 20:40:06 +01:00
def rxf_reference_name
2015-11-14 23:35:43 +01:00
@name
2015-11-14 21:53:01 +01:00
end
2015-11-03 15:22:24 +01:00
# a method start has a label of the form Class.method , test for that
def is_method
@name.split(".").length == 2
end
2018-03-26 18:17:30 +02:00
def assemble_all( io )
self.each {|ins| ins.assemble(io)}
end
def assemble io
end
def total_byte_length
ret = 0
self.each{|ins| ret += ins.byte_length}
ret
end
2015-11-03 15:22:24 +01:00
# shame we need this, just for logging
def byte_length
0
end
alias :padded_length :byte_length
end
def self.label( source , name , nekst = nil)
Label.new( source , name , nekst = nil)
end
end