get the label int to work consistently
still need to use it in the return
This commit is contained in:
parent
074ec34659
commit
0dc89c772a
@ -91,7 +91,6 @@ module Arm
|
|||||||
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or
|
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or
|
||||||
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
|
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
|
||||||
left = @left
|
left = @left
|
||||||
puts "Label #{@left.integer.inspect}" if left.is_a?(Risc::Label)
|
|
||||||
left = @left.integer if left.is_a?(Risc::Label)
|
left = @left.integer if left.is_a?(Risc::Label)
|
||||||
# do pc relative addressing with the difference to the instuction
|
# do pc relative addressing with the difference to the instuction
|
||||||
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
|
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
|
||||||
|
@ -31,10 +31,7 @@ module Mom
|
|||||||
# Off course some specific place still has to be responsible for actually
|
# Off course some specific place still has to be responsible for actually
|
||||||
# adding the label to the instruction list (usually an if/while)
|
# adding the label to the instruction list (usually an if/while)
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
int = Parfait.object_space.get_integer
|
@risc_label ||= Risc.label(self,name)
|
||||||
puts "ADDING int #{int}"
|
|
||||||
compiler.add_constant(int)
|
|
||||||
@risc_label ||= Risc.label(self,name , int , nil)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,6 @@ module Risc
|
|||||||
def self.collect_space
|
def self.collect_space
|
||||||
@objects = {}
|
@objects = {}
|
||||||
keep Parfait.object_space , 0
|
keep Parfait.object_space , 0
|
||||||
puts "CONST #{Risc.machine.constants}"
|
|
||||||
Risc.machine.constants.each {|obj| keep(obj,0)}
|
Risc.machine.constants.each {|obj| keep(obj,0)}
|
||||||
@objects
|
@objects
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,25 @@
|
|||||||
module Risc
|
module Risc
|
||||||
|
|
||||||
# A label is a placeholder for it's next Instruction
|
# A label is a placeholder for it's next Instruction
|
||||||
# It's function is not to turn into code, but to be a valid brnch target
|
# It's function is not to turn into code, but to be a valid branch target
|
||||||
|
# Labels have the same position as their next instruction (See positioning code)
|
||||||
#
|
#
|
||||||
# So branches and Labels are pairs, fan out, fan in
|
# So branches and Labels are pairs, fan out, fan in
|
||||||
#
|
#
|
||||||
#
|
# For a return, the address (position) of the label has to be loaded.
|
||||||
|
# So a Label carries the Integer constant that holds the address (it's own
|
||||||
|
# position, again see positioning code).
|
||||||
|
# But currently the label is used in the Risc abstraction layer, and in the
|
||||||
|
# arm/interpreter layer. The integer is only used in the lower layer, but needs
|
||||||
|
# to be created (and positioned)
|
||||||
|
|
||||||
class Label < Instruction
|
class Label < Instruction
|
||||||
|
# See class description. also factory method Risc.label below
|
||||||
def initialize( source , name , int , nekst = nil)
|
def initialize( source , name , int , nekst = nil)
|
||||||
super(source , nekst)
|
super(source , nekst)
|
||||||
@name = name
|
@name = name
|
||||||
@integer = int
|
@integer = int
|
||||||
raise "Not int #{int}" if int and !int.is_a?(Parfait::Integer)
|
raise "Not int #{int}" unless int.is_a?(Parfait::Integer)
|
||||||
end
|
end
|
||||||
attr_reader :name , :integer
|
attr_reader :name , :integer
|
||||||
|
|
||||||
@ -53,8 +60,15 @@ module Risc
|
|||||||
alias :padded_length :byte_length
|
alias :padded_length :byte_length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Labels carry what is esentially an integer constant
|
||||||
|
# The int holds the labels position for use at runtime (return address)
|
||||||
|
# An integer is plucked from object_space abd added to the machine constant pool
|
||||||
|
# if none was given
|
||||||
def self.label( source , name , position = nil , nekst = nil)
|
def self.label( source , name , position = nil , nekst = nil)
|
||||||
position ||= Parfait.object_space.get_integer
|
unless position
|
||||||
|
position = Parfait.object_space.get_integer
|
||||||
|
Risc.machine.add_constant(position)
|
||||||
|
end
|
||||||
Label.new( source , name , position, nekst )
|
Label.new( source , name , position, nekst )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,21 +13,6 @@ module Arm
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FakeInt
|
|
||||||
attr_reader :value
|
|
||||||
def initialize(val)
|
|
||||||
set_value(val)
|
|
||||||
end
|
|
||||||
def is_a?(clazz)
|
|
||||||
clazz == Parfait::Integer
|
|
||||||
end
|
|
||||||
def byte_length
|
|
||||||
4
|
|
||||||
end
|
|
||||||
def set_value(val)
|
|
||||||
@value = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
module ArmHelper
|
module ArmHelper
|
||||||
def setup
|
def setup
|
||||||
@machine = Arm::ArmMachine
|
@machine = Arm::ArmMachine
|
||||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
|||||||
module Risc
|
module Risc
|
||||||
class TestInstructions < MiniTest::Test
|
class TestInstructions < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
@label = Label.new("test" , "test",nil)
|
@label = Label.new("test" , "test",FakeInt.new(5))
|
||||||
@branch = Branch.new("test" , @label)
|
@branch = Branch.new("test" , @label)
|
||||||
@instruction = Instruction.new("test")
|
@instruction = Instruction.new("test")
|
||||||
end
|
end
|
||||||
@ -19,7 +19,7 @@ module Risc
|
|||||||
assert @label.to_s.include?("Label")
|
assert @label.to_s.include?("Label")
|
||||||
end
|
end
|
||||||
def test_label_tos2
|
def test_label_tos2
|
||||||
assert Label.new(nil,nil,nil).to_s.include?("Label")
|
assert Label.new("nil",nil,FakeInt.new(2)).to_s.include?("Label")
|
||||||
end
|
end
|
||||||
def test_last_empty
|
def test_last_empty
|
||||||
assert_equal @instruction, @instruction.last
|
assert_equal @instruction, @instruction.last
|
||||||
@ -55,7 +55,7 @@ module Risc
|
|||||||
assert_nil @instruction.next(2)
|
assert_nil @instruction.next(2)
|
||||||
end
|
end
|
||||||
def test_label_is_method
|
def test_label_is_method
|
||||||
label = Label.new("test" , "Object.test" , nil)
|
label = Label.new("test" , "Object.test" , FakeInt.new(5))
|
||||||
assert label.is_method
|
assert label.is_method
|
||||||
end
|
end
|
||||||
def test_label_is_not_method
|
def test_label_is_not_method
|
||||||
|
@ -52,7 +52,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_pc1
|
def test_pc1
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 17952 , @interpreter.pc
|
assert_equal 18392 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick2
|
def test_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@ -66,7 +66,7 @@ module Risc
|
|||||||
def test_pc2
|
def test_pc2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 17956 , @interpreter.pc
|
assert_equal 18396 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick_14_jump
|
def test_tick_14_jump
|
||||||
14.times {@interpreter.tick}
|
14.times {@interpreter.tick}
|
||||||
|
@ -29,10 +29,10 @@ module Risc
|
|||||||
assert_equal 0 , Position.get(@machine.cpu_init).at
|
assert_equal 0 , Position.get(@machine.cpu_init).at
|
||||||
end
|
end
|
||||||
def test_cpu_at
|
def test_cpu_at
|
||||||
assert_equal "0x555c" , Position.get(@machine.cpu_init.first).to_s
|
assert_equal "0x5714" , Position.get(@machine.cpu_init.first).to_s
|
||||||
end
|
end
|
||||||
def test_cpu_bin
|
def test_cpu_bin
|
||||||
assert_equal "0x5554" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
|
assert_equal "0x570c" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
|
||||||
end
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class
|
assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class
|
||||||
|
15
test/support/fake_int.rb
Normal file
15
test/support/fake_int.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
class FakeInt
|
||||||
|
attr_reader :value
|
||||||
|
def initialize(val)
|
||||||
|
set_value(val)
|
||||||
|
end
|
||||||
|
def is_a?(clazz)
|
||||||
|
clazz == Parfait::Integer
|
||||||
|
end
|
||||||
|
def byte_length
|
||||||
|
4
|
||||||
|
end
|
||||||
|
def set_value(val)
|
||||||
|
@value = val
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user