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)
|
self.send( "translate_#{class_name}".to_sym , instruction)
|
||||||
end
|
end
|
||||||
|
|
||||||
# don't replace labels
|
|
||||||
def translate_Label( code )
|
def translate_Label( code )
|
||||||
nil
|
Risc::Label.new( code.source , code.name )
|
||||||
end
|
end
|
||||||
|
|
||||||
# arm indexes are
|
# arm indexes are
|
||||||
@ -68,7 +67,7 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def translate_FunctionCall code
|
def translate_FunctionCall code
|
||||||
ArmMachine.b( code.method.instructions )
|
ArmMachine.b( code.method.risc_instructions )
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_FunctionReturn code
|
def translate_FunctionReturn code
|
||||||
|
@ -42,6 +42,10 @@ module Risc
|
|||||||
raise "Abstract called on #{self}"
|
raise "Abstract called on #{self}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_cpu( translator )
|
||||||
|
translator.translate( self )
|
||||||
|
end
|
||||||
|
|
||||||
def assemble_all io , labels = []
|
def assemble_all io , labels = []
|
||||||
self.assemble(io)
|
self.assemble(io)
|
||||||
self.next.assemble_all(io, labels) if self.next
|
self.next.assemble_all(io, labels) if self.next
|
||||||
|
@ -14,6 +14,10 @@ module Risc
|
|||||||
end
|
end
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
|
def to_cpu(translator)
|
||||||
|
@cpu_label ||= super
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
class_source "#{@name} (next: #{self.next.class.name.split("::").last})"
|
class_source "#{@name} (next: #{self.next.class.name.split("::").last})"
|
||||||
end
|
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