split create_binary into two phases
Which gives instructions a chance to check everything and in Arms case check the constant loads/ instruction adding So that during assembly no more change happens (and we don't have to reassemble)
This commit is contained in:
parent
c94f6eaa78
commit
3298651238
@ -1,4 +1,6 @@
|
|||||||
require "util/list"
|
require "util/list"
|
||||||
|
require "util/dev_null"
|
||||||
|
|
||||||
module Arm
|
module Arm
|
||||||
# Arm instruction base class
|
# Arm instruction base class
|
||||||
# Mostly linked list functionality that all instructions have
|
# Mostly linked list functionality that all instructions have
|
||||||
@ -21,6 +23,13 @@ module Arm
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# precheck that everything is ok, before asembly
|
||||||
|
# in arm, we use the oppertunity to assemble to dev_null, so any
|
||||||
|
# additions are done _before_ assemnly
|
||||||
|
def precheck
|
||||||
|
assemble(Util::DevNull.new)
|
||||||
|
end
|
||||||
|
|
||||||
def insert(instruction)
|
def insert(instruction)
|
||||||
ret = super
|
ret = super
|
||||||
Risc::Position.get(self).trigger_inserted if Risc::Position.set?(self)
|
Risc::Position.get(self).trigger_inserted if Risc::Position.set?(self)
|
||||||
|
@ -37,6 +37,10 @@ module Risc
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# just part of the protocol, noop in this case
|
||||||
|
def precheck
|
||||||
|
end
|
||||||
|
|
||||||
def to_cpu( translator )
|
def to_cpu( translator )
|
||||||
translator.translate( self )
|
translator.translate( self )
|
||||||
end
|
end
|
||||||
|
@ -22,6 +22,7 @@ module Risc
|
|||||||
@constants = []
|
@constants = []
|
||||||
@next_address = nil
|
@next_address = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :constants , :cpu_init
|
attr_reader :constants , :cpu_init
|
||||||
attr_reader :booted , :translated
|
attr_reader :booted , :translated
|
||||||
attr_reader :platform
|
attr_reader :platform
|
||||||
@ -143,12 +144,23 @@ module Risc
|
|||||||
# constant loads into one instruction.
|
# constant loads into one instruction.
|
||||||
#
|
#
|
||||||
def create_binary
|
def create_binary
|
||||||
object_positions.keys.each do |method|
|
methods = object_positions.keys.find_all{|obj| obj.is_a? Parfait::TypedMethod}
|
||||||
next unless method.is_a? Parfait::TypedMethod
|
prerun(methods)
|
||||||
|
assemble(methods)
|
||||||
|
log.debug "BinaryInit #{cpu_init.object_id.to_s(16)}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def prerun(methods)
|
||||||
|
methods.each do |method|
|
||||||
|
method.cpu_instructions.each {|i| i.precheck }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def assemble(methods)
|
||||||
|
methods.each do |method|
|
||||||
writer = BinaryWriter.new(method.binary)
|
writer = BinaryWriter.new(method.binary)
|
||||||
writer.assemble(method.cpu_instructions)
|
writer.assemble(method.cpu_instructions)
|
||||||
end
|
end
|
||||||
log.debug "BinaryInit #{cpu_init.object_id.to_s(16)}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
|
7
lib/util/dev_null.rb
Normal file
7
lib/util/dev_null.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module Util
|
||||||
|
# A class that does not write, or swallows all incoming data
|
||||||
|
# Used in Arm to do a dry run (and in testing, where it was born)
|
||||||
|
class DevNull
|
||||||
|
def write_unsigned_int_32( _ );end
|
||||||
|
end
|
||||||
|
end
|
@ -1,4 +1 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
class DevNull
|
|
||||||
def write_unsigned_int_32( _ );end
|
|
||||||
end
|
|
||||||
|
@ -57,7 +57,7 @@ module Risc
|
|||||||
@machine.object_positions.each do | method , position|
|
@machine.object_positions.each do | method , position|
|
||||||
next unless method.is_a? Parfait::TypedMethod
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
method.cpu_instructions.each do |ins|
|
method.cpu_instructions.each do |ins|
|
||||||
ins.assemble(DevNull.new)
|
ins.assemble(Util::DevNull.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -33,7 +33,7 @@ module Risc
|
|||||||
@machine.object_positions.keys.each do |method|
|
@machine.object_positions.keys.each do |method|
|
||||||
next unless method.is_a? Parfait::TypedMethod
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
method.cpu_instructions.each do |ins|
|
method.cpu_instructions.each do |ins|
|
||||||
ins.assemble(DevNull.new)
|
ins.assemble(Util::DevNull.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user