2018-05-17 08:31:36 +02:00
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterPlatform
|
|
|
|
def translator
|
|
|
|
IdentityTranslator.new
|
|
|
|
end
|
|
|
|
def loaded_at
|
|
|
|
0x90
|
|
|
|
end
|
|
|
|
def padding
|
|
|
|
0x100 - loaded_at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class Instruction
|
|
|
|
def nil_next
|
|
|
|
@next = nil
|
2018-05-23 17:06:55 +02:00
|
|
|
self
|
2018-05-17 08:31:36 +02:00
|
|
|
end
|
|
|
|
def byte_length
|
|
|
|
4
|
|
|
|
end
|
|
|
|
def assemble(io)
|
2018-05-17 08:49:01 +02:00
|
|
|
pos = Position.get(self).at
|
|
|
|
io.write_unsigned_int_32(pos)
|
2018-05-17 08:31:36 +02:00
|
|
|
end
|
|
|
|
class Branch < Instruction
|
2018-05-17 08:49:01 +02:00
|
|
|
def first #some logging assumes arm
|
2018-05-17 08:31:36 +02:00
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class IdentityTranslator
|
|
|
|
def translate(code)
|
2018-05-23 17:06:55 +02:00
|
|
|
case code
|
|
|
|
when Branch
|
2018-05-25 18:04:48 +02:00
|
|
|
new_label = code.label.is_a?(Label) ? code.label.to_cpu(self) : code.label
|
|
|
|
ret = code.class.new(code.source , new_label)
|
2018-05-24 18:20:06 +02:00
|
|
|
when LoadConstant
|
|
|
|
const = code.constant
|
|
|
|
const = const.to_cpu(self) if const.is_a?(Label)
|
|
|
|
ret = LoadConstant.new(code.source , const , code.register)
|
2018-05-23 17:06:55 +02:00
|
|
|
else
|
|
|
|
ret = code.dup
|
2018-05-17 19:14:59 +02:00
|
|
|
end
|
2018-05-24 18:20:06 +02:00
|
|
|
ret.nil_next
|
2018-05-17 08:31:36 +02:00
|
|
|
ret
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|