fix some arguemnt names

This commit is contained in:
Torsten Ruger 2014-05-18 12:34:53 +03:00
parent 9fc8bfbb55
commit 76f1537174
5 changed files with 23 additions and 23 deletions

View File

@ -10,29 +10,29 @@ require_relative "constants"
module Arm module Arm
class ArmMachine < Vm::CMachine class ArmMachine < Vm::CMachine
def integer_less_or_equal block , first , right def integer_less_or_equal block , left , right
block << cmp( first , right ) block << cmp( left , right )
Vm::Bool.new Vm::Bool.new
end end
def integer_plus block , result , first , right def integer_plus block , result , left , right
block << add( result , first , right ) block << add( result , left , right )
result result
end end
def integer_minus block , result , first , right def integer_minus block , result , left , right
block << sub( result , first , right ) block << sub( result , left , right )
result result
end end
def integer_load block , first , right def integer_load block , to , from
block << mov( first , right ) block << mov( to , from )
first to
end end
def integer_move block , first , right def integer_move block , to , from
block << mov( first , right ) block << mov( to , from )
first to
end end
def string_load block , str_lit , reg def string_load block , str_lit , reg
@ -45,7 +45,7 @@ module Arm
def function_call into , call def function_call into , call
raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite
raise "Not linked #{call.inspect}" unless call.function raise "Not linked #{call.inspect}" unless call.function
into << call( call.function , {}) into << call( call.function )
call.function.return_type call.function.return_type
end end
@ -57,10 +57,10 @@ module Arm
exit exit
end end
def function_entry block, f_name def function_entry block, f_name
block << push( [:lr] , {}) block << push( [:lr] )
end end
def function_exit entry , f_name def function_exit entry , f_name
entry << pop( [:pc] , {}) entry << pop( [:pc] )
end end
# assumes string in r0 and r1 and moves them along for the syscall # assumes string in r0 and r1 and moves them along for the syscall
@ -98,7 +98,7 @@ module Arm
def syscall block , num def syscall block , num
block << mov( :r7 , num ) block << mov( :r7 , num )
block << swi( 0 , {}) block << swi( 0 )
Vm::Integer.new(0) #small todo, is this actually correct for all (that they return int) Vm::Integer.new(0) #small todo, is this actually correct for all (that they return int)
end end

View File

@ -45,7 +45,7 @@ module Core
mov( reg1 , str_addr ) #move arg up mov( reg1 , str_addr ) #move arg up
add( str_addr , buffer ,nil ) # string to write to add( str_addr , buffer ,nil ) # string to write to
add( str_addr , str_addr , (buffer.length-3)) add( str_addr , str_addr , (buffer.length-3))
call( itos_fun , {}) call( itos_fun )
# And now we "just" have to print it, using the write_stdout # And now we "just" have to print it, using the write_stdout
add( str_addr , buffer , nil ) # string to write to add( str_addr , buffer , nil ) # string to write to
mov( reg1 , buffer.length ) mov( reg1 , buffer.length )
@ -71,7 +71,7 @@ module Core
strb( remainder, right: str_addr ) strb( remainder, right: str_addr )
sub( str_addr, str_addr , 1 ) sub( str_addr, str_addr , 1 )
cmp( number , 0 ) cmp( number , 0 )
callne( function , {} ) callne( function )
end end
return function return function
end end

View File

@ -89,7 +89,7 @@ module Vm
# assemble in the same order as linked # assemble in the same order as linked
def assemble( io ) def assemble( io )
link_at( @position , {}) #second link in case of forward declarations link_at( @position , nil) #second link in case of forward declarations
@entry.assemble( io ) @entry.assemble( io )
@main.assemble( io ) @main.assemble( io )
@exit.assemble( io ) @exit.assemble( io )

View File

@ -7,7 +7,7 @@ class TestArmAsm < MiniTest::Test
# the address is what an assembler calculates (a signed number for the amount of instructions), # the address is what an assembler calculates (a signed number for the amount of instructions),
# ie the relative (to pc) address -8 (pipeline) /4 so save space # ie the relative (to pc) address -8 (pipeline) /4 so save space
# so the cpu adds the value*4 and starts loading that (load, decode, execute) # so the cpu adds the value*4 and starts loading that (load, decode, execute)
code = @machine.b -4 , {} #this jumps to the next instruction code = @machine.b -4 #this jumps to the next instruction
assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe
end end
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here) def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
@ -15,11 +15,11 @@ class TestArmAsm < MiniTest::Test
assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
end end
def test_push def test_push
code = @machine.push [:lr] , {} code = @machine.push [:lr]
assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00 assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00
end end
def test_pop def test_pop
code = @machine.pop [:pc] , {} code = @machine.pop [:pc]
assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00 assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00
end end
def test_swi def test_swi

View File

@ -33,7 +33,7 @@ class TestSmallProg < MiniTest::Test
mov :r0 , 1 # stdout mov :r0 , 1 # stdout
add :r1 , hello , nil # address of "hello Raisa" add :r1 , hello , nil # address of "hello Raisa"
mov :r2 , hello.length mov :r2 , hello.length
swi 0 , {} #software interupt, ie kernel syscall swi 0 #software interupt, ie kernel syscall
end end
write(7 + hello.length/4 + 1 , 'hello') write(7 + hello.length/4 + 1 , 'hello')
end end