use translator and remove passes
the only passes that were left were reg -> arm those are almost completely one to one, so the idea of passes didn’t fit
This commit is contained in:
parent
a871f96630
commit
3774f8a5a2
@ -1,6 +1,15 @@
|
|||||||
module Arm
|
module Arm
|
||||||
class Translator
|
class Translator
|
||||||
|
|
||||||
|
# translator should translate from register instructio set to it's own (arm eg)
|
||||||
|
# for each instruction we call the translator with translate_XXX
|
||||||
|
# with XXX being the class name.
|
||||||
|
# the result is replaced in the stream
|
||||||
|
def translate instruction
|
||||||
|
class_name = instruction.class.name.split("::").last
|
||||||
|
self.send( "translate_#{class_name}".to_sym , instruction)
|
||||||
|
end
|
||||||
|
|
||||||
# don't replace labels
|
# don't replace labels
|
||||||
def translate_Label code
|
def translate_Label code
|
||||||
nil
|
nil
|
||||||
@ -52,8 +61,9 @@ module Arm
|
|||||||
# The only target for a call is a Block, so we just need to get the address for the code
|
# The only target for a call is a Block, so we just need to get the address for the code
|
||||||
# and branch to it.
|
# and branch to it.
|
||||||
def translate_Branch code
|
def translate_Branch code
|
||||||
ArmMachine.b( code.block )
|
ArmMachine.b( code.label )
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_Syscall code
|
def translate_Syscall code
|
||||||
call_codes = { :putstring => 4 , :exit => 1 }
|
call_codes = { :putstring => 4 , :exit => 1 }
|
||||||
int_code = call_codes[code.name]
|
int_code = call_codes[code.name]
|
||||||
|
@ -33,22 +33,22 @@ module Register
|
|||||||
end
|
end
|
||||||
methods.each do |method|
|
methods.each do |method|
|
||||||
instruction = method.instructions
|
instruction = method.instructions
|
||||||
begin
|
puts "instruction #{instruction.to_ac}" #if instruction.is_a?(Label) and instruction.name == "Method_main"
|
||||||
|
while instruction.next
|
||||||
nekst = instruction.next
|
nekst = instruction.next
|
||||||
t = translate(translator , nekst) # returning nil means no replace
|
puts "translate #{nekst}"
|
||||||
instruction.replace_next(t) if t
|
t = translator.translate(nekst) # returning nil means no replace
|
||||||
|
if t
|
||||||
|
nekst = t.last
|
||||||
|
instruction.replace_next(t)
|
||||||
|
end
|
||||||
instruction = nekst
|
instruction = nekst
|
||||||
end while instruction.next
|
|
||||||
end
|
end
|
||||||
|
puts "instruction #{method.instructions.to_ac}" #if method.instructions.is_a?(Label) and method.instructions.name == "Method_main"
|
||||||
end
|
end
|
||||||
|
label = @init.next
|
||||||
# translator should translate from register instructio set to it's own (arm eg)
|
@init = translator.translate( @init)
|
||||||
# for each instruction we call the translator with translate_XXX
|
@init.append label
|
||||||
# with XXX being the class name.
|
|
||||||
# the result is replaced in the stream
|
|
||||||
def translate translator , instruction
|
|
||||||
class_name = instruction.class.name.split("::").last
|
|
||||||
translator.send( "translate_#{class_name}".to_sym , instruction)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -75,17 +75,6 @@ module Register
|
|||||||
Soml::Compiler.compile( parts )
|
Soml::Compiler.compile( parts )
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def run_blocks_for pass_class
|
|
||||||
parts = pass_class.split("::")
|
|
||||||
pass = Object.const_get(parts[0]).const_get parts[1]
|
|
||||||
raise "no such pass-class as #{pass_class}" unless pass
|
|
||||||
@blocks.each do |block|
|
|
||||||
raise "nil block " unless block
|
|
||||||
pass.new.run(block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Module function to retrieve singleton
|
# Module function to retrieve singleton
|
||||||
|
Loading…
Reference in New Issue
Block a user