2018-07-31 17:00:42 +02:00
|
|
|
module Minitest
|
2018-04-05 19:10:00 +02:00
|
|
|
module Assertions
|
2019-10-02 16:42:24 +02:00
|
|
|
def assert_tos string , object
|
|
|
|
assert_equal string , object.to_s.gsub("\n",";").gsub(/\s+/," ").gsub("; ",";")
|
|
|
|
end
|
2020-03-02 16:50:03 +01:00
|
|
|
def assert_register( kind , pattern , register)
|
|
|
|
return unless register
|
|
|
|
if(pattern.is_a?(Symbol))
|
|
|
|
assert_equal( pattern , register.symbol , "wrong #{kind} register:#{register}")
|
|
|
|
else
|
|
|
|
is_parts = pattern.split(".")
|
|
|
|
reg_parts = register.symbol.to_s.split(".")
|
|
|
|
assert_equal reg_parts.length , is_parts.length , "wrong dot length for #{pattern}"
|
|
|
|
is_parts.each_with_index do |part , index|
|
|
|
|
assert reg_parts[index].start_with?(part) , "wrong #{kind}, at:#{part} register:#{register}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-05 19:10:00 +02:00
|
|
|
def assert_slot_to_reg( slot , array = nil, index = nil , register = nil)
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal Risc::SlotToReg , slot.class
|
2020-03-02 16:50:03 +01:00
|
|
|
assert_register( :source , array , slot.array)
|
2018-04-05 19:37:03 +02:00
|
|
|
assert_equal( index , slot.index, "wrong source index") if index
|
2020-03-02 16:50:03 +01:00
|
|
|
assert_register( :destination , register , slot.register )
|
2018-04-05 19:37:03 +02:00
|
|
|
end
|
|
|
|
def assert_reg_to_slot( slot , register = nil, array = nil, index = nil )
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal Risc::RegToSlot , slot.class
|
2020-03-02 16:50:03 +01:00
|
|
|
assert_register( :source , register , slot.register )
|
|
|
|
assert_register( :destination , array , slot.array)
|
2018-04-05 19:37:03 +02:00
|
|
|
assert_equal( index , slot.index, "wrong destination index") if index
|
2018-04-05 19:10:00 +02:00
|
|
|
end
|
|
|
|
def assert_load(load , clazz = nil , register = nil)
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal Risc::LoadConstant , load.class
|
2018-04-05 19:10:00 +02:00
|
|
|
assert_equal( clazz , load.constant.class) if clazz
|
2020-03-01 17:07:42 +01:00
|
|
|
if register
|
2020-03-02 16:50:03 +01:00
|
|
|
assert_register(:source , register , load.register)
|
2020-03-01 17:07:42 +01:00
|
|
|
else
|
2020-03-02 16:50:03 +01:00
|
|
|
raise "rewrite"
|
2020-03-01 17:07:42 +01:00
|
|
|
end
|
2018-04-05 19:10:00 +02:00
|
|
|
end
|
2018-08-15 16:52:21 +02:00
|
|
|
def assert_transfer( transfer , from , to)
|
|
|
|
assert_equal Risc::Transfer , transfer.class
|
2020-03-02 16:50:03 +01:00
|
|
|
assert_register( :source , from , transfer.from )
|
|
|
|
assert_register( :destination , to , transfer.to )
|
2018-08-15 16:52:21 +02:00
|
|
|
end
|
2019-09-15 16:44:35 +02:00
|
|
|
def assert_label( label , name )
|
|
|
|
assert_equal Risc::Label , label.class
|
|
|
|
if(name[-1] == "_")
|
|
|
|
assert label.name.start_with?(name) , "Label does not start with #{name}:#{label.name}"
|
|
|
|
else
|
|
|
|
assert_equal name , label.name
|
|
|
|
end
|
|
|
|
end
|
2019-09-17 09:18:45 +02:00
|
|
|
def assert_branch( branch , label_name )
|
|
|
|
assert_equal Risc::Branch , branch.class
|
|
|
|
assert_label branch.label , label_name
|
|
|
|
end
|
|
|
|
def assert_operator ins , op , left , right
|
|
|
|
assert_equal Risc::OperatorInstruction , ins.class
|
|
|
|
assert_equal op , ins.operator
|
2020-03-02 16:50:03 +01:00
|
|
|
assert_register :left , left , ins.left
|
|
|
|
assert_register :right , right , ins.right
|
2019-09-17 09:18:45 +02:00
|
|
|
end
|
|
|
|
def assert_zero ins , label
|
|
|
|
assert_equal Risc::IsZero , ins.class
|
|
|
|
assert_label ins.label , label
|
|
|
|
end
|
|
|
|
def assert_syscall ins , name
|
|
|
|
assert_equal Risc::Syscall , ins.class
|
|
|
|
assert_equal ins.name , name
|
|
|
|
end
|
|
|
|
|
2018-04-05 19:10:00 +02:00
|
|
|
end
|
|
|
|
end
|