2018-05-12 17:32:10 +02:00
|
|
|
module Risc
|
|
|
|
# A platform is (or will be) something like the linux tripple
|
|
|
|
#
|
|
|
|
# Currently it just provides a Translator and binary start point
|
|
|
|
#
|
|
|
|
class Platform
|
|
|
|
|
|
|
|
# return the translator instance that traslates risc intructions into
|
|
|
|
# platform specific ones
|
|
|
|
def translator
|
2020-03-19 17:18:22 +01:00
|
|
|
raise "not implemented in #{self.class}"
|
2018-05-12 17:32:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# return an integer where the binary is loaded
|
|
|
|
def loaded_at
|
2020-03-19 17:18:22 +01:00
|
|
|
raise "not implemented in #{self.class}"
|
2018-05-12 17:32:10 +02:00
|
|
|
end
|
2020-02-26 18:01:01 +01:00
|
|
|
|
2020-03-19 17:18:22 +01:00
|
|
|
# return an array of register names that should be used by the allocator
|
|
|
|
# does not include :message
|
|
|
|
# could be in interpreter and arm, but here for now
|
|
|
|
def register_names
|
|
|
|
(1 ... 16).collect{|i| "r#{i}".to_sym }
|
2020-03-18 14:27:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# return the Allocator for the platform
|
|
|
|
# stanrard implementation return StandardAllocator, which uses
|
|
|
|
# num_registers and assumes rXX naming (ie arm + interpreter)
|
|
|
|
#
|
|
|
|
# Possibility to override and implemented different schemes
|
|
|
|
def allocator(compiler)
|
|
|
|
StandardAllocator.new(compiler , self )
|
2020-02-26 18:01:01 +01:00
|
|
|
end
|
2020-03-13 19:18:34 +01:00
|
|
|
|
2020-03-19 17:18:22 +01:00
|
|
|
def assign_reg?(name)
|
|
|
|
case name
|
|
|
|
when :message
|
|
|
|
:r0
|
|
|
|
when :syscall_1
|
|
|
|
:r0
|
|
|
|
when :syscall_2
|
|
|
|
:r1
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-12 17:32:10 +02:00
|
|
|
# Factory method to create a Platform object according to the platform
|
|
|
|
# string given.
|
2018-05-17 08:31:36 +02:00
|
|
|
# Currently only "Arm" and "Interpreter"
|
2018-05-12 17:32:10 +02:00
|
|
|
def self.for( name )
|
2018-07-02 08:36:29 +02:00
|
|
|
return name if name.is_a?(Platform)
|
|
|
|
name = name.to_s.capitalize
|
2018-05-12 17:32:10 +02:00
|
|
|
case name
|
|
|
|
when "Arm"
|
|
|
|
return Arm::ArmPlatform.new
|
2018-05-17 08:31:36 +02:00
|
|
|
when "Interpreter"
|
|
|
|
return Risc::InterpreterPlatform.new
|
2018-05-12 17:32:10 +02:00
|
|
|
else
|
2018-07-01 10:57:17 +02:00
|
|
|
raise "not recognized platform #{name.class}:#{name}"
|
2018-05-12 17:32:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-17 08:31:36 +02:00
|
|
|
require_relative "interpreter_platform"
|