generalize assemblers to use callables
not just methods, they are almost the same anyway
This commit is contained in:
parent
4055709529
commit
285a88b59f
@ -24,7 +24,7 @@ module Elf
|
|||||||
|
|
||||||
# for debug add labels for labels
|
# for debug add labels for labels
|
||||||
@linker.assemblers.each do |asm|
|
@linker.assemblers.each do |asm|
|
||||||
meth = asm.method
|
meth = asm.callable
|
||||||
asm.instructions.each do |label|
|
asm.instructions.each do |label|
|
||||||
next unless label.is_a?(Risc::Label)
|
next unless label.is_a?(Risc::Label)
|
||||||
add_symbol "#{meth.self_type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at
|
add_symbol "#{meth.self_type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Risc
|
module Risc
|
||||||
class Assembler
|
class Assembler
|
||||||
attr_reader :method , :instructions
|
attr_reader :callable , :instructions
|
||||||
|
|
||||||
def initialize( method , instructions)
|
def initialize( callable , instructions)
|
||||||
@method = method
|
@callable = callable
|
||||||
@instructions = instructions
|
@instructions = instructions
|
||||||
total = instructions.total_byte_length / 4 + 1
|
total = instructions.total_byte_length / 4 + 1
|
||||||
method.binary.extend_to( total )
|
callable.binary.extend_to( total )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -82,13 +82,13 @@ module Risc
|
|||||||
# start at code_start.
|
# start at code_start.
|
||||||
def position_code(code_start)
|
def position_code(code_start)
|
||||||
assemblers.each do |asm|
|
assemblers.each do |asm|
|
||||||
Position.log.debug "Method start #{code_start.to_s(16)} #{asm.method.name}"
|
Position.log.debug "Method start #{code_start.to_s(16)} #{asm.callable.name}"
|
||||||
code_pos = CodeListener.init(asm.method.binary, platform)
|
code_pos = CodeListener.init(asm.callable.binary, platform)
|
||||||
instructions = asm.instructions
|
instructions = asm.instructions
|
||||||
InstructionListener.init( instructions, asm.method.binary)
|
InstructionListener.init( instructions, asm.callable.binary)
|
||||||
code_pos.position_listener( LabelListener.new(instructions))
|
code_pos.position_listener( LabelListener.new(instructions))
|
||||||
code_pos.set(code_start)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ module Risc
|
|||||||
|
|
||||||
def assemble
|
def assemble
|
||||||
assemblers.each do |asm|
|
assemblers.each do |asm|
|
||||||
writer = BinaryWriter.new(asm.method.binary)
|
writer = BinaryWriter.new(asm.callable.binary)
|
||||||
writer.assemble(asm.instructions)
|
writer.assemble(asm.instructions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -119,8 +119,8 @@ module Risc
|
|||||||
# risc_init is a branch to the __init__ method
|
# risc_init is a branch to the __init__ method
|
||||||
#
|
#
|
||||||
def cpu_init_init
|
def cpu_init_init
|
||||||
init = assemblers.find {|asm| asm.method.name == :__init__}
|
init = assemblers.find {|asm| asm.callable.name == :__init__}
|
||||||
risc_init = Branch.new( "__initial_branch__" , init.method.binary )
|
risc_init = Branch.new( "__initial_branch__" , init.callable.binary )
|
||||||
@platform.translator.translate(risc_init)
|
@platform.translator.translate(risc_init)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ module Risc
|
|||||||
# Really like any other object, it's just about the ordering
|
# Really like any other object, it's just about the ordering
|
||||||
def write_code
|
def write_code
|
||||||
@linker.assemblers.each do |asm|
|
@linker.assemblers.each do |asm|
|
||||||
asm.method.each_binary do |code|
|
asm.callable.each_binary do |code|
|
||||||
write_any(code)
|
write_any(code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,7 @@ module Risc
|
|||||||
def produce_instructions
|
def produce_instructions
|
||||||
assert @expect , "No output given"
|
assert @expect , "No output given"
|
||||||
linker = RubyX::RubyXCompiler.new(as_test_main).ruby_to_risc(:interpreter)
|
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
|
compiler.instructions
|
||||||
end
|
end
|
||||||
def check_nil
|
def check_nil
|
||||||
|
@ -14,7 +14,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_one_main
|
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
|
assert_equal 1 , mains.length
|
||||||
end
|
end
|
||||||
def test_assembler_num
|
def test_assembler_num
|
||||||
|
@ -14,7 +14,7 @@ module RubyX
|
|||||||
assert_equal Risc::Linker , @linker.class
|
assert_equal Risc::Linker , @linker.class
|
||||||
end
|
end
|
||||||
def test_method
|
def test_method
|
||||||
assert_equal :main , @linker.assemblers.first.method.name
|
assert_equal :main , @linker.assemblers.first.callable.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user