really translate risc - cpu/arm

also labels.
Actual translation/assembly is much cleaner
This commit is contained in:
Torsten Ruger 2018-03-25 19:38:59 +03:00
parent eb7713a9f3
commit 279fdcc1e2
4 changed files with 26 additions and 3 deletions

View File

@ -10,9 +10,8 @@ module Arm
self.send( "translate_#{class_name}".to_sym , instruction)
end
# don't replace labels
def translate_Label( code )
nil
Risc::Label.new( code.source , code.name )
end
# arm indexes are
@ -68,7 +67,7 @@ module Arm
end
def translate_FunctionCall code
ArmMachine.b( code.method.instructions )
ArmMachine.b( code.method.risc_instructions )
end
def translate_FunctionReturn code

View File

@ -42,6 +42,10 @@ module Risc
raise "Abstract called on #{self}"
end
def to_cpu( translator )
translator.translate( self )
end
def assemble_all io , labels = []
self.assemble(io)
self.next.assemble_all(io, labels) if self.next

View File

@ -14,6 +14,10 @@ module Risc
end
attr_reader :name
def to_cpu(translator)
@cpu_label ||= super
end
def to_s
class_source "#{@name} (next: #{self.next.class.name.split("::").last})"
end

View File

@ -0,0 +1,16 @@
require_relative "../helper"
module Risc
class TestTranslator < MiniTest::Test
def setup
@machine = Risc.machine.boot
@translator = Arm::Translator.new
end
def test_translate_label
label = Parfait.object_space.get_main.risc_instructions
assert @translator.translate(label) , label
end
end
end