make the interpreter platform
but still using the risc_instruction stream
This commit is contained in:
38
lib/risc/interpreter_platform.rb
Normal file
38
lib/risc/interpreter_platform.rb
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
module Risc
|
||||
class InterpreterPlatform
|
||||
def translator
|
||||
IdentityTranslator.new
|
||||
end
|
||||
def loaded_at
|
||||
0x90
|
||||
end
|
||||
def padding
|
||||
0x100 - loaded_at
|
||||
end
|
||||
end
|
||||
class Instruction
|
||||
def nil_next
|
||||
@next = nil
|
||||
end
|
||||
def byte_length
|
||||
4
|
||||
end
|
||||
def assemble(io)
|
||||
io.write_unsigned_int_32(self)
|
||||
end
|
||||
class Branch < Instruction
|
||||
def first
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
class IdentityTranslator
|
||||
def translate(code)
|
||||
return Label.new( code.source , code.name ) if code.is_a?(Label)
|
||||
ret = code.dup
|
||||
ret.nil_next
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
@ -125,7 +125,7 @@ module Risc
|
||||
writer = BinaryWriter.new(method.binary)
|
||||
writer.assemble(method.cpu_instructions)
|
||||
end
|
||||
log.debug "BinaryInit #{cpu_init.first.object_id.to_s(16)}"
|
||||
log.debug "BinaryInit #{cpu_init.object_id.to_s(16)}"
|
||||
end
|
||||
|
||||
def boot
|
||||
|
@ -15,14 +15,17 @@ module Risc
|
||||
end
|
||||
# Factory method to create a Platform object according to the platform
|
||||
# string given.
|
||||
# Currently only "Arm"
|
||||
# Currently only "Arm" and "Interpreter"
|
||||
def self.for( name )
|
||||
case name
|
||||
when "Arm"
|
||||
return Arm::ArmPlatform.new
|
||||
when "Interpreter"
|
||||
return Risc::InterpreterPlatform.new
|
||||
else
|
||||
raise "not recignized platform #{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
require_relative "interpreter_platform"
|
||||
|
Reference in New Issue
Block a user