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
|
||||
class ClassCompiler
|
||||
attr_reader :clazz , :methods
|
||||
attr_reader :clazz , :method_compilers
|
||||
|
||||
def initialize(clazz , methods)
|
||||
def initialize(clazz , compilers)
|
||||
@clazz = clazz
|
||||
@methods = methods
|
||||
@method_compilers = compilers
|
||||
end
|
||||
|
||||
|
||||
# Translate code to whatever cpu is specified.
|
||||
# Currently only :arm and :interpret
|
||||
#
|
||||
# Translating means translating the initial jump
|
||||
# and then translating all methods
|
||||
def translate( platform )
|
||||
platform = platform.to_s.capitalize
|
||||
@platform = Risc::Platform.for(platform)
|
||||
translate_methods( @platform.translator )
|
||||
def translate( platform_sym )
|
||||
platform_sym = platform_sym.to_s.capitalize
|
||||
platform = Risc::Platform.for(platform_sym)
|
||||
translate_methods( platform.translator )
|
||||
#@cpu_init = risc_init.to_cpu(@platform.translator)
|
||||
end
|
||||
|
||||
# go through all methods and translate them to cpu, given the translator
|
||||
def translate_methods(translator)
|
||||
Parfait.object_space.get_all_methods.each do |method|
|
||||
#log.debug "Translate method #{method.name}"
|
||||
method.translate_cpu(translator)
|
||||
method_compilers.collect do |compiler|
|
||||
#log.debug "Translate method #{compiler.method.name}"
|
||||
translate_cpu(compiler , translator)
|
||||
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
|
||||
|
@ -24,12 +24,12 @@ module Vool
|
||||
|
||||
def to_mom( _ )
|
||||
create_class_object
|
||||
methods = []
|
||||
method_compilers = []
|
||||
body.statements.each do |node|
|
||||
raise "Only methods for now #{node}" unless node.is_a?(MethodStatement)
|
||||
methods << node.to_mom(@clazz)
|
||||
method_compilers << node.to_mom(@clazz)
|
||||
end
|
||||
Mom::ClassCompiler.new(@clazz , methods)
|
||||
Mom::ClassCompiler.new(@clazz , method_compilers)
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
|
Loading…
x
Reference in New Issue
Block a user