generalize assemblers to use callables

not just methods,  they are almost the same anyway
This commit is contained in:
Torsten Ruger
2018-07-30 10:23:42 +03:00
parent 4055709529
commit 285a88b59f
7 changed files with 16 additions and 16 deletions

View File

@ -1,12 +1,12 @@
module Risc
class Assembler
attr_reader :method , :instructions
attr_reader :callable , :instructions
def initialize( method , instructions)
@method = method
def initialize( callable , instructions)
@callable = callable
@instructions = instructions
total = instructions.total_byte_length / 4 + 1
method.binary.extend_to( total )
callable.binary.extend_to( total )
end
end
end

View File

@ -82,13 +82,13 @@ module Risc
# start at code_start.
def position_code(code_start)
assemblers.each do |asm|
Position.log.debug "Method start #{code_start.to_s(16)} #{asm.method.name}"
code_pos = CodeListener.init(asm.method.binary, platform)
Position.log.debug "Method start #{code_start.to_s(16)} #{asm.callable.name}"
code_pos = CodeListener.init(asm.callable.binary, platform)
instructions = asm.instructions
InstructionListener.init( instructions, asm.method.binary)
InstructionListener.init( instructions, asm.callable.binary)
code_pos.position_listener( LabelListener.new(instructions))
code_pos.set(code_start)
code_start = Position.get(asm.method.binary.last_code).next_slot
code_start = Position.get(asm.callable.binary.last_code).next_slot
end
end
@ -109,7 +109,7 @@ module Risc
def assemble
assemblers.each do |asm|
writer = BinaryWriter.new(asm.method.binary)
writer = BinaryWriter.new(asm.callable.binary)
writer.assemble(asm.instructions)
end
end
@ -119,8 +119,8 @@ module Risc
# risc_init is a branch to the __init__ method
#
def cpu_init_init
init = assemblers.find {|asm| asm.method.name == :__init__}
risc_init = Branch.new( "__initial_branch__" , init.method.binary )
init = assemblers.find {|asm| asm.callable.name == :__init__}
risc_init = Branch.new( "__initial_branch__" , init.callable.binary )
@platform.translator.translate(risc_init)
end

View File

@ -60,7 +60,7 @@ module Risc
# Really like any other object, it's just about the ordering
def write_code
@linker.assemblers.each do |asm|
asm.method.each_binary do |code|
asm.callable.each_binary do |code|
write_any(code)
end
end