diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 39f62f82..fc170c26 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -36,9 +36,9 @@ module Arm end def string_load block , str_lit , reg - block << add( "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit + block << add( "r#{reg}".to_sym , str_lit , nil ) #right is pc, implicit #second arg is a hack to get the stringlength without coding - block << mov( "r#{reg+1}".to_sym , right: str_lit.length ) + block << mov( "r#{reg+1}".to_sym , str_lit.length ) str_lit end @@ -50,7 +50,7 @@ module Arm end def main_start entry - entry << mov( :fp , right: 0 ) + entry << mov( :fp , 0 ) end def main_exit exit syscall(exit , 1) @@ -66,9 +66,9 @@ module Arm # assumes string in r0 and r1 and moves them along for the syscall def write_stdout block block.instance_eval do - mov( :r2 , right: :r1 ) - mov( :r1 , right: :r0 ) - mov( :r0 , right: 1 ) # 1 == stdout + mov( :r2 , :r1 ) + mov( :r1 , :r0 ) + mov( :r0 , 1 ) # 1 == stdout end syscall( block , 4 ) end @@ -97,7 +97,7 @@ module Arm end def syscall block , num - block << mov( :r7 , right: num ) + block << mov( :r7 , num ) block << swi( 0 , {}) Vm::Integer.new(0) #small todo, is this actually correct for all (that they return int) end diff --git a/lib/arm/move_instruction.rb b/lib/arm/move_instruction.rb index 4a1ad811..3dd0d722 100644 --- a/lib/arm/move_instruction.rb +++ b/lib/arm/move_instruction.rb @@ -3,8 +3,8 @@ module Arm class MoveInstruction < Vm::MoveInstruction include Arm::Constants - def initialize(first , attributes) - super(first , attributes) + def initialize(to , from , attributes) + super(to , from , attributes) @attributes[:update_status] = 0 if @attributes[:update_status] == nil @attributes[:condition_code] = :al if @attributes[:condition_code] == nil @attributes[:opcode] = attributes[:opcode] @@ -20,7 +20,7 @@ module Arm end def build - right = @attributes[:right] + right = @from if right.is_a?(Vm::StringConstant) # do pc relative addressing with the difference to the instuction # 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute) @@ -55,7 +55,7 @@ module Arm build instuction_class = 0b00 # OPC_DATA_PROCESSING val = shift(@operand , 0) - val |= shift(reg_code(@first) , 12) + val |= shift(reg_code(@to) , 12) val |= shift(reg_code(@rn) , 12+4) val |= shift(@attributes[:update_status] , 12+4+4)#20 val |= shift(op_bit_code , 12+4+4 +1) diff --git a/lib/core/kernel.rb b/lib/core/kernel.rb index bacb6871..58568044 100644 --- a/lib/core/kernel.rb +++ b/lib/core/kernel.rb @@ -42,13 +42,13 @@ module Core reg1 = Vm::Integer.new(1) itos_fun = context.program.get_or_create_function(:utoa) block.instance_eval do - mov( reg1 , right: str_addr ) #move arg up + mov( reg1 , str_addr ) #move arg up add( str_addr , buffer ,nil ) # string to write to add( str_addr , str_addr , (buffer.length-3)) call( itos_fun , {}) # And now we "just" have to print it, using the write_stdout - add( str_addr , left: buffer ) # string to write to - mov( reg1 , right: buffer.length ) + add( str_addr , buffer , nil ) # string to write to + mov( reg1 , buffer.length ) end ret = Vm::CMachine.instance.write_stdout(block) function diff --git a/lib/vm/c_machine.rb b/lib/vm/c_machine.rb index 165f8f7d..7c2e4bd9 100644 --- a/lib/vm/c_machine.rb +++ b/lib/vm/c_machine.rb @@ -51,7 +51,7 @@ module Vm define_instruction_three(inst , LogicInstruction) end [:mov, :mvn].each do |inst| - define_instruction_one(inst , MoveInstruction) + define_instruction_two(inst , MoveInstruction) end [:cmn, :cmp, :teq, :tst].each do |inst| define_instruction_two(inst , CompareInstruction) diff --git a/lib/vm/call_site.rb b/lib/vm/call_site.rb index 6a975393..6d0955a0 100644 --- a/lib/vm/call_site.rb +++ b/lib/vm/call_site.rb @@ -13,7 +13,7 @@ module Vm def load_args into args.each_with_index do |arg , index| - if arg.is_a? IntegerConstant + if arg.is_a?(IntegerConstant) or arg.is_a?(StringConstant) Vm::Integer.new(index).load into , arg else Vm::Integer.new(index).move( into, arg ) if arg.register != index diff --git a/lib/vm/instruction.rb b/lib/vm/instruction.rb index 3187efe3..7ad49ada 100644 --- a/lib/vm/instruction.rb +++ b/lib/vm/instruction.rb @@ -64,8 +64,9 @@ module Vm end end class MoveInstruction < Instruction - def initialize first , options - @first = first + def initialize to , from , options + @to = to + @from = from super(options) end end diff --git a/test/arm/test_move.rb b/test/arm/test_move.rb index 8fd9dd77..2847ee8e 100644 --- a/test/arm/test_move.rb +++ b/test/arm/test_move.rb @@ -4,11 +4,11 @@ class TestMoves < MiniTest::Test include ArmHelper def test_mov - code = @machine.mov :r0, right: 5 + code = @machine.mov :r0, 5 assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05 end def test_mvn - code = @machine.mvn :r1, right: 5 + code = @machine.mvn :r1, 5 assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05 end end diff --git a/test/runners/fibo_while.rb b/test/runners/fibo_while.rb index e9a1d035..6dccce9a 100644 --- a/test/runners/fibo_while.rb +++ b/test/runners/fibo_while.rb @@ -5,7 +5,7 @@ def fibonaccit(n) # n == r0 tmp = a # r3 <- r1 a = b # r1 <- r2 b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4 - tmp = inttos(b) + tmp = putint(b) putstring(tmp) n = n - 1 # r2 <- 0 ???? #call ok end #r5 <- r0 - 1 # r0 <- r5 diff --git a/test/test_small_program.rb b/test/test_small_program.rb index 80b592ec..64d257d6 100644 --- a/test/test_small_program.rb +++ b/test/test_small_program.rb @@ -14,7 +14,7 @@ class TestSmallProg < MiniTest::Test def test_loop @program.main.instance_eval do - mov :r0, right: 5 #1 + mov :r0, 5 #1 start = Vm::Block.new("start") add_code start start.instance_eval do @@ -29,10 +29,10 @@ class TestSmallProg < MiniTest::Test hello = Vm::StringConstant.new "Hello Raisa\n" @program.add_object hello @program.main.instance_eval do - mov :r7, right: 4 # 4 == write - mov :r0 , right: 1 # stdout + mov :r7, 4 # 4 == write + mov :r0 , 1 # stdout add :r1 , hello , nil # address of "hello Raisa" - mov :r2 , right: hello.length + mov :r2 , hello.length swi 0 , {} #software interupt, ie kernel syscall end write(7 + hello.length/4 + 1 , 'hello')