2018-03-26 19:04:39 +02:00
|
|
|
require "util/list"
|
|
|
|
module Arm
|
|
|
|
# Arm instruction base class
|
|
|
|
# Mostly linked list functionality that all instructions have
|
|
|
|
class Instruction
|
|
|
|
include Constants
|
|
|
|
include Attributed
|
|
|
|
include Util::List
|
|
|
|
|
|
|
|
def initialize( source , nekst = nil )
|
|
|
|
@source = source
|
|
|
|
@next = nekst
|
|
|
|
return unless source
|
|
|
|
raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or source.is_a?(Mom::Instruction)
|
|
|
|
end
|
|
|
|
attr_reader :source
|
|
|
|
|
|
|
|
def total_byte_length
|
|
|
|
ret = 0
|
|
|
|
self.each{|ins| ret += ins.byte_length}
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
|
2018-05-05 22:55:50 +02:00
|
|
|
def insert(instruction)
|
|
|
|
super
|
2018-05-06 18:56:36 +02:00
|
|
|
my_pos = Risc::Position.position(self)
|
|
|
|
@next.set_position( my_pos + self.byte_length , 0 , my_pos.binary)
|
2018-05-05 22:55:50 +02:00
|
|
|
end
|
|
|
|
|
2018-05-06 18:56:36 +02:00
|
|
|
def set_position( position , count , extra = nil)
|
|
|
|
Risc::Position.set_position(self,position , extra)
|
2018-03-26 19:04:39 +02:00
|
|
|
position += byte_length
|
|
|
|
if self.next
|
2018-05-05 18:32:01 +02:00
|
|
|
count += 1 #assumes 4 byte instructions, as does the whole setup
|
|
|
|
if( 0 == count % 12) # 12 is the amount of instructions that fit into a BinaryCode
|
|
|
|
count = 0
|
|
|
|
position += 12 # 12=3*4 , 3 for marker,type,next words to jump over
|
|
|
|
end
|
2018-05-06 18:56:36 +02:00
|
|
|
self.next.set_position( position , count , extra)
|
2018-03-26 19:04:39 +02:00
|
|
|
else
|
|
|
|
position
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|