start on new binary creation process
now writing into BinaryCode instead of stream also in the risc layer, not arm, for reusability
This commit is contained in:
parent
2e57674008
commit
500851d246
34
lib/risc/binary_writer.rb
Normal file
34
lib/risc/binary_writer.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
module Risc
|
||||||
|
# Little glue class to get the assembled binary from the Arm Instructions into
|
||||||
|
# the BinaryCode instances. Arm code originally uses io, but slightly modified
|
||||||
|
# really only uses write_unsigned_int_32 , which converts
|
||||||
|
# to an set_internal_word on the BinaryCode
|
||||||
|
#
|
||||||
|
# Machine instantiates and the writer reads from the arm Instructions
|
||||||
|
# and writes to the BinaryCode
|
||||||
|
class BinaryWriter
|
||||||
|
def initialize( code )
|
||||||
|
@code = code
|
||||||
|
end
|
||||||
|
|
||||||
|
# write into the given BinaryCode instance
|
||||||
|
def assemble( instruction )
|
||||||
|
@index = 1
|
||||||
|
while(instruction)
|
||||||
|
begin
|
||||||
|
instruction.assemble(self)
|
||||||
|
rescue LinkException
|
||||||
|
instruction.assemble(self)
|
||||||
|
end
|
||||||
|
instruction = instruction.next
|
||||||
|
puts "Next #{instruction.to_s}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_unsigned_int_32( bin )
|
||||||
|
@code.set_word( @index , bin )
|
||||||
|
@index += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,4 +1,5 @@
|
|||||||
require_relative "collector"
|
require_relative "collector"
|
||||||
|
require_relative "binary_writer"
|
||||||
|
|
||||||
module Risc
|
module Risc
|
||||||
# The Risc Machine is an abstraction of the register level. This is seperate from the
|
# The Risc Machine is an abstraction of the register level. This is seperate from the
|
||||||
@ -93,6 +94,15 @@ module Risc
|
|||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_binary
|
||||||
|
objects.each do |id , method|
|
||||||
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
|
puts "CODE1 #{method.name}:#{}"
|
||||||
|
writer = BinaryWriter.new(method.binary)
|
||||||
|
writer.assemble(method.cpu_instructions)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
initialize
|
initialize
|
||||||
@objects = nil
|
@objects = nil
|
||||||
|
@ -28,8 +28,9 @@ module Risc
|
|||||||
assert @assembler.assemble
|
assert @assembler.assemble
|
||||||
end
|
end
|
||||||
def test_write_space
|
def test_write_space
|
||||||
@assembler = Assembler.new(@machine , Collector.collect_space)
|
|
||||||
assert @machine.translate_arm
|
assert @machine.translate_arm
|
||||||
|
assert @machine.position_all
|
||||||
|
@assembler = Assembler.new(@machine , Collector.collect_space)
|
||||||
#assert @assembler.write_as_string
|
#assert @assembler.write_as_string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,13 +6,11 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
@machine = Risc.machine.boot
|
@machine = Risc.machine.boot
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_objects
|
def test_objects
|
||||||
objects = @machine.objects
|
objects = @machine.objects
|
||||||
assert_equal Hash , objects.class
|
assert_equal Hash , objects.class
|
||||||
assert 350 < objects.length
|
assert 350 < objects.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_position_length
|
def test_position_length
|
||||||
@machine.position_all
|
@machine.position_all
|
||||||
objects = @machine.objects
|
objects = @machine.objects
|
||||||
@ -25,5 +23,9 @@ module Risc
|
|||||||
assert Positioned.position(obj)
|
assert Positioned.position(obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def test_binary
|
||||||
|
@machine.position_all
|
||||||
|
@machine.create_binary
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user