loading label must translate the labels too
(psst: like arm translator already did. duh)
This commit is contained in:
parent
dae8e88b7a
commit
183d4152d5
@ -5,7 +5,7 @@ module Risc
|
|||||||
# second argument is the register the constant is loaded into
|
# second argument is the register the constant is loaded into
|
||||||
|
|
||||||
class LoadConstant < Instruction
|
class LoadConstant < Instruction
|
||||||
def initialize source , constant , register
|
def initialize( source , constant , register)
|
||||||
super(source)
|
super(source)
|
||||||
@register = register
|
@register = register
|
||||||
@constant = constant
|
@constant = constant
|
||||||
@ -33,6 +33,6 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def self.load_constant( source , constant , register )
|
def self.load_constant( source , constant , register )
|
||||||
LoadConstant.new source , constant , register
|
LoadConstant.new( source , constant , register )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -216,7 +216,7 @@ module Risc
|
|||||||
meth = @instruction.method
|
meth = @instruction.method
|
||||||
at = Position.get(meth.binary).at
|
at = Position.get(meth.binary).at
|
||||||
log.debug "Call to #{meth.name} at:#{at}"
|
log.debug "Call to #{meth.name} at:#{at}"
|
||||||
set_pc(at + BinaryCode.offset)
|
set_pc(at + Parfait::BinaryCode.offset)
|
||||||
#set_instruction @instruction.method.risc_instructions
|
#set_instruction @instruction.method.risc_instructions
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -224,9 +224,8 @@ module Risc
|
|||||||
def execute_FunctionReturn
|
def execute_FunctionReturn
|
||||||
link = get_register( @instruction.register )
|
link = get_register( @instruction.register )
|
||||||
log.debug "Return to #{link}"
|
log.debug "Return to #{link}"
|
||||||
@instruction = link
|
set_pc Position.get(link).at
|
||||||
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
false
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_Syscall
|
def execute_Syscall
|
||||||
|
@ -34,10 +34,14 @@ module Risc
|
|||||||
case code
|
case code
|
||||||
when Branch
|
when Branch
|
||||||
ret = code.class.new(code.source , code.label.to_cpu(self))
|
ret = code.class.new(code.source , code.label.to_cpu(self))
|
||||||
|
when LoadConstant
|
||||||
|
const = code.constant
|
||||||
|
const = const.to_cpu(self) if const.is_a?(Label)
|
||||||
|
ret = LoadConstant.new(code.source , const , code.register)
|
||||||
else
|
else
|
||||||
ret = code.dup
|
ret = code.dup
|
||||||
ret.nil_next
|
|
||||||
end
|
end
|
||||||
|
ret.nil_next
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,14 +34,13 @@ module Risc
|
|||||||
platform = platform.to_s.capitalize
|
platform = platform.to_s.capitalize
|
||||||
@platform = Platform.for(platform)
|
@platform = Platform.for(platform)
|
||||||
@translated = true
|
@translated = true
|
||||||
methods = Parfait.object_space.get_all_methods
|
translate_methods( @platform.translator )
|
||||||
translate_methods( methods , @platform.translator )
|
|
||||||
@cpu_init = risc_init.to_cpu(@platform.translator)
|
@cpu_init = risc_init.to_cpu(@platform.translator)
|
||||||
end
|
end
|
||||||
|
|
||||||
# go through all methods and translate them to cpu, given the translator
|
# go through all methods and translate them to cpu, given the translator
|
||||||
def translate_methods(methods , translator)
|
def translate_methods(translator)
|
||||||
methods.each do |method|
|
Parfait.object_space.get_all_methods.each do |method|
|
||||||
log.debug "Translate method #{method.name}"
|
log.debug "Translate method #{method.name}"
|
||||||
method.translate_cpu(translator)
|
method.translate_cpu(translator)
|
||||||
end
|
end
|
||||||
@ -90,7 +89,6 @@ module Risc
|
|||||||
before = at
|
before = at
|
||||||
Position.set(objekt,at)
|
Position.set(objekt,at)
|
||||||
at += objekt.padded_length
|
at += objekt.padded_length
|
||||||
log.debug "PADDED #{objekt.padded_length}"
|
|
||||||
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||||
end
|
end
|
||||||
at
|
at
|
||||||
|
@ -109,7 +109,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
# return a new builder that uses this compiler
|
# return a new builder that uses this compiler
|
||||||
# must specify weather to add code automatically to compiler
|
# must specify whether to add code automatically to compiler
|
||||||
# second arg is the source for which to build, either method or mom::instruction
|
# second arg is the source for which to build, either method or mom::instruction
|
||||||
def builder( auto_add , source)
|
def builder( auto_add , source)
|
||||||
Builder.new(self , auto_add , source)
|
Builder.new(self , auto_add , source)
|
||||||
|
@ -19,7 +19,7 @@ module Risc
|
|||||||
@instruction_events << was
|
@instruction_events << was
|
||||||
end
|
end
|
||||||
def length
|
def length
|
||||||
88
|
84
|
||||||
end
|
end
|
||||||
def test_state_change
|
def test_state_change
|
||||||
@interpreter.register_event :state_changed , self
|
@interpreter.register_event :state_changed , self
|
||||||
@ -39,24 +39,23 @@ module Risc
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
check_chain [Branch, Label, LoadConstant, SlotToReg, SlotToReg,
|
check_chain [Branch, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
||||||
RegToSlot, LoadConstant, LoadConstant, SlotToReg, RegToSlot,
|
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
|
||||||
SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg,
|
|
||||||
RegToSlot, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
|
|
||||||
FunctionCall, Label, LoadConstant, LoadConstant, SlotToReg,
|
|
||||||
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
|
||||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
|
||||||
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
|
||||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
|
|
||||||
Label, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
|
||||||
SlotToReg, OperatorInstruction, LoadConstant, SlotToReg, SlotToReg,
|
|
||||||
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
|
||||||
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
|
|
||||||
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
|
||||||
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
FunctionReturn, Transfer, Syscall, NilClass]
|
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||||
|
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
|
||||||
|
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
||||||
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
|
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
||||||
|
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||||
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||||
|
SlotToReg, FunctionCall, SlotToReg, SlotToReg, SlotToReg,
|
||||||
|
SlotToReg, SlotToReg, OperatorInstruction, LoadConstant, SlotToReg,
|
||||||
|
SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
|
||||||
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn,
|
||||||
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||||
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
||||||
|
SlotToReg, FunctionReturn, Transfer, Syscall, NilClass]
|
||||||
assert_equal Parfait::Integer , get_return.class
|
assert_equal Parfait::Integer , get_return.class
|
||||||
assert_equal 12 , get_return.value
|
assert_equal 12 , get_return.value
|
||||||
end
|
end
|
||||||
|
@ -25,6 +25,12 @@ module Risc
|
|||||||
@translator = IdentityTranslator.new
|
@translator = IdentityTranslator.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_load_translates_label
|
||||||
|
label = Label.new("test" , "test")
|
||||||
|
load = Risc.load_constant("source" , label , :r1)
|
||||||
|
translated = @translator.translate(load)
|
||||||
|
assert label != translated.constant
|
||||||
|
end
|
||||||
def test_translate_first_label
|
def test_translate_first_label
|
||||||
label = Parfait.object_space.get_main.risc_instructions
|
label = Parfait.object_space.get_main.risc_instructions
|
||||||
assert_equal "Space_Type.main" ,label.to_cpu(@translator).name , label
|
assert_equal "Space_Type.main" ,label.to_cpu(@translator).name , label
|
||||||
|
Loading…
Reference in New Issue
Block a user