really translate risc - cpu/arm
also labels. Actual translation/assembly is much cleaner
This commit is contained in:
parent
eb7713a9f3
commit
279fdcc1e2
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
16
test/risc/test_translator.rb
Normal file
16
test/risc/test_translator.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user