wip, fixed some label, need more fixing

This commit is contained in:
Torsten Ruger 2018-05-30 10:29:38 +03:00
parent c55b41afae
commit 074ec34659
8 changed files with 34 additions and 11 deletions

View File

@ -90,9 +90,12 @@ module Arm
def determine_operands def determine_operands
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
puts "Label #{@left.integer.inspect}" 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)
right = Risc::Position.get(@left) - Risc::Position.get(self) - 8 right = Risc::Position.get(left) - Risc::Position.get(self) - 8
if( (right < 0) && ((opcode == :add) || (opcode == :sub)) ) if( (right < 0) && ((opcode == :add) || (opcode == :sub)) )
right *= -1 # this works as we never issue sub only add right *= -1 # this works as we never issue sub only add
set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode

View File

@ -32,6 +32,7 @@ module Mom
# 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 int = Parfait.object_space.get_integer
puts "ADDING int #{int}"
compiler.add_constant(int) compiler.add_constant(int)
@risc_label ||= Risc.label(self,name , int , nil) @risc_label ||= Risc.label(self,name , int , nil)
end end

View File

@ -5,6 +5,7 @@ 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

View File

@ -5,7 +5,7 @@ module Risc
# compilation of ruby code. Ruby code works on Objects only # compilation of ruby code. Ruby code works on Objects only
# #
# But for Builtin methods, methods that are created programatically and form the runtime, # But for Builtin methods, methods that are created programatically and form the runtime,
# it can be handy to load an integer directly withou the object overhead. # it can be handy to load an integer directly without the object overhead.
# #
class LoadData < Instruction class LoadData < Instruction
def initialize( source , constant , register) def initialize( source , constant , register)

View File

@ -55,7 +55,7 @@ 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 compilatio and need to be linked) # 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) raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
@constants << const @constants << const
@ -66,10 +66,10 @@ module Risc
# #
# Position in the order # Position in the order
# - initial jump # - initial jump
# - all object # - all objects
# - all code # - all code (BinaryCode objects)
# As code length amy change during assembly, this way at least the objects stay # As code length may change during assembly, this way at least the objects stay
# in place and we don't have to deal with chaning loading code # in place and we don't have to deal with changing loading code
def position_all def position_all
raise "Not translated " unless @translated raise "Not translated " unless @translated
#need the initial jump at 0 and then functions #need the initial jump at 0 and then functions

View File

@ -43,7 +43,9 @@ module Risc
if pos == nil if pos == nil
str = "position accessed but not set, " str = "position accessed but not set, "
str += "0x#{object.object_id.to_s(16)}\n" str += "0x#{object.object_id.to_s(16)}\n"
str += "for #{object.class} byte_length #{object.byte_length if object.respond_to?(:byte_length)} for #{object.to_s[0...130]}" str += "for #{object.class} "
str += "byte_length #{object.byte_length}" if object.respond_to?(:byte_length)
str += " for #{object.to_s[0...130]}"
raise str raise str
end end
pos pos

View File

@ -13,6 +13,21 @@ 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

View File

@ -89,9 +89,10 @@ module Arm
assert_code code.next , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22 assert_code code.next , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22
end end
def label( pos = 0x22 + 8) def label( pos = 0x12 + 8)
l = Risc.label("some" , "Label") l = Risc::Label.new("some" , "Label" , FakeInt.new(2))
Risc::Position.set(l,pos , @binary) Risc::Position.set(l.integer , 0x22 + 8)
Risc::Position.set(l , pos , @binary)
l l
end end