adding sources to register instructions

This commit is contained in:
Torsten Ruger
2015-07-27 12:13:39 +03:00
parent f91c9fabe8
commit 36f635f7c1
16 changed files with 55 additions and 47 deletions

View File

@ -4,7 +4,8 @@ module Register
# assembly takes care of the rest (ie getting the address)
class FunctionCall < Instruction
def initialize method
def initialize source , method
super(source)
@method = method
end
attr_reader :method

View File

@ -4,7 +4,8 @@ module Register
# register and index specify where the return address is stored
class FunctionReturn < Instruction
def initialize register , index
def initialize source , register , index
super(source)
@register = register
@index = index
end

View File

@ -18,30 +18,31 @@ module Register
# the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruciton name
# So GetSlot means the slot (array and index) moves to the register (last argument)
def initialize array , index , register
@register = register
def initialize source , array , index , register
super(source)
@array = array
@index = index
@register = register
raise "not integer #{index}" unless index.is_a? Numeric
raise "Not register #{register}" unless Register::RegisterReference.look_like_reg(register)
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array)
end
attr_accessor :register , :array , :index
attr_accessor :array , :index , :register
def to_s
"GetSlot: #{register} -> #{array} [#{index}]"
"GetSlot: #{array} [#{index}] -> #{register}"
end
end
# Produce a GetSlot instruction.
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# Array and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.get_slot from , index , to
index = resolve_index( from , index)
from = resolve_to_register from
def self.get_slot source , array , index , to
index = resolve_index( array , index)
array = resolve_to_register array
to = resolve_to_register to
GetSlot.new( from , index , to)
GetSlot.new( source , array , index , to)
end
end

View File

@ -5,7 +5,8 @@ module Register
# second argument is the register the constant is loaded into
class LoadConstant < Instruction
def initialize constant , register
def initialize source , constant , register
super(source)
@register = register
@constant = constant
end

View File

@ -16,7 +16,8 @@ module Register
# second arguemnt to
#
# Note: this may be reversed from some assembler notations (also arm)
def initialize from , to
def initialize source , from , to
super(source)
@from = wrap_register(from)
@to = wrap_register(to)
end

View File

@ -7,7 +7,8 @@ module Register
# address. In arm that is a register, but intel may (?) push it, and who knows, what other machines do.
class SaveReturn < Instruction
def initialize register , index
def initialize source , register , index
super(source)
@register = register
@index = index
end
@ -22,10 +23,10 @@ module Register
# Produce a SaveReturn instruction.
# From is a register or symbol that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.save_return from , index
def self.save_return code, from , index
index = resolve_index( from , index)
from = resolve_to_register from
SaveReturn.new( from , index )
SaveReturn.new( code , from , index )
end
end

View File

@ -17,7 +17,8 @@ module Register
# If you had a c array and index offset
# the instruction would do array[index] = register
# So SetSlot means the register (first argument) moves to the slot (array and index)
def initialize register , array , index
def initialize source , register , array , index
super(source)
@register = register
@array = array
@index = index
@ -35,11 +36,11 @@ module Register
# Produce a SetSlot instruction.
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.set_slot from , to , index
index = resolve_index( to , index)
def self.set_slot source , from , to , index
from = resolve_to_register from
index = resolve_index( to , index)
to = resolve_to_register to
SetSlot.new( from , to , index)
SetSlot.new( source, from , to , index)
end
end

View File

@ -9,7 +9,8 @@ module Register
class Syscall < Instruction
def initialize name
def initialize source ,name
super(source)
@name = name
end
attr_reader :name