move generator functions to the instructions they generate

This commit is contained in:
Torsten Ruger 2015-06-30 09:43:50 +03:00
parent bd77db656a
commit 60c8f8ef73
4 changed files with 34 additions and 31 deletions

View File

@ -28,4 +28,15 @@ module Register
end
attr_accessor :register , :array , :index
end
# Produce a GetSlot 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.get_slot from , index , to
index = resolve_index( from , index)
from = resolve_to_register from
to = resolve_to_register to
GetSlot.new( from , index , to)
end
end

View File

@ -3,7 +3,7 @@ module Register
# save the return address of a call
# register and index specify where the return address is stored
# This instruction exists mainly, so we don't have to hard-code where the machine stores the
# This instruction exists mainly, so we don't have to hard-code where the machine stores the
# address. In arm that is a register, but intel may (?) push it, and who knows, what other machines do.
class SaveReturn < Instruction
@ -13,4 +13,14 @@ module Register
end
attr_reader :register , :index
end
end
# 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
index = resolve_index( from , index)
from = resolve_to_register from
SaveReturn.new( from , index )
end
end

View File

@ -27,4 +27,15 @@ module Register
end
attr_accessor :register , :array , :index
end
# 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)
from = resolve_to_register from
to = resolve_to_register to
SetSlot.new( from , to , index)
end
end

View File

@ -86,35 +86,6 @@ module Register
RegisterReference.new :r4
end
# Produce a GetSlot instruction (see there).
# 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.get_slot from , index , to
index = resolve_index( from , index)
from = resolve_to_register from
to = resolve_to_register to
GetSlot.new( from , index , to)
end
# Produce a SetSlot instruction (see there).
# 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)
from = resolve_to_register from
to = resolve_to_register to
SetSlot.new( from , to , index)
end
# Produce a SaveReturn instruction (see there).
# 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
index = resolve_index( from , index)
from = resolve_to_register from
SaveReturn.new( from , index )
end
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
# By looking up the class and the layout for that class, we can resolve the instance
# variable name to an index.