named the first intruction constructor argument

This commit is contained in:
Torsten Ruger
2014-05-15 19:41:51 +03:00
parent b4c79d218f
commit a0f0d08e81
13 changed files with 78 additions and 77 deletions

View File

@ -11,46 +11,46 @@ module Arm
class ArmMachine < Vm::CMachine
def integer_less_or_equal block , left , right
block.add_code cmp(:left => left , :right => right )
block.add_code cmp( left , :right => right )
Vm::Bool.new
end
def integer_plus block , result , left , right
block.add_code add(:left => result , :right => left , :extra => right )
block.add_code add( result , :right => left , :extra => right )
result
end
def integer_minus block , result , left , right
block.add_code sub(:left => result , :right => left , :extra => right )
block.add_code sub( result , :right => left , :extra => right )
result
end
def integer_load block , left , right
block.add_code mov( :left => left , :right => right )
block.add_code mov( left , :right => right )
left
end
def integer_move block , left , right
block.add_code mov( :left => left , :right => right )
block.add_code mov( left , :right => right )
left
end
def string_load block , str_lit , reg
block.add_code add( :left => "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
block.add_code add( "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
#second arg is a hack to get the stringlength without coding
block.add_code mov( :left => "r#{reg+1}".to_sym , :right => str_lit.length )
block.add_code mov( "r#{reg+1}".to_sym , :right => str_lit.length )
str_lit
end
def function_call into , call
raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite
raise "Not linked #{call.inspect}" unless call.function
into.add_code call( :left => call.function )
into.add_code call( call.function )
call.function.return_type
end
def main_start entry
entry.add_code mov( :left => :fp , :right => 0 )
entry.add_code mov( :fp , :right => 0 )
end
def main_exit exit
syscall(exit , 1)
@ -61,14 +61,14 @@ module Arm
block
end
def function_exit entry , f_name
entry.add_code mov( :left => :pc , :right => :lr )
entry.add_code mov( :pc , :right => :lr )
end
# assumes string in r0 and r1 and moves them along for the syscall
def write_stdout block
block.add_code mov( :left => :r2 , :right => :r1 )
block.add_code mov( :left => :r1 , :right => :r0 )
block.add_code mov( :left => :r0 , :right => 1 ) # 1 == stdout
block.add_code mov( :r2 , :right => :r1 )
block.add_code mov( :r1 , :right => :r0 )
block.add_code mov( :r0 , :right => 1 ) # 1 == stdout
syscall( block , 4 )
end
@ -110,7 +110,7 @@ module Arm
# takes argument in r1
# returns quotient in r1, remainder in r2
# SUB r2, r1, #10 # keep (x-10) for later
block.add_code sub(:left => remainder , :right => number , :extra => 10 )
block.add_code sub( remainder , :right => number , :extra => 10 )
# SUB r1, r1, r1, lsr #2
# ADD r1, r1, r1, lsr #4
# ADD r1, r1, r1, lsr #8
@ -124,8 +124,8 @@ module Arm
end
def syscall block , num
block.add_code mov( :left => :r7 , :right => num )
block.add_code swi( :left => 0 )
block.add_code mov( :r7 , :right => num )
block.add_code swi( 0 , {})
Vm::Integer.new(0) #small todo, is this actually correct for all (that they return int)
end