cleanup
This commit is contained in:
parent
46a5eefbd4
commit
e61ef93943
@ -12,14 +12,15 @@ module Parfait
|
|||||||
def initialize(total_size)
|
def initialize(total_size)
|
||||||
super()
|
super()
|
||||||
if total_size > self.data_length
|
if total_size > self.data_length
|
||||||
@next = BinaryCode.new(total_size - data_length) #one for the jump
|
@next = BinaryCode.new(total_size - data_length)
|
||||||
end
|
end
|
||||||
#puts "Init with #{total_size} for #{object_id}"
|
puts "Init with #{total_size} for #{object_id}"
|
||||||
(1..(data_length+1)).each{ |index| set_word(index , 0) }
|
(1..(data_length+1)).each{ |index| set_word(index , 0) }
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
"BinaryCode #{}"
|
"BinaryCode #{}"
|
||||||
end
|
end
|
||||||
|
#16 - 2 -1 , two instance varaibles and one for the jump
|
||||||
def data_length
|
def data_length
|
||||||
13
|
13
|
||||||
end
|
end
|
||||||
|
@ -33,26 +33,27 @@ module Risc
|
|||||||
at += 8 # thats the padding
|
at += 8 # thats the padding
|
||||||
# want to have the objects first in the executable
|
# want to have the objects first in the executable
|
||||||
@objects.each do | id , objekt|
|
@objects.each do | id , objekt|
|
||||||
if objekt.is_a? Risc::Label # will get assembled as method.cpu_instructions
|
case objekt
|
||||||
|
when Risc::Label # will get assembled as method.cpu_instructions
|
||||||
Positioned.set_position(objekt,at)
|
Positioned.set_position(objekt,at)
|
||||||
next
|
when Parfait::BinaryCode
|
||||||
end
|
else
|
||||||
next if objekt.is_a? Parfait::BinaryCode
|
|
||||||
Positioned.set_position(objekt,at)
|
Positioned.set_position(objekt,at)
|
||||||
at += objekt.padded_length
|
at += objekt.padded_length
|
||||||
end
|
end
|
||||||
|
end
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
def position_code_from( at )
|
def position_code_from( at )
|
||||||
@objects.each do |id , objekt|
|
@objects.each do |id , method|
|
||||||
next unless objekt.is_a? Parfait::TypedMethod
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
log.debug "CODE1 #{objekt.name}"
|
log.debug "CODE1 #{method.name}"
|
||||||
# create binary for assembly
|
# create binary for assembly
|
||||||
objekt.create_binary if objekt.is_a? Parfait::TypedMethod
|
method.create_binary
|
||||||
binary = objekt.binary
|
binary = method.binary
|
||||||
Positioned.set_position(binary,at)
|
Positioned.set_position(binary,at)
|
||||||
objekt.cpu_instructions.set_position( at + 12) # BinaryCode header
|
method.cpu_instructions.set_position( at + 12) # BinaryCode header
|
||||||
len = 4 * 14
|
len = 4 * 14
|
||||||
at += binary.padded_length
|
at += binary.padded_length
|
||||||
nekst = binary.next
|
nekst = binary.next
|
||||||
@ -63,7 +64,7 @@ module Risc
|
|||||||
len += 4 * 16
|
len += 4 * 16
|
||||||
#puts "LENGTH #{len}"
|
#puts "LENGTH #{len}"
|
||||||
end
|
end
|
||||||
log.debug "CODE2 #{objekt.name} at #{Positioned.position(binary)} len: #{len}"
|
log.debug "CODE2 #{method.name} at #{Positioned.position(binary)} len: #{len}"
|
||||||
end
|
end
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
@ -74,7 +75,7 @@ module Risc
|
|||||||
write_debug
|
write_debug
|
||||||
write_create_binary
|
write_create_binary
|
||||||
write_objects
|
write_objects
|
||||||
write_method
|
write_code
|
||||||
log.debug "Assembled #{stream_position} bytes"
|
log.debug "Assembled #{stream_position} bytes"
|
||||||
return @stream.string
|
return @stream.string
|
||||||
end
|
end
|
||||||
@ -111,7 +112,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_method
|
def write_code
|
||||||
# then write the methods to file
|
# then write the methods to file
|
||||||
@objects.each do |id, objekt|
|
@objects.each do |id, objekt|
|
||||||
next unless objekt.is_a? Parfait::BinaryCode
|
next unless objekt.is_a? Parfait::BinaryCode
|
||||||
@ -121,7 +122,7 @@ module Risc
|
|||||||
|
|
||||||
# assemble the MethodSource into a stringio
|
# assemble the MethodSource into a stringio
|
||||||
# and then plonk that binary data into the method.code array
|
# and then plonk that binary data into the method.code array
|
||||||
def assemble_binary_method method
|
def assemble_binary_method( method )
|
||||||
stream = StringIO.new
|
stream = StringIO.new
|
||||||
#puts "Method #{method.source.cpu_instructions.to_ac}"
|
#puts "Method #{method.source.cpu_instructions.to_ac}"
|
||||||
begin
|
begin
|
||||||
|
@ -36,24 +36,10 @@ module Risc
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
# derived classes must provide a byte_length
|
|
||||||
def byte_length
|
|
||||||
raise "Abstract called on #{self}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_cpu( translator )
|
def to_cpu( translator )
|
||||||
translator.translate( self )
|
translator.translate( self )
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_all( io )
|
|
||||||
self.assemble(io)
|
|
||||||
self.next.assemble_all(io) if self.next
|
|
||||||
end
|
|
||||||
|
|
||||||
def assemble io
|
|
||||||
raise "Abstract called on #{self}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_byte_length
|
def total_byte_length
|
||||||
ret = 0
|
ret = 0
|
||||||
self.each{|ins| ret += ins.byte_length}
|
self.each{|ins| ret += ins.byte_length}
|
||||||
|
@ -31,6 +31,10 @@ module Risc
|
|||||||
@name.split(".").length == 2
|
@name.split(".").length == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assemble_all( io )
|
||||||
|
self.each {|ins| ins.assemble(io)}
|
||||||
|
end
|
||||||
|
|
||||||
def assemble io
|
def assemble io
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user