most of the length and assembly stuff fixed
This commit is contained in:
parent
405a6935d4
commit
471329917b
@ -28,17 +28,17 @@ module Register
|
|||||||
@machine.objects.each do |id , objekt|
|
@machine.objects.each do |id , objekt|
|
||||||
next unless objekt.is_a? Parfait::Method
|
next unless objekt.is_a? Parfait::Method
|
||||||
# should be fill_to_length (with zeros)
|
# should be fill_to_length (with zeros)
|
||||||
objekt.binary.set_length(objekt.source.byte_length , 0)
|
objekt.binary.set_length(objekt.source.total_byte_length , 0)
|
||||||
end
|
end
|
||||||
#need the initial jump at 0 and then functions
|
#need the initial jump at 0 and then functions
|
||||||
@machine.init.set_position(at)
|
@machine.init.set_position(at)
|
||||||
at += @machine.init.byte_length
|
at += @machine.init.total_byte_length
|
||||||
at += 8 # thats the padding
|
at += 8 # thats the padding
|
||||||
|
|
||||||
# then we make sure we really get the binary codes first
|
# then we make sure we really get the binary codes first
|
||||||
@machine.objects.each do |id , objekt|
|
@machine.objects.each do |id , objekt|
|
||||||
next unless objekt.is_a? Parfait::BinaryCode
|
next unless objekt.is_a? Parfait::BinaryCode
|
||||||
objekt.set_position at
|
objekt.position = at
|
||||||
#puts "CODE #{objekt.name} at #{objekt.position}"
|
#puts "CODE #{objekt.name} at #{objekt.position}"
|
||||||
at += objekt.word_length
|
at += objekt.word_length
|
||||||
end
|
end
|
||||||
@ -50,7 +50,7 @@ module Register
|
|||||||
objekt.source.set_position( objekt.binary.position )
|
objekt.source.set_position( objekt.binary.position )
|
||||||
end
|
end
|
||||||
next if objekt.is_a? Parfait::BinaryCode
|
next if objekt.is_a? Parfait::BinaryCode
|
||||||
objekt.set_position at
|
objekt.position = at
|
||||||
at += objekt.word_length
|
at += objekt.word_length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -61,6 +61,7 @@ module Register
|
|||||||
return try_write
|
return try_write
|
||||||
rescue LinkException
|
rescue LinkException
|
||||||
# knowing that we fix the problem, we hope to get away with retry.
|
# knowing that we fix the problem, we hope to get away with retry.
|
||||||
|
puts "retry"
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -106,23 +107,20 @@ module Register
|
|||||||
# 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
|
||||||
method.source.blocks.each do |block|
|
puts "Method #{method.source.instructions.to_ac}"
|
||||||
block.codes.each do |code|
|
|
||||||
begin
|
begin
|
||||||
code.assemble( stream )
|
puts "assemble #{method.source.instructions}"
|
||||||
|
method.source.instructions.assemble_all( stream )
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "Assembly error #{method.name}\n#{Sof.write(method.source.blocks).to_s[0...2000]}"
|
puts "Assembly error #{method.name}\n#{Sof.write(method.source.instructions).to_s[0...2000]}"
|
||||||
puts Sof.write(code)
|
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
method.binary.fill_with 0
|
method.binary.fill_with 0
|
||||||
index = 1
|
index = 1
|
||||||
stream.rewind
|
stream.rewind
|
||||||
#puts "Assembled #{method.name} with length #{stream.length}"
|
#puts "Assembled #{method.name} with length #{stream.length}"
|
||||||
raise "length error #{method.binary.length} != #{method.source.byte_length}" if method.binary.length != method.source.byte_length
|
raise "length error #{method.binary.length} != #{method.source.total_byte_length}" if method.binary.length != method.source.total_byte_length
|
||||||
raise "length error #{stream.length} != #{method.source.byte_length}" if method.source.byte_length != stream.length
|
raise "length error #{stream.length} != #{method.source.total_byte_length}" if method.source.total_byte_length != stream.length
|
||||||
stream.each_byte do |b|
|
stream.each_byte do |b|
|
||||||
method.binary.set_char(index , b )
|
method.binary.set_char(index , b )
|
||||||
index = index + 1
|
index = index + 1
|
||||||
@ -229,6 +227,7 @@ module Register
|
|||||||
@stream.write_uint8(0)
|
@stream.write_uint8(0)
|
||||||
end
|
end
|
||||||
after = stream_position
|
after = stream_position
|
||||||
|
before - after # shut up the linter
|
||||||
#puts "padded #{length.to_s(16)} with #{pad.to_s(16)} stream #{before}/#{after}"
|
#puts "padded #{length.to_s(16)} with #{pad.to_s(16)} stream #{before}/#{after}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,9 +81,19 @@ module Register
|
|||||||
raise "Abstract called on #{self}"
|
raise "Abstract called on #{self}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assemble_all io , labels = []
|
||||||
|
self.assemble(io)
|
||||||
|
self.next.assemble_all(io, labels) if self.next
|
||||||
|
end
|
||||||
|
|
||||||
|
def assemble io
|
||||||
|
raise "Abstract called on #{self}"
|
||||||
|
end
|
||||||
|
|
||||||
def total_byte_length labels = []
|
def total_byte_length labels = []
|
||||||
ret = self.byte_length
|
ret = self.byte_length
|
||||||
ret += self.next.total_byte_length(labels) if self.next
|
ret += self.next.total_byte_length(labels) if self.next
|
||||||
|
#puts "#{self.class.name} return #{ret}"
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,8 +27,9 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def total_byte_length labels = []
|
def total_byte_length labels = []
|
||||||
ret = super
|
ret = super(labels)
|
||||||
ret += label.total_byte_length(labels) if self.label
|
ret += self.label.total_byte_length(labels) if self.label
|
||||||
|
#puts "#{self.class.name} return #{ret}"
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -38,6 +39,12 @@ module Register
|
|||||||
super(position,labels)
|
super(position,labels)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assemble_all io , labels = []
|
||||||
|
self.assemble(io)
|
||||||
|
self.label.assemble_all(io,labels) if self.label
|
||||||
|
self.next.assemble_all(io, labels) if self.next
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class IsZero < Branch
|
class IsZero < Branch
|
||||||
|
@ -32,14 +32,21 @@ module Register
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def byte_length
|
def assemble io
|
||||||
0
|
end
|
||||||
|
|
||||||
|
def assemble_all io , labels = []
|
||||||
|
return if labels.include?(self)
|
||||||
|
labels << self
|
||||||
|
self.next.assemble_all(io,labels)
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_byte_length labels = []
|
def total_byte_length labels = []
|
||||||
return 0 if labels.include?(self)
|
return 0 if labels.include?(self)
|
||||||
labels << self
|
labels << self
|
||||||
self.next.length(labels)
|
ret = self.next.total_byte_length(labels)
|
||||||
|
#puts "#{self.class.name} return #{ret}"
|
||||||
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
# labels have the same position as their next
|
# labels have the same position as their next
|
||||||
|
@ -33,10 +33,8 @@ module Register
|
|||||||
end
|
end
|
||||||
methods.each do |method|
|
methods.each do |method|
|
||||||
instruction = method.instructions
|
instruction = method.instructions
|
||||||
puts "instruction #{instruction.to_ac}" #if instruction.is_a?(Label) and instruction.name == "Method_main"
|
|
||||||
while instruction.next
|
while instruction.next
|
||||||
nekst = instruction.next
|
nekst = instruction.next
|
||||||
puts "translate #{nekst}"
|
|
||||||
t = translator.translate(nekst) # returning nil means no replace
|
t = translator.translate(nekst) # returning nil means no replace
|
||||||
if t
|
if t
|
||||||
nekst = t.last
|
nekst = t.last
|
||||||
@ -44,7 +42,6 @@ module Register
|
|||||||
end
|
end
|
||||||
instruction = nekst
|
instruction = nekst
|
||||||
end
|
end
|
||||||
puts "instruction #{method.instructions.to_ac}" #if method.instructions.is_a?(Label) and method.instructions.name == "Method_main"
|
|
||||||
end
|
end
|
||||||
label = @init.next
|
label = @init.next
|
||||||
@init = translator.translate( @init)
|
@init = translator.translate( @init)
|
||||||
|
@ -83,7 +83,7 @@ module Register
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def byte_length
|
def total_byte_length
|
||||||
@instructions.total_byte_length
|
@instructions.total_byte_length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user