rubyx/lib/risc/machine.rb

62 lines
1.7 KiB
Ruby
Raw Normal View History

require_relative "collector"
2016-12-08 19:13:08 +01:00
module Risc
# The Risc Machine is an abstraction of the register level. This is seperate from the
2016-12-06 10:38:09 +01:00
# actual assembler level to allow for several cpu architectures.
# The Instructions (see class Instruction) define what the machine can do (ie load/store/maths)
2018-03-11 11:41:15 +01:00
# From code, the next step down is Vool, then Mom (in two steps)
2014-06-25 01:33:44 +02:00
#
2015-06-20 22:49:30 +02:00
# The next step transforms to the register machine layer, which is quite close to what actually
# executes. The step after transforms to Arm, which creates executables.
2014-06-25 01:33:44 +02:00
#
2015-06-20 22:49:30 +02:00
class Machine
include Collector
include Logging
2016-12-31 14:08:32 +01:00
log_level :info
def initialize
@booted = false
2015-10-28 12:00:23 +01:00
@constants = []
end
attr_reader :constants , :risc_init , :cpu_init , :booted
# idea being that later method missing could catch translate_xxx and translate to target xxx
# now we just instantiate ArmTranslater and pass instructions
def translate_arm
methods = Parfait.object_space.collect_methods
translate_methods( methods )
@cpu_init = Arm::Translator.new.translate( @risc_init )
end
def translate_methods(methods)
translator = Arm::Translator.new
methods.each do |method|
log.debug "Translate method #{method.name}"
method.translate_cpu(translator)
2015-06-12 17:52:06 +02:00
end
end
2015-06-12 17:52:06 +02:00
def boot
initialize
2015-06-12 17:52:06 +02:00
boot_parfait!
@risc_init = Branch.new( "__initial_branch__" , Parfait.object_space.get_init.risc_instructions )
2015-06-12 17:52:06 +02:00
@booted = true
self
2015-06-12 17:52:06 +02:00
end
2014-06-25 01:33:44 +02:00
end
2015-06-12 17:52:06 +02:00
# Module function to retrieve singleton
def self.machine
unless defined?(@machine)
@machine = Machine.new
end
@machine
end
2015-06-12 17:52:06 +02:00
end
require_relative "boot"