2018-03-31 11:38:30 +02:00
|
|
|
module Risc
|
|
|
|
# load raw data into a register
|
|
|
|
#
|
|
|
|
# This is not really used by the compiler, or to be more precise: not used during the
|
|
|
|
# compilation of ruby code. Ruby code works on Objects only
|
|
|
|
#
|
|
|
|
# But for Builtin methods, methods that are created programatically and form the runtime,
|
2018-05-30 09:29:38 +02:00
|
|
|
# it can be handy to load an integer directly without the object overhead.
|
2018-03-31 11:38:30 +02:00
|
|
|
#
|
|
|
|
class LoadData < Instruction
|
|
|
|
def initialize( source , constant , register)
|
|
|
|
super(source)
|
|
|
|
@register = register
|
|
|
|
@constant = constant
|
|
|
|
raise "Not Integer #{constant}" unless constant.is_a?(Integer)
|
2018-06-29 10:39:07 +02:00
|
|
|
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
|
2018-03-31 11:38:30 +02:00
|
|
|
end
|
|
|
|
attr_accessor :register , :constant
|
|
|
|
|
2020-03-18 16:49:23 +01:00
|
|
|
# return an array of names of registers that is used by the instruction
|
2020-03-20 12:58:40 +01:00
|
|
|
def register_attributes
|
|
|
|
[:register]
|
2020-03-18 16:49:23 +01:00
|
|
|
end
|
|
|
|
|
2018-03-31 11:38:30 +02:00
|
|
|
def to_s
|
|
|
|
class_source "#{register} <- #{constant}"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2020-03-08 11:05:25 +01:00
|
|
|
def self.load_data( source , value , register = nil )
|
|
|
|
raise "can only load integers, not #{value}" unless value.is_a?(Integer)
|
|
|
|
type = Parfait.object_space.get_type_by_class_name(:Integer)
|
|
|
|
register = RegisterValue.new( "fix_#{value}".to_sym , type ) unless register
|
|
|
|
LoadData.new( source , value , register)
|
2018-03-31 11:38:30 +02:00
|
|
|
end
|
|
|
|
end
|