Class: Indis::ARM::Instruction
- Inherits:
-
Entity
- Object
- Entity
- Indis::ARM::Instruction
- Defined in:
- lib/indis-arm/instruction.rb
Overview
ARM::Instruction is a code entity that represens an ARM instruction
Direct Known Subclasses
Class Attribute Summary collapse
-
.encoding ⇒ String
readonly
Instruction encoding per ARMARM.
-
.formats ⇒ Hash
readonly
Output formats.
-
.name ⇒ String
readonly
Instruction name.
-
.process_automap ⇒ Array
readonly
A list of automapping procs.
-
.process_block ⇒ Proc
readonly
Data-processing proc.
Instance Attribute Summary collapse
-
#value_format ⇒ Symbol
Instructions can have different value formats.
Class Method Summary collapse
-
.bits_mask ⇒ String
Instruction mask bits.
-
.bits_match ⇒ String
Instruction matching bits.
-
.kmap(v) ⇒ OpenStruct
A map of known fields to instruction value.
Instance Method Summary collapse
-
#h ⇒ Indis::ARM::InstructionHelper
Helper that provides common methods for DSL.
-
#initialize(vmaddr, bytes) ⇒ Instruction
constructor
A new instance of Instruction.
- #to_s ⇒ Object
Constructor Details
#initialize(vmaddr, bytes) ⇒ Instruction
Returns a new instance of Instruction.
36 37 38 39 40 41 42 |
# File 'lib/indis-arm/instruction.rb', line 36 def initialize(vmaddr, bytes) super vmaddr @size = 4 m = self.class.kmap(bytes) self.class.process_automap.each { |p| self.instance_exec(m, &p) } if self.class.process_automap self.instance_exec(m, &self.class.process_block) if self.class.process_block end |
Class Attribute Details
.encoding ⇒ String (readonly)
Returns instruction encoding per ARMARM.
64 65 66 |
# File 'lib/indis-arm/instruction.rb', line 64 def encoding @encoding end |
.formats ⇒ Hash (readonly)
Returns output formats.
68 69 70 |
# File 'lib/indis-arm/instruction.rb', line 68 def formats @formats end |
.name ⇒ String (readonly)
Returns instruction name.
62 63 64 |
# File 'lib/indis-arm/instruction.rb', line 62 def name @name end |
.process_automap ⇒ Array (readonly)
Returns a list of automapping procs.
70 71 72 |
# File 'lib/indis-arm/instruction.rb', line 70 def process_automap @process_automap end |
.process_block ⇒ Proc (readonly)
Returns data-processing proc.
66 67 68 |
# File 'lib/indis-arm/instruction.rb', line 66 def process_block @process_block end |
Instance Attribute Details
#value_format ⇒ Symbol
Instructions can have different value formats. In such a case, value_format specifies the format to use
32 33 34 |
# File 'lib/indis-arm/instruction.rb', line 32 def value_format @value_format end |
Class Method Details
.bits_mask ⇒ String
Returns instruction mask bits.
73 74 75 |
# File 'lib/indis-arm/instruction.rb', line 73 def bits_mask @bits.gsub('0', '1').gsub(/[^1]/, '0').to_i(2) end |
.bits_match ⇒ String
Returns instruction matching bits.
78 79 80 |
# File 'lib/indis-arm/instruction.rb', line 78 def bits_match @bits.gsub(/[^01]/, '0').to_i(2) end |
.kmap(v) ⇒ OpenStruct
Returns a map of known fields to instruction value.
83 84 85 86 87 88 89 90 91 |
# File 'lib/indis-arm/instruction.rb', line 83 def kmap(v) return OpenStruct.new unless @kmap map = @kmap.inject({}) do |map, (m, o, n)| map[n] = (v & m) >> o map end OpenStruct.new(map) end |
Instance Method Details
#h ⇒ Indis::ARM::InstructionHelper
Returns helper that provides common methods for DSL.
45 46 47 |
# File 'lib/indis-arm/instruction.rb', line 45 def h InstructionHelper end |
#to_s ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/indis-arm/instruction.rb', line 49 def to_s s = self.instance_eval "\"#{self.class.formats[:operator]}\"" if @value_format fmt = self.class.formats[@value_format] v = self.instance_eval "\"#{fmt}\"" else v = self.instance_eval "\"#{self.class.formats[:value]}\"" if self.class.formats[:value] end s = "#{s}\t#{v}" if v s end |