Class: Evoasm::Population::SeedBuilder
- Inherits:
-
Object
- Object
- Evoasm::Population::SeedBuilder
- Defined in:
- lib/evoasm/population/seed_builder.rb
Defined Under Namespace
Classes: Kernel
Instance Attribute Summary collapse
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#population ⇒ Object
readonly
Returns the value of attribute population.
Instance Method Summary collapse
- #allowed_instruction_name?(name) ⇒ Boolean
- #architecture ⇒ Object
-
#initialize(population, instructions, &block) ⇒ SeedBuilder
constructor
A new instance of SeedBuilder.
- #instruction_name?(name) ⇒ Boolean
- #kernel(&block) ⇒ Object
- #seed_population! ⇒ Object
Constructor Details
#initialize(population, instructions, &block) ⇒ SeedBuilder
Returns a new instance of SeedBuilder
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/evoasm/population/seed_builder.rb', line 72 def initialize(population, instructions, &block) @population = population @instructions = instructions case architecture when :x64 @jmp_cond_enum_type = Libevoasm.enum_type :x64_jmp_cond @inst_id_enum_type = Libevoasm.enum_type :x64_inst_id else raise end @kernels = [] instance_eval &block end |
Instance Attribute Details
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions
5 6 7 |
# File 'lib/evoasm/population/seed_builder.rb', line 5 def instructions @instructions end |
#population ⇒ Object (readonly)
Returns the value of attribute population
6 7 8 |
# File 'lib/evoasm/population/seed_builder.rb', line 6 def population @population end |
Instance Method Details
#allowed_instruction_name?(name) ⇒ Boolean
93 94 95 |
# File 'lib/evoasm/population/seed_builder.rb', line 93 def allowed_instruction_name?(name) @instructions.include? name end |
#architecture ⇒ Object
68 69 70 |
# File 'lib/evoasm/population/seed_builder.rb', line 68 def architecture @population.architecture end |
#instruction_name?(name) ⇒ Boolean
89 90 91 |
# File 'lib/evoasm/population/seed_builder.rb', line 89 def instruction_name?(name) !@inst_id_enum_type[name].nil? end |
#kernel(&block) ⇒ Object
97 98 99 |
# File 'lib/evoasm/population/seed_builder.rb', line 97 def kernel(&block) @kernels << Kernel.new(self, &block) end |
#seed_population! ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/evoasm/population/seed_builder.rb', line 41 def seed_population! kernels = Libevoasm.deme_kernels_alloc success = Libevoasm.deme_kernels_init kernels, @population.parameters, architecture, @kernels.size unless success Libevoasm.deme_kernels_free kernels raise Error.last end @kernels.each do |kernel, kernel_index| kernel.instructions.each_with_index do |instruction, instruction_index| inst_id, params_hash = instruction parameters = Evoasm::X64::BasicParameters.new(params_hash) Libevoasm.deme_kernels_set_inst kernels, kernel_index, instruction_index, inst_id, parameters end Libevoasm.deme_kernels_set_size kernels, kernel_index, kernel.instructions.size end success = Libevoasm.pop_seed @population, kernels Libevoasm.deme_kernels_free kernels unless success raise Error.last end end |