return the linker from mom_compiler
linker holds assemblers assemblers come from method compilation and so the layers come into focus
This commit is contained in:
parent
5f2a256608
commit
22408b86c6
@ -3,7 +3,7 @@ module Mom
|
|||||||
attr_reader :clazz , :method_compilers
|
attr_reader :clazz , :method_compilers
|
||||||
|
|
||||||
def initialize(compilers = [])
|
def initialize(compilers = [])
|
||||||
@method_compilers = Builtin.boot_functions + compilers
|
@method_compilers = Risc::Builtin.boot_functions + compilers
|
||||||
end
|
end
|
||||||
|
|
||||||
# Translate code to whatever cpu is specified.
|
# Translate code to whatever cpu is specified.
|
||||||
@ -14,7 +14,8 @@ module Mom
|
|||||||
def translate( platform_sym )
|
def translate( platform_sym )
|
||||||
platform_sym = platform_sym.to_s.capitalize
|
platform_sym = platform_sym.to_s.capitalize
|
||||||
platform = Risc::Platform.for(platform_sym)
|
platform = Risc::Platform.for(platform_sym)
|
||||||
translate_methods( platform.translator )
|
assemblers = translate_methods( platform.translator )
|
||||||
|
Risc::Linker.new(platform , assemblers)
|
||||||
#@cpu_init = risc_init.to_cpu(@platform.translator)
|
#@cpu_init = risc_init.to_cpu(@platform.translator)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,19 +13,20 @@ module Risc
|
|||||||
include Util::Logging
|
include Util::Logging
|
||||||
log_level :info
|
log_level :info
|
||||||
|
|
||||||
def initialize(platform)
|
def initialize(platform , assemblers)
|
||||||
if(platform.is_a?(Symbol))
|
if(platform.is_a?(Symbol))
|
||||||
platform = platform.to_s.capitalize
|
platform = platform.to_s.capitalize
|
||||||
platform = Risc::Platform.for(platform)
|
platform = Risc::Platform.for(platform)
|
||||||
end
|
end
|
||||||
raise "Platform must be platform, not #{platform.class}" unless platform.is_a?(Platform)
|
raise "Platform must be platform, not #{platform.class}" unless platform.is_a?(Platform)
|
||||||
@platform = platform
|
@platform = platform
|
||||||
|
@assemblers = assemblers
|
||||||
@risc_init = nil
|
@risc_init = nil
|
||||||
@constants = []
|
@constants = []
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :constants , :cpu_init
|
attr_reader :constants , :cpu_init
|
||||||
attr_reader :platform
|
attr_reader :platform , :assemblers
|
||||||
|
|
||||||
# machine keeps a list of all objects and their positions.
|
# machine keeps a list of all objects and their positions.
|
||||||
# this is lazily created with a collector
|
# this is lazily created with a collector
|
||||||
@ -38,12 +39,6 @@ module Risc
|
|||||||
def risc_init
|
def risc_init
|
||||||
@risc_init ||= Branch.new( "__initial_branch__" , Parfait.object_space.get_init.risc_instructions )
|
@risc_init ||= Branch.new( "__initial_branch__" , Parfait.object_space.get_init.risc_instructions )
|
||||||
end
|
end
|
||||||
# add a constant (which get created during compilation and need to be linked)
|
|
||||||
def add_constant(const)
|
|
||||||
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
|
||||||
@constants << const
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# To create binaries, objects (and labels) need to have a position
|
# To create binaries, objects (and labels) need to have a position
|
||||||
# (so objects can be loaded and branches know where to jump)
|
# (so objects can be loaded and branches know where to jump)
|
||||||
|
@ -61,7 +61,9 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add a constant (which get created during compilation and need to be linked)
|
||||||
def add_constant(const)
|
def add_constant(const)
|
||||||
|
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
||||||
@constants << const
|
@constants << const
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,9 +27,7 @@ module RubyX
|
|||||||
def ruby_to_binary(platform = :arm)
|
def ruby_to_binary(platform = :arm)
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
assemblers = ruby_to_mom
|
linker = ruby_to_risc(platform)
|
||||||
puts "Assemblers #{assemblers}"
|
|
||||||
linker = Risc::Linker.new(platform)
|
|
||||||
linker.position_all
|
linker.position_all
|
||||||
linker.create_binary
|
linker.create_binary
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@ module Mom
|
|||||||
assert_equal MomCompiler , @comp.class
|
assert_equal MomCompiler , @comp.class
|
||||||
end
|
end
|
||||||
def test_compilers
|
def test_compilers
|
||||||
assert_equal 1 , @comp.method_compilers.length
|
assert_equal 24 , @comp.method_compilers.length
|
||||||
end
|
end
|
||||||
def test_has_translate
|
def test_has_translate
|
||||||
assert @comp.translate(:interpreter)
|
assert @comp.translate(:interpreter)
|
||||||
@ -29,16 +29,19 @@ module Mom
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_translate_class
|
def test_translate_class
|
||||||
assert_equal Array , @trans.class
|
assert_equal Risc::Linker , @trans.class
|
||||||
|
end
|
||||||
|
def test_translate_platform
|
||||||
|
assert_kind_of Risc::Platform , @trans.platform
|
||||||
end
|
end
|
||||||
def test_translate_assemblers
|
def test_translate_assemblers
|
||||||
assert_equal Risc::Assembler , @trans.first.class
|
assert_equal Risc::Assembler , @trans.assemblers.first.class
|
||||||
end
|
end
|
||||||
def test_assembler_code
|
def test_assembler_code
|
||||||
assert_equal Risc::Label , @trans.first.instructions.class
|
assert_equal Risc::Label , @trans.assemblers.first.instructions.class
|
||||||
end
|
end
|
||||||
def test_assembler_assembled
|
def test_assembler_assembled
|
||||||
assert_equal Risc::LoadConstant , @trans.first.instructions.next.class
|
assert_equal Risc::SlotToReg , @trans.assemblers.first.instructions.next.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -6,27 +6,23 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
@machine = Linker.new(:arm)
|
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||||
end
|
end
|
||||||
def test_objects
|
def test_objects
|
||||||
objects = @machine.object_positions
|
objects = @linker.object_positions
|
||||||
assert_equal Hash , objects.class
|
assert_equal Hash , objects.class
|
||||||
assert 350 < objects.length
|
assert 350 < objects.length
|
||||||
end
|
end
|
||||||
def test_constant_fail
|
def test_constant_fail
|
||||||
assert_raises {@machine.add_constant( 1 )}
|
assert_raises {@machine.add_constant( 1 )}
|
||||||
end
|
end
|
||||||
def test_constant
|
|
||||||
assert @machine.add_constant( Parfait::Integer.new(5) )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class TestMachinePos < MiniTest::Test
|
class TestMachinePos < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
@linker = Linker.new(:arm)
|
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||||
@linker.translate
|
@linker.position_all
|
||||||
@machine.position_all
|
|
||||||
end
|
end
|
||||||
def test_positions_set
|
def test_positions_set
|
||||||
@machine.object_positions.each do |obj , position|
|
@machine.object_positions.each do |obj , position|
|
||||||
|
@ -5,11 +5,16 @@ module RubyX
|
|||||||
include ScopeHelper
|
include ScopeHelper
|
||||||
include RubyXHelper
|
include RubyXHelper
|
||||||
|
|
||||||
def test_to_risc
|
def setup
|
||||||
|
super
|
||||||
code = "class Space ; def main(arg);return arg;end; end"
|
code = "class Space ; def main(arg);return arg;end; end"
|
||||||
risc = ruby_to_risc(code, :interpreter)
|
@linker = ruby_to_risc(code, :interpreter)
|
||||||
assert_equal Array , risc.class
|
end
|
||||||
|
def test_to_risc
|
||||||
|
assert_equal Risc::Linker , @linker.class
|
||||||
|
end
|
||||||
|
def test_method
|
||||||
|
assert_equal :main , @linker.assemblers.last.method.name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,5 +16,10 @@ module Vool
|
|||||||
def test_has_compilers
|
def test_has_compilers
|
||||||
assert_equal Risc::MethodCompiler , @ret.method_compilers.first.class
|
assert_equal Risc::MethodCompiler , @ret.method_compilers.first.class
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_constant
|
||||||
|
assert @ret.method_compilers.first.add_constant( Parfait::Integer.new(5) )
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user