Class: Evoasm::Kernel
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Evoasm::Kernel
- Defined in:
- lib/evoasm/kernel.rb,
lib/evoasm/kernel/io.rb
Overview
Represents a kernel comprising one ore multiple kernels
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#disassemble(frame = false, format: false) ⇒ String+
Disassembles the whole kernel.
-
#disassemble_kernel(kernel_index) ⇒ String
Gives the disassembly for the specified kernel.
-
#disassemble_kernels ⇒ Array<String>
Gives the disassembly for all kernels in the kernel.
-
#eliminate_introns ⇒ Kernel
Eliminates intron instructions (instructions without effect).
-
#input_arity ⇒ Integer
Gives the input arity, i.e.
-
#input_mapping ⇒ Hash<Symbol, Integer>
Gives the mapping of input arguments to input registers of this kernel.
-
#input_registers ⇒ Array<Symbol>
Gives the input registers of this kernel.
-
#input_types ⇒ Array<Symbol>
Gives the kernel's input type.
-
#output_arity ⇒ Integer
Gives the output arity, i.e.
-
#output_registers ⇒ Array<Symbol>
Gives the output registers of this kernel.
-
#output_types ⇒ Array<Symbol>
Gives the kernel's output type.
-
#run(*input_tuple) ⇒ Array
Runs the kernel with the given input.
-
#run_all(*input_examples) ⇒ Array
Like #run, but runs multiple input tuples at once.
-
#size ⇒ Integer
Gives the size of the kernel as the number of instructions.
Class Method Details
.wrap(ptr) ⇒ Object
12 13 14 |
# File 'lib/evoasm/kernel.rb', line 12 def self.wrap(ptr) new ptr end |
Instance Method Details
#disassemble(frame = false, format: false) ⇒ String+
Disassembles the whole kernel
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/evoasm/kernel.rb', line 164 def disassemble(frame = false, format: false) code_ptr_ptr = FFI::MemoryPointer.new :pointer code_len = Libevoasm.kernel_get_code self, frame, code_ptr_ptr code_ptr = code_ptr_ptr.read_pointer code = code_ptr.read_string(code_len) disasm = X64.disassemble code, code_ptr.address if format format_disassembly disasm else disasm end end |
#disassemble_kernel(kernel_index) ⇒ String
Gives the disassembly for the specified kernel
97 98 99 100 101 102 103 104 |
# File 'lib/evoasm/kernel.rb', line 97 def disassemble_kernel(kernel_index) code_ptr_ptr = FFI::MemoryPointer.new :pointer code_len = Libevoasm.kernel_get_kernel_code self, kernel_index, code_ptr_ptr code_ptr = code_ptr_ptr.read_pointer code = code_ptr.read_string(code_len) X64.disassemble code, code_ptr.address end |
#disassemble_kernels ⇒ Array<String>
Gives the disassembly for all kernels in the kernel
108 109 110 111 112 |
# File 'lib/evoasm/kernel.rb', line 108 def disassemble_kernels Array.new(size) do |kernel_index| disassemble_kernel kernel_index end end |
#eliminate_introns ⇒ Kernel
Eliminates intron instructions (instructions without effect)
85 86 87 88 89 90 91 92 |
# File 'lib/evoasm/kernel.rb', line 85 def eliminate_introns kernel = Libevoasm.kernel_alloc unless Libevoasm.kernel_elim_introns self, kernel raise Error.last end self.class.wrap kernel end |
#input_arity ⇒ Integer
Gives the input arity, i.e. the number of arguments
31 32 33 |
# File 'lib/evoasm/kernel.rb', line 31 def input_arity Libevoasm.kernel_get_input_arity self end |
#input_mapping ⇒ Hash<Symbol, Integer>
Gives the mapping of input arguments to input registers of this kernel
138 139 140 141 142 |
# File 'lib/evoasm/kernel.rb', line 138 def input_mapping io_registers(true).each_with_object({}) do |reg, mapping| mapping[reg] = Libevoasm.kernel_get_reg_input_mapping(self, reg) end end |
#input_registers ⇒ Array<Symbol>
Gives the input registers of this kernel
132 133 134 |
# File 'lib/evoasm/kernel.rb', line 132 def input_registers io_registers true end |
#input_types ⇒ Array<Symbol>
Gives the kernel's input type
45 46 47 48 49 |
# File 'lib/evoasm/kernel.rb', line 45 def input_types Array.new(self.input_arity) do |index| Libevoasm.kernel_get_input_type self, index end end |
#output_arity ⇒ Integer
Gives the output arity, i.e. the number of return values
37 38 39 |
# File 'lib/evoasm/kernel.rb', line 37 def output_arity Libevoasm.kernel_get_output_arity self end |
#output_registers ⇒ Array<Symbol>
Gives the output registers of this kernel
146 147 148 149 150 151 |
# File 'lib/evoasm/kernel.rb', line 146 def output_registers reg_enum_type = Libevoasm.enum_type(:x64_reg_id) Array.new(Libevoasm.kernel_get_arity self) do |index| reg_enum_type[Libevoasm.kernel_get_output_reg(self, index)] end end |
#output_types ⇒ Array<Symbol>
Gives the kernel's output type
55 56 57 58 59 |
# File 'lib/evoasm/kernel.rb', line 55 def output_types Array.new(self.output_arity) do |index| Libevoasm.kernel_get_output_type self, index end end |
#run(*input_tuple) ⇒ Array
Runs the kernel with the given input
25 26 27 |
# File 'lib/evoasm/kernel.rb', line 25 def run(*input_tuple) run_all(input_tuple).first end |
#run_all(*input_examples) ⇒ Array
Like #run, but runs multiple input tuples at once
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/evoasm/kernel.rb', line 64 def run_all(*input_examples) input = Kernel::Input.new(input_examples, self.input_types) output_ptr = Libevoasm.kernel_io_alloc success = Libevoasm.kernel_run self, input, output_ptr unless success raise Error.last end Kernel::Output.new(output_ptr, self.output_types).to_a end |
#size ⇒ Integer
Gives the size of the kernel as the number of instructions
79 80 81 |
# File 'lib/evoasm/kernel.rb', line 79 def size Libevoasm.kernel_get_size self end |