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
|
||||
|
||||
def initialize(compilers = [])
|
||||
@method_compilers = Builtin.boot_functions + compilers
|
||||
@method_compilers = Risc::Builtin.boot_functions + compilers
|
||||
end
|
||||
|
||||
# Translate code to whatever cpu is specified.
|
||||
@ -14,7 +14,8 @@ module Mom
|
||||
def translate( platform_sym )
|
||||
platform_sym = platform_sym.to_s.capitalize
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -13,19 +13,20 @@ module Risc
|
||||
include Util::Logging
|
||||
log_level :info
|
||||
|
||||
def initialize(platform)
|
||||
def initialize(platform , assemblers)
|
||||
if(platform.is_a?(Symbol))
|
||||
platform = platform.to_s.capitalize
|
||||
platform = Risc::Platform.for(platform)
|
||||
end
|
||||
raise "Platform must be platform, not #{platform.class}" unless platform.is_a?(Platform)
|
||||
@platform = platform
|
||||
@assemblers = assemblers
|
||||
@risc_init = nil
|
||||
@constants = []
|
||||
end
|
||||
|
||||
attr_reader :constants , :cpu_init
|
||||
attr_reader :platform
|
||||
attr_reader :platform , :assemblers
|
||||
|
||||
# machine keeps a list of all objects and their positions.
|
||||
# this is lazily created with a collector
|
||||
@ -38,12 +39,6 @@ module Risc
|
||||
def risc_init
|
||||
@risc_init ||= Branch.new( "__initial_branch__" , Parfait.object_space.get_init.risc_instructions )
|
||||
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
|
||||
# (so objects can be loaded and branches know where to jump)
|
||||
|
@ -61,7 +61,9 @@ module Risc
|
||||
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
|
||||
|
||||
|
@ -27,9 +27,7 @@ module RubyX
|
||||
def ruby_to_binary(platform = :arm)
|
||||
Parfait.boot!
|
||||
Risc.boot!
|
||||
assemblers = ruby_to_mom
|
||||
puts "Assemblers #{assemblers}"
|
||||
linker = Risc::Linker.new(platform)
|
||||
linker = ruby_to_risc(platform)
|
||||
linker.position_all
|
||||
linker.create_binary
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ module Mom
|
||||
assert_equal MomCompiler , @comp.class
|
||||
end
|
||||
def test_compilers
|
||||
assert_equal 1 , @comp.method_compilers.length
|
||||
assert_equal 24 , @comp.method_compilers.length
|
||||
end
|
||||
def test_has_translate
|
||||
assert @comp.translate(:interpreter)
|
||||
@ -29,16 +29,19 @@ module Mom
|
||||
end
|
||||
|
||||
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
|
||||
def test_translate_assemblers
|
||||
assert_equal Risc::Assembler , @trans.first.class
|
||||
assert_equal Risc::Assembler , @trans.assemblers.first.class
|
||||
end
|
||||
def test_assembler_code
|
||||
assert_equal Risc::Label , @trans.first.instructions.class
|
||||
assert_equal Risc::Label , @trans.assemblers.first.instructions.class
|
||||
end
|
||||
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
|
@ -6,27 +6,23 @@ module Risc
|
||||
def setup
|
||||
Parfait.boot!
|
||||
Risc.boot!
|
||||
@machine = Linker.new(:arm)
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
end
|
||||
def test_objects
|
||||
objects = @machine.object_positions
|
||||
objects = @linker.object_positions
|
||||
assert_equal Hash , objects.class
|
||||
assert 350 < objects.length
|
||||
end
|
||||
def test_constant_fail
|
||||
assert_raises {@machine.add_constant( 1 )}
|
||||
end
|
||||
def test_constant
|
||||
assert @machine.add_constant( Parfait::Integer.new(5) )
|
||||
end
|
||||
end
|
||||
class TestMachinePos < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!
|
||||
Risc.boot!
|
||||
@linker = Linker.new(:arm)
|
||||
@linker.translate
|
||||
@machine.position_all
|
||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
||||
@linker.position_all
|
||||
end
|
||||
def test_positions_set
|
||||
@machine.object_positions.each do |obj , position|
|
||||
|
@ -5,11 +5,16 @@ module RubyX
|
||||
include ScopeHelper
|
||||
include RubyXHelper
|
||||
|
||||
def test_to_risc
|
||||
def setup
|
||||
super
|
||||
code = "class Space ; def main(arg);return arg;end; end"
|
||||
risc = ruby_to_risc(code, :interpreter)
|
||||
assert_equal Array , risc.class
|
||||
@linker = ruby_to_risc(code, :interpreter)
|
||||
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
|
||||
|
@ -16,5 +16,10 @@ module Vool
|
||||
def test_has_compilers
|
||||
assert_equal Risc::MethodCompiler , @ret.method_compilers.first.class
|
||||
end
|
||||
|
||||
def test_constant
|
||||
assert @ret.method_compilers.first.add_constant( Parfait::Integer.new(5) )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user