save and restore the right registers

This commit is contained in:
Torsten Ruger 2014-05-22 21:55:17 +03:00
parent 4f0b769e82
commit 86e73bf1ba
5 changed files with 22 additions and 17 deletions

View File

@ -59,7 +59,12 @@ module Arm
if name.is_a? Vm::Word if name.is_a? Vm::Word
name = "r#{name.register}" name = "r#{name.register}"
end end
REGISTERS[name.to_s] if name.is_a? Fixnum
name = "r#{name}"
end
r = REGISTERS[name.to_s]
raise "no reg #{name}" if r == nil
r
end end
def calculate_u8_with_rr(arg) def calculate_u8_with_rr(arg)

View File

@ -58,8 +58,8 @@ module Arm
regs = @first regs = @first
if (regs.is_a?(Array)) if (regs.is_a?(Array))
@operand = 0 @operand = 0
regs.each do |reg | regs.each_with_index do |reg , index|
next unless reg raise "nil register in push, index #{index}" if reg == nil
@operand |= (1 << reg_code(reg)) @operand |= (1 << reg_code(reg))
end end
else else

View File

@ -11,25 +11,14 @@ module Ast
function = context.program.get_or_create_function(name) function = context.program.get_or_create_function(name)
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
call = Vm::CallSite.new( name , params , function) call = Vm::CallSite.new( name , params , function)
save_locals context , into current_function = context.function
current_function.save_locals(context , into) if current_function
call.load_args into call.load_args into
call.do_call into call.do_call into
restore_locals context , into current_function.restore_locals(context , into) if current_function
function.return_type function.return_type
end end
def save_locals context , into
into.instance_eval do
push [:r0,:r1 , :r2 , :r3]
end
end
def restore_locals context , into
into.instance_eval do
pop [:r0,:r1, :r2 , :r3]
end
end
def inspect def inspect
self.class.name + ".new(" + name.inspect + ", ["+ self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") +"] )" args.collect{|m| m.inspect }.join( ",") +"] )"

View File

@ -67,6 +67,16 @@ module Vm
l l
end end
def save_locals context , into
save = args.collect{|a| a.register } + @locals.collect{|l| l.register}
into.push save
end
def restore_locals context , into
restore = args.collect{|a| a.register } + @locals.collect{|l| l.register}
into.pop restore
end
def new_block name def new_block name
block = Block.new(name , self) block = Block.new(name , self)
@blocks << block @blocks << block

View File

@ -59,6 +59,7 @@ module Vm
end end
def initialize reg def initialize reg
@register = reg @register = reg
raise inspect if reg == nil
end end
def length def length
4 4