loading label must translate the labels too

(psst: like arm translator already did. duh)
This commit is contained in:
Torsten Ruger 2018-05-24 19:20:06 +03:00
parent dae8e88b7a
commit 183d4152d5
7 changed files with 37 additions and 31 deletions

View File

@ -5,7 +5,7 @@ module Risc
# second argument is the register the constant is loaded into
class LoadConstant < Instruction
def initialize source , constant , register
def initialize( source , constant , register)
super(source)
@register = register
@constant = constant
@ -33,6 +33,6 @@ module Risc
end
end
def self.load_constant( source , constant , register )
LoadConstant.new source , constant , register
LoadConstant.new( source , constant , register )
end
end

View File

@ -216,7 +216,7 @@ module Risc
meth = @instruction.method
at = Position.get(meth.binary).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
false
end
@ -224,9 +224,8 @@ module Risc
def execute_FunctionReturn
link = get_register( @instruction.register )
log.debug "Return to #{link}"
@instruction = link
# we jump back to the call instruction. so it is as if the call never happened and we continue
true
set_pc Position.get(link).at
false
end
def execute_Syscall

View File

@ -34,10 +34,14 @@ module Risc
case code
when Branch
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
ret = code.dup
ret.nil_next
end
ret.nil_next
ret
end
end

View File

@ -34,14 +34,13 @@ module Risc
platform = platform.to_s.capitalize
@platform = Platform.for(platform)
@translated = true
methods = Parfait.object_space.get_all_methods
translate_methods( methods , @platform.translator )
translate_methods( @platform.translator )
@cpu_init = risc_init.to_cpu(@platform.translator)
end
# go through all methods and translate them to cpu, given the translator
def translate_methods(methods , translator)
methods.each do |method|
def translate_methods(translator)
Parfait.object_space.get_all_methods.each do |method|
log.debug "Translate method #{method.name}"
method.translate_cpu(translator)
end
@ -90,7 +89,6 @@ module Risc
before = at
Position.set(objekt,at)
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)}"
end
at

View File

@ -109,7 +109,7 @@ module Risc
end
# 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
def builder( auto_add , source)
Builder.new(self , auto_add , source)

View File

@ -19,7 +19,7 @@ module Risc
@instruction_events << was
end
def length
88
84
end
def test_state_change
@interpreter.register_event :state_changed , self
@ -39,24 +39,23 @@ module Risc
def test_chain
#show_ticks # get output of what is
check_chain [Branch, Label, LoadConstant, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, LoadConstant, SlotToReg, 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,
check_chain [Branch, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
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 12 , get_return.value
end

View File

@ -25,6 +25,12 @@ module Risc
@translator = IdentityTranslator.new
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
label = Parfait.object_space.get_main.risc_instructions
assert_equal "Space_Type.main" ,label.to_cpu(@translator).name , label