wip, fixed some label, need more fixing
This commit is contained in:
parent
c55b41afae
commit
074ec34659
@ -90,9 +90,12 @@ module Arm
|
||||
def determine_operands
|
||||
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 = @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
|
||||
# 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)) )
|
||||
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
|
||||
|
@ -32,6 +32,7 @@ module Mom
|
||||
# adding the label to the instruction list (usually an if/while)
|
||||
def to_risc(compiler)
|
||||
int = Parfait.object_space.get_integer
|
||||
puts "ADDING int #{int}"
|
||||
compiler.add_constant(int)
|
||||
@risc_label ||= Risc.label(self,name , int , nil)
|
||||
end
|
||||
|
@ -5,6 +5,7 @@ module Risc
|
||||
def self.collect_space
|
||||
@objects = {}
|
||||
keep Parfait.object_space , 0
|
||||
puts "CONST #{Risc.machine.constants}"
|
||||
Risc.machine.constants.each {|obj| keep(obj,0)}
|
||||
@objects
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Risc
|
||||
# compilation of ruby code. Ruby code works on Objects only
|
||||
#
|
||||
# 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
|
||||
def initialize( source , constant , register)
|
||||
|
@ -55,7 +55,7 @@ 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 compilatio and need to be linked)
|
||||
# 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
|
||||
@ -66,10 +66,10 @@ module Risc
|
||||
#
|
||||
# Position in the order
|
||||
# - initial jump
|
||||
# - all object
|
||||
# - all code
|
||||
# As code length amy change during assembly, this way at least the objects stay
|
||||
# in place and we don't have to deal with chaning loading code
|
||||
# - all objects
|
||||
# - all code (BinaryCode objects)
|
||||
# As code length may change during assembly, this way at least the objects stay
|
||||
# in place and we don't have to deal with changing loading code
|
||||
def position_all
|
||||
raise "Not translated " unless @translated
|
||||
#need the initial jump at 0 and then functions
|
||||
|
@ -43,7 +43,9 @@ module Risc
|
||||
if pos == nil
|
||||
str = "position accessed but not set, "
|
||||
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
|
||||
end
|
||||
pos
|
||||
|
@ -13,6 +13,21 @@ module Arm
|
||||
true
|
||||
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
|
||||
def setup
|
||||
@machine = Arm::ArmMachine
|
||||
|
@ -89,9 +89,10 @@ module Arm
|
||||
assert_code code.next , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22
|
||||
end
|
||||
|
||||
def label( pos = 0x22 + 8)
|
||||
l = Risc.label("some" , "Label")
|
||||
Risc::Position.set(l,pos , @binary)
|
||||
def label( pos = 0x12 + 8)
|
||||
l = Risc::Label.new("some" , "Label" , FakeInt.new(2))
|
||||
Risc::Position.set(l.integer , 0x22 + 8)
|
||||
Risc::Position.set(l , pos , @binary)
|
||||
l
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user