Module for selecting code generators.
The code generation API is described in Voodoo::CommonCodeGenerator.
Tests if a given architecture is supported.
# File voodoo/code_generator.rb, line 49 def architecture_supported? arch @@generators.has_key? arch.to_sym end
Gets an array of supported architectures.
# File voodoo/code_generator.rb, line 54 def architectures @@generators.keys end
Tests if a given format is supported for a given architecture.
# File voodoo/code_generator.rb, line 59 def format_supported? arch, format architecture_supported?(arch.to_sym) && @@generators[arch.to_sym].has_key?(format.to_sym) end
Gets an array of supported formats for a given architecture.
# File voodoo/code_generator.rb, line 65 def formats architecture @@generators[architecture.to_sym].keys end
Gets a code generator for the specified parameters.
# File voodoo/code_generator.rb, line 33 def get_generator params = {} params[:architecture] = Config.default_architecture unless params[:architecture] params[:format] = Config.default_format unless params[:format] arch = params[:architecture].to_sym format = params[:format].to_sym format_hash = @@generators[arch] klass = format_hash ? format_hash[format] : nil if klass return klass.new params else raise NotImplementedError, "No code generator for architecture #{arch} and format #{format}" end end
Registers a code generator. Example:
Voodoo::CodeGenerator.register_generator I386NasmGenerator, :architecture => :i386, :format => :nasm
# File voodoo/code_generator.rb, line 20 def register_generator klass, params if params.has_key?(:architecture) && params.has_key?(:format) arch = params[:architecture].to_sym format = params[:format].to_sym format_hash = @@generators[arch] || {} format_hash[format] = klass @@generators[arch] = format_hash else raise ArgumentError, "Need to specify :architecture and :format" end end
Generated with the Darkfish Rdoc Generator 2.