create add_code helper and some cleaning

This commit is contained in:
Torsten Ruger
2015-10-23 14:08:12 +03:00
parent dcbd3c7091
commit 991cc0519f
11 changed files with 41 additions and 66 deletions

View File

@ -14,12 +14,10 @@ module Register
@method = method
raise "Method is not Method, but #{method.class}" unless method == :__init__ or method.is_a?(Parfait::Method)
@name = name.to_sym
@branch = nil
@codes = []
end
attr_reader :name , :codes , :method , :position
attr_accessor :branch
def add_code kode
@codes << kode
@ -38,14 +36,6 @@ module Register
end
end
# returns if this is a block that ends in a call (and thus needs local variable handling)
def call_block?
raise "called"
return false unless codes.last.is_a?(CallInstruction)
return false unless codes.last.opcode == :call
codes.dup.reverse.find{ |c| c.is_a? StackInstruction }
end
# position is what another block uses to jump to. this is determined by the assembler
# the assembler allso assembles and assumes a linear instruction sequence
# Note: this will have to change for plocks and maybe anyway.
@ -67,24 +57,5 @@ module Register
@codes.inject(0){|count , instruction| count += instruction.byte_length }
end
# def reachable ret = []
# add_next ret
# add_branch ret
# ret
# end
# # helper for determining reachable blocks
# def add_next ret
# return if @next.nil?
# return if ret.include? @next
# ret << @next
# @next.reachable ret
# end
# # helper for determining reachable blocks
# def add_branch ret
# return if @branch.nil?
# return if ret.include? @branch
# ret << @branch
# @branch.reachable ret
# end
end
end

View File

@ -90,18 +90,18 @@ module Register
# return a list of registers that are still in use after the given block
# a call_site uses pushes and pops these to make them available for code after a call
def locals_at l_block
used =[]
# call assigns the return register, but as it is in l_block, it is not asked.
assigned = [ RegisterValue.new(RegisterMachine.instance.return_register) ]
l_block.reachable.each do |b|
b.uses.each {|u|
(used << u) unless assigned.include?(u)
}
assigned += b.assigns
end
used.uniq
end
# def locals_at l_block
# used =[]
# # call assigns the return register, but as it is in l_block, it is not asked.
# assigned = [ RegisterValue.new(RegisterMachine.instance.return_register) ]
# l_block.reachable.each do |b|
# b.uses.each {|u|
# (used << u) unless assigned.include?(u)
# }
# assigned += b.assigns
# end
# used.uniq
# end
# control structures need to see blocks as a graph, but they are stored as a list with implict
# branches