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

@ -24,7 +24,7 @@ module Elf
# for debug add labels for labels
@linker.assemblers.each do |asm|
meth = asm.method
meth = asm.callable
asm.instructions.each do |label|
next unless label.is_a?(Risc::Label)
add_symbol "#{meth.self_type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at

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

View File

@ -30,7 +30,7 @@ module Risc
def produce_instructions
assert @expect , "No output given"
linker = RubyX::RubyXCompiler.new(as_test_main).ruby_to_risc(:interpreter)
compiler = linker.assemblers.find{|c| c.method.name == :main and c.method.self_type.object_class.name == :Test}
compiler = linker.assemblers.find{|c| c.callable.name == :main and c.callable.self_type.object_class.name == :Test}
compiler.instructions
end
def check_nil

View File

@ -14,7 +14,7 @@ module Risc
end
end
def test_one_main
mains = @linker.assemblers.find_all{|asm| asm.method.name == :main }
mains = @linker.assemblers.find_all{|asm| asm.callable.name == :main }
assert_equal 1 , mains.length
end
def test_assembler_num

View File

@ -14,7 +14,7 @@ module RubyX
assert_equal Risc::Linker , @linker.class
end
def test_method
assert_equal :main , @linker.assemblers.first.method.name
assert_equal :main , @linker.assemblers.first.callable.name
end
end
end