reworking method and block assembly for new aproach
This commit is contained in:
parent
90e5b4584a
commit
d33077c2b1
@ -19,7 +19,7 @@ module Virtual
|
|||||||
@codes = []
|
@codes = []
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :name , :codes , :method
|
attr_reader :name , :codes , :method , :position
|
||||||
attr_accessor :branch
|
attr_accessor :branch
|
||||||
|
|
||||||
def reachable ret = []
|
def reachable ret = []
|
||||||
@ -48,6 +48,17 @@ module Virtual
|
|||||||
codes.dup.reverse.find{ |c| c.is_a? StackInstruction }
|
codes.dup.reverse.find{ |c| c.is_a? StackInstruction }
|
||||||
end
|
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. back to oo, no more visitors
|
||||||
|
def set_position at
|
||||||
|
@position = at
|
||||||
|
end
|
||||||
|
|
||||||
|
def length
|
||||||
|
@codes.inject(0){|count , instruction| count += instruction.length }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# helper for determining reachable blocks
|
# helper for determining reachable blocks
|
||||||
def add_next ret
|
def add_next ret
|
||||||
|
@ -162,32 +162,17 @@ module Virtual
|
|||||||
# to the current block
|
# to the current block
|
||||||
# also symbols are supported and wrapped as register usages (for bare metal programming)
|
# also symbols are supported and wrapped as register usages (for bare metal programming)
|
||||||
def method_missing(meth, *args, &block)
|
def method_missing(meth, *args, &block)
|
||||||
add_code RegisterMachine.instance.send(meth , *args)
|
add_code Register::RegisterMachine.instance.send(meth , *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
# following id the Code interface
|
# position of the function is the position of the entry block, is where we call
|
||||||
|
def set_position at
|
||||||
# to link we link the entry and then any blocks. The entry links the straight line
|
@blocks.each do |block|
|
||||||
def link_at address , context
|
blocks.set_position at
|
||||||
super #just sets the position
|
at = at + block.length
|
||||||
@entry.link_at address , context
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# position of the function is the position of the entry block
|
|
||||||
def position
|
|
||||||
@entry.position
|
|
||||||
end
|
|
||||||
|
|
||||||
# length of a function is the entry block length (includes the straight line behind it)
|
|
||||||
# plus any out of line blocks that have been added
|
|
||||||
def length
|
|
||||||
@entry.length
|
|
||||||
end
|
|
||||||
|
|
||||||
# assembling assembles the entry (straight line/ no branch line) + any additional branches
|
|
||||||
def assemble io
|
|
||||||
@entry.assemble(io)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user