return assemblers from translation
result of translate is cpu instructions, our equivalent of assembly. So return Assemblers for next stage
This commit is contained in:
parent
3813de19fc
commit
f7dfa1c45e
@ -1,30 +1,43 @@
|
|||||||
module Mom
|
module Mom
|
||||||
class ClassCompiler
|
class ClassCompiler
|
||||||
attr_reader :clazz , :methods
|
attr_reader :clazz , :method_compilers
|
||||||
|
|
||||||
def initialize(clazz , methods)
|
def initialize(clazz , compilers)
|
||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
@methods = methods
|
@method_compilers = compilers
|
||||||
end
|
end
|
||||||
|
|
||||||
# Translate code to whatever cpu is specified.
|
# Translate code to whatever cpu is specified.
|
||||||
# Currently only :arm and :interpret
|
# Currently only :arm and :interpret
|
||||||
#
|
#
|
||||||
# Translating means translating the initial jump
|
# Translating means translating the initial jump
|
||||||
# and then translating all methods
|
# and then translating all methods
|
||||||
def translate( platform )
|
def translate( platform_sym )
|
||||||
platform = platform.to_s.capitalize
|
platform_sym = platform_sym.to_s.capitalize
|
||||||
@platform = Risc::Platform.for(platform)
|
platform = Risc::Platform.for(platform_sym)
|
||||||
translate_methods( @platform.translator )
|
translate_methods( platform.translator )
|
||||||
#@cpu_init = risc_init.to_cpu(@platform.translator)
|
#@cpu_init = risc_init.to_cpu(@platform.translator)
|
||||||
end
|
end
|
||||||
|
|
||||||
# go through all methods and translate them to cpu, given the translator
|
# go through all methods and translate them to cpu, given the translator
|
||||||
def translate_methods(translator)
|
def translate_methods(translator)
|
||||||
Parfait.object_space.get_all_methods.each do |method|
|
method_compilers.collect do |compiler|
|
||||||
#log.debug "Translate method #{method.name}"
|
#log.debug "Translate method #{compiler.method.name}"
|
||||||
method.translate_cpu(translator)
|
translate_cpu(compiler , translator)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def translate_cpu(compiler , translator)
|
||||||
|
risc = compiler.risc_instructions
|
||||||
|
cpu_instructions = risc.to_cpu(translator)
|
||||||
|
nekst = risc.next
|
||||||
|
while(nekst)
|
||||||
|
cpu = nekst.to_cpu(translator) # returning nil means no replace
|
||||||
|
cpu_instructions << cpu if cpu
|
||||||
|
nekst = nekst.next
|
||||||
|
end
|
||||||
|
Risc::Assembler.new(compiler.method , cpu_instructions)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,12 +24,12 @@ module Vool
|
|||||||
|
|
||||||
def to_mom( _ )
|
def to_mom( _ )
|
||||||
create_class_object
|
create_class_object
|
||||||
methods = []
|
method_compilers = []
|
||||||
body.statements.each do |node|
|
body.statements.each do |node|
|
||||||
raise "Only methods for now #{node}" unless node.is_a?(MethodStatement)
|
raise "Only methods for now #{node}" unless node.is_a?(MethodStatement)
|
||||||
methods << node.to_mom(@clazz)
|
method_compilers << node.to_mom(@clazz)
|
||||||
end
|
end
|
||||||
Mom::ClassCompiler.new(@clazz , methods)
|
Mom::ClassCompiler.new(@clazz , method_compilers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&block)
|
def each(&block)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user