Module: OrigenTesters::Decompiler::API
- Included in:
- OrigenTesters, SmartestBasedTester, Test::Decompiler::Dummy
- Defined in:
- lib/origen_testers/decompiler/decompiler_api.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_pins(pattern, options = {}) ⇒ Object
-
#decompile(pattern, options = {}) ⇒ Object
Decompiles the given pattern, returning.
-
#decompile_text(text, decompiler: nil) ⇒ Object
(also: #decompile_str, #decompile_string, #decompile_raw_input)
Creates a decompiled pattern from the raw input directly.
- #decompiled_pattern(pattern, options = {}) ⇒ Object
-
#decompiler_for?(pattern = nil, options = {}) ⇒ Boolean
Queries if a decompiler is available for the given pattern.
- #execute(pattern, options = {}) ⇒ Object
-
#register_decompiler(mod) ⇒ TrueClass, FalseClass
Registers a new decompiler module.
-
#registered_decompiler?(mod) ⇒ Boolean
Queries if the decompiler in mod has been registered.
-
#registered_decompilers ⇒ Object
Returns all the registered decompiler modules.
-
#select_decompiler(pattern = nil, options = {}) ⇒ Object
(also: #decompiler, #decompiler_for)
Returns the decompiler module that will be uesd to decompile the given pattern source.
- #select_decompiler!(pattern = nil, options = {}) ⇒ Object (also: #decompiler!, #decompiler_for!)
-
#verify_decompiler_mod!(mod) ⇒ Object
Verifies that the registered decompiler has the required methods available.
Class Method Details
.convert(pattern) ⇒ Object
159 160 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 159 def self.convert(pattern) end |
Instance Method Details
#add_pins(pattern, options = {}) ⇒ Object
155 156 157 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 155 def add_pins(pattern, = {}) decompile(pattern, ).add_pins end |
#decompile(pattern, options = {}) ⇒ Object
Decompiles the given pattern, returning
7 8 9 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 7 def decompile(pattern, = {}) decompiled_pattern(pattern, ).decompile end |
#decompile_text(text, decompiler: nil) ⇒ Object Also known as: decompile_str, decompile_string, decompile_raw_input
Creates a decompiled pattern from the raw input directly. In this case, no attempts to figure out the decompiler are made. The suitable decompiler should either be given with the :decompiler parameter, or the current environment will be used.
23 24 25 26 27 28 29 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 23 def decompile_text(text, decompiler: nil) if decompiler.nil? select_decompiler!.new(text, direct_source: true).decompile else decompiler.new(text, direct_source: true).decompile end end |
#decompiled_pattern(pattern, options = {}) ⇒ Object
This method is the same as #decompile except that the module's #decompile method won't be automatically called.
13 14 15 16 17 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 13 def decompiled_pattern(pattern, = {}) # decompiler!(pattern).decompiled_pattern(pattern) _decompiler = .delete(:decompiler) _decompiler.nil? ? decompiler!(pattern).new(pattern, ) : _decompiler.new(pattern, ) end |
#decompiler_for?(pattern = nil, options = {}) ⇒ Boolean
Queries if a decompiler is available for the given pattern.
138 139 140 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 138 def decompiler_for?(pattern = nil, = {}) !select_decompiler(pattern, ).nil? end |
#execute(pattern, options = {}) ⇒ Object
151 152 153 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 151 def execute(pattern, = {}) decompile(pattern, ).execute() end |
#register_decompiler(mod) ⇒ TrueClass, FalseClass
Registers a new decompiler module.
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 111 def register_decompiler(mod) if mod.is_a?(String) mod = eval(mod) end if registered_decompiler?(mod) false else verify_decompiler_mod!(mod) registered_decompilers << mod true end end |
#registered_decompiler?(mod) ⇒ Boolean
Queries if the decompiler in mod has been registered.
143 144 145 146 147 148 149 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 143 def registered_decompiler?(mod) if mod.is_a?(String) mod = eval(mod) end registered_decompilers.include?(mod) end |
#registered_decompilers ⇒ Object
Registered decompilers are stored on the OrigenTesters::Decompiler module.
Returns all the registered decompiler modules.
101 102 103 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 101 def registered_decompilers OrigenTesters::Decompiler::API.instance_variable_get(:@registered_decompilers) end |
#select_decompiler(pattern = nil, options = {}) ⇒ Object Also known as: decompiler, decompiler_for
Returns the decompiler module that will be uesd to decompile the given pattern source.
36 37 38 39 40 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 67 68 69 70 71 72 73 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 36 def select_decompiler(pattern = nil, = {}) if pattern.is_a?(Hash) = pattern pattern = nil elsif pattern.nil? = {} pattern = nil end # if respond_to?(:suitable_decompiler_for) # puts "HI".red # puts self # registered_decompilers = [self] # end _registered_decompilers = respond_to?(:suitable_decompiler_for) ? [self] : registered_decompilers # We have the list of modules that support decompilation, but those modules # could have sub-modules that support other decompilation flavors. # We'll select the decompiler by just iterating through each support # decompiler and until we find one that supports either the file extension, # or the current tester name. _registered_decompilers.each do |m| if pattern mod = m.suitable_decompiler_for(pattern: pattern, **) elsif tester.nil? return nil else mod = m.suitable_decompiler_for(tester: Origen.tester.name.to_s, **) end if mod return mod end end nil end |
#select_decompiler!(pattern = nil, options = {}) ⇒ Object Also known as: decompiler!, decompiler_for!
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 77 def select_decompiler!(pattern = nil, = {}) mod = select_decompiler(pattern, ) if mod.nil? && pattern # Origen.log.error "Unknown decompiler for file extension '#{File.extname(pattern)}'" Origen.app!.fail( message: "Cannot find a suitable decompiler for pattern source '#{pattern}' ('#{File.extname(pattern)}')", exception_class: OrigenTesters::Decompiler::NoSuitableDecompiler ) elsif mod.nil? # Origen.log.error "Unknown decompiler for tester #{Origen.tester.name}" # fail "Current environment '#{Orige.current_environment}' does not contain a suitable decompiler! Cannot select this as the decompiler." Origen.app!.fail( message: "Current environment '#{Origen.environment.file.basename}' does not contain a suitable decompiler! Cannot select this as the decompiler.", exception_class: OrigenTesters::Decompiler::NoSuitableDecompiler ) end mod end |
#verify_decompiler_mod!(mod) ⇒ Object
Verifies that the registered decompiler has the required methods available. Namely: #select_decompiler and #decompiled_pattern
127 128 129 130 131 132 133 134 135 |
# File 'lib/origen_testers/decompiler/decompiler_api.rb', line 127 def verify_decompiler_mod!(mod) unless mod.respond_to?(:suitable_decompiler_for) Origen.app!.fail( exception_class: OrigenTesters::Decompiler::NoMethodError, message: "No method #suitable_decompiler_for found on #{mod}. Cannot register as a decompiler." ) end true end |