2018-03-26 19:04:39 +02:00
|
|
|
require "util/list"
|
2018-06-17 12:53:17 +02:00
|
|
|
require "util/dev_null"
|
|
|
|
|
2018-03-26 19:04:39 +02:00
|
|
|
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-06-17 12:53:17 +02:00
|
|
|
# precheck that everything is ok, before asembly
|
|
|
|
# in arm, we use the oppertunity to assemble to dev_null, so any
|
|
|
|
# additions are done _before_ assemnly
|
|
|
|
def precheck
|
|
|
|
assemble(Util::DevNull.new)
|
|
|
|
end
|
|
|
|
|
2018-05-05 22:55:50 +02:00
|
|
|
def insert(instruction)
|
2018-06-06 09:00:07 +02:00
|
|
|
ret = super
|
|
|
|
Risc::Position.get(self).trigger_inserted if Risc::Position.set?(self)
|
|
|
|
ret
|
2018-05-05 22:55:50 +02:00
|
|
|
end
|
2018-03-26 19:04:39 +02:00
|
|
|
end
|
|
|
|
end
|