aliased add_code to <<, to give a bit of the stream feel
This commit is contained in:
parent
53666e8b33
commit
7b1b2c5d87
@ -11,56 +11,56 @@ module Arm
|
|||||||
class ArmMachine < Vm::CMachine
|
class ArmMachine < Vm::CMachine
|
||||||
|
|
||||||
def integer_less_or_equal block , first , right
|
def integer_less_or_equal block , first , right
|
||||||
block.add_code cmp( first , right: right )
|
block << cmp( first , right: right )
|
||||||
Vm::Bool.new
|
Vm::Bool.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_plus block , result , first , right
|
def integer_plus block , result , first , right
|
||||||
block.add_code add( result , left: first , :extra => right )
|
block << add( result , left: first , :extra => right )
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_minus block , result , first , right
|
def integer_minus block , result , first , right
|
||||||
block.add_code sub( result , left: first , :extra => right )
|
block << sub( result , left: first , :extra => right )
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_load block , first , right
|
def integer_load block , first , right
|
||||||
block.add_code mov( first , right: right )
|
block << mov( first , right: right )
|
||||||
first
|
first
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_move block , first , right
|
def integer_move block , first , right
|
||||||
block.add_code mov( first , right: right )
|
block << mov( first , right: right )
|
||||||
first
|
first
|
||||||
end
|
end
|
||||||
|
|
||||||
def string_load block , str_lit , reg
|
def string_load block , str_lit , reg
|
||||||
block.add_code add( "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
|
block << add( "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
|
||||||
#second arg is a hack to get the stringlength without coding
|
#second arg is a hack to get the stringlength without coding
|
||||||
block.add_code mov( "r#{reg+1}".to_sym , right: str_lit.length )
|
block << mov( "r#{reg+1}".to_sym , right: str_lit.length )
|
||||||
str_lit
|
str_lit
|
||||||
end
|
end
|
||||||
|
|
||||||
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.add_code call( call.function , {})
|
into << call( call.function , {})
|
||||||
call.function.return_type
|
call.function.return_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def main_start entry
|
def main_start entry
|
||||||
entry.add_code mov( :fp , right: 0 )
|
entry << mov( :fp , right: 0 )
|
||||||
end
|
end
|
||||||
def main_exit exit
|
def main_exit exit
|
||||||
syscall(exit , 1)
|
syscall(exit , 1)
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
def function_entry block, f_name
|
def function_entry block, f_name
|
||||||
block.add_code push( [:lr] , {})
|
block << push( [:lr] , {})
|
||||||
end
|
end
|
||||||
def function_exit entry , f_name
|
def function_exit entry , f_name
|
||||||
entry.add_code 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
|
||||||
@ -97,8 +97,8 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def syscall block , num
|
def syscall block , num
|
||||||
block.add_code mov( :r7 , right: num )
|
block << mov( :r7 , right: num )
|
||||||
block.add_code 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
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ module Vm
|
|||||||
@codes << kode
|
@codes << kode
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
alias :<< :add_code
|
||||||
|
|
||||||
def link_at pos , context
|
def link_at pos , context
|
||||||
@position = pos
|
@position = pos
|
||||||
|
Loading…
x
Reference in New Issue
Block a user