2019-08-08 12:19:27 +03:00
|
|
|
module Risc
|
|
|
|
# The Collection for the Risc level is a collection of Risc level Method compilers,
|
2018-11-02 15:54:30 -07:00
|
|
|
# plus functions to translate from the risc to cpu specific code.
|
|
|
|
#
|
2019-08-08 12:19:27 +03:00
|
|
|
class RiscCollection
|
2018-07-02 15:50:54 +03:00
|
|
|
attr_reader :method_compilers
|
2018-06-30 19:20:17 +03:00
|
|
|
|
2018-11-02 15:54:30 -07:00
|
|
|
# Initialize with an array of risc MethodCompilers
|
2018-07-01 21:26:45 +03:00
|
|
|
def initialize(compilers = [])
|
2019-09-28 15:07:20 +03:00
|
|
|
@method_compilers = nil
|
|
|
|
compilers.each{|c| add_compiler(c)}
|
2018-11-02 15:54:30 -07:00
|
|
|
end
|
|
|
|
|
2018-07-03 10:12:22 +03:00
|
|
|
# collects constants from all compilers into one array
|
|
|
|
def constants
|
2019-09-28 15:07:20 +03:00
|
|
|
all = []
|
|
|
|
method_compilers.each_compiler{|comp| all += comp.constants }
|
|
|
|
all
|
2018-11-02 15:54:30 -07:00
|
|
|
end
|
|
|
|
|
2019-09-28 15:07:20 +03:00
|
|
|
def append(collection)
|
|
|
|
@method_compilers.add_method_compiler( collection.method_compilers)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_compiler(compiler)
|
|
|
|
if(@method_compilers)
|
|
|
|
@method_compilers.add_method_compiler(compiler)
|
|
|
|
else
|
|
|
|
@method_compilers = compiler
|
|
|
|
end
|
2018-11-02 15:54:30 -07:00
|
|
|
self
|
2018-07-03 10:12:22 +03:00
|
|
|
end
|
|
|
|
|
2018-06-30 22:53:32 +03:00
|
|
|
# Translate code to whatever cpu is specified.
|
|
|
|
# Currently only :arm and :interpret
|
|
|
|
#
|
|
|
|
# Translating means translating the initial jump
|
|
|
|
# and then translating all methods
|
2018-07-01 11:56:09 +03:00
|
|
|
def translate( platform_sym )
|
|
|
|
platform_sym = platform_sym.to_s.capitalize
|
2020-03-16 17:32:24 +02:00
|
|
|
platform = Platform.for(platform_sym)
|
2019-09-28 15:34:09 +03:00
|
|
|
assemblers = []
|
|
|
|
@method_compilers.each_compiler do |compiler|
|
2020-03-17 21:46:57 +02:00
|
|
|
compiler.translate_method( platform , assemblers)
|
2018-06-30 22:53:32 +03:00
|
|
|
end
|
2019-09-28 15:34:09 +03:00
|
|
|
Risc::Linker.new(platform , assemblers , constants)
|
2018-07-01 11:56:09 +03:00
|
|
|
end
|
|
|
|
|
2018-06-30 19:20:17 +03:00
|
|
|
end
|
|
|
|
end
|