remove io.write_unsigned_8

and replace with write_unsigned_32, so that is the only used
method from the stream
Next up, replace the actual “stream” with a binary code writer
This commit is contained in:
Torsten Ruger 2018-03-27 19:37:52 +03:00
parent 4069397fca
commit 2e57674008

View File

@ -60,20 +60,20 @@ module Arm
def write_call(arg,io) def write_call(arg,io)
raise "else not Attributed arg =\n#{arg.to_s[0..1000]}: #{inspect[0..1000]}" unless (arg.is_a?(Numeric)) raise "else not Attributed arg =\n#{arg.to_s[0..1000]}: #{inspect[0..1000]}" unless (arg.is_a?(Numeric))
jmp_val = arg >> 2 val = (arg >> 2) & 0xFFFFFF
packed = [jmp_val].pack('l') raise "too big #{val}" if (val & 0xFFFFFFFF000000) != 0
# signed 32-bit, condense to 24-bit val |= shift(op_bit_code , 24)
# TODO add check that the value fits into 24 bits val |= shift(COND_CODES[@attributes[:condition_code]] , 28)
io << packed[0,3] io.write_unsigned_int_32( val )
io.write_unsigned_int_8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4)
end end
def handle_swi(io) def handle_swi(io)
arg = @first arg = @first
raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric)) raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric))
packed = [arg].pack('L')[0,3] val = arg & 0xFFFFFF
io << packed val |= shift(0b1111 , 24)
io.write_unsigned_int_8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4) val |= shift(COND_CODES[@attributes[:condition_code]] , 28)
io.write_unsigned_int_32 val
end end
def to_s def to_s