Class Voodoo::CommonCodeGenerator
In: voodoo/generators/common_code_generator.rb
Parent: Object

Common base class for code generators.

Code generators are expected to implement the following methods:

This class contains base implementations of some of these methods, which can be used and/or overridden by subclasses.

An example of how to use the code generators provided by this module is provided on the main page of the documentation of the Voodoo module.

Methods

Classes and Modules

Class Voodoo::CommonCodeGenerator::Environment

Public Class methods

Initializes the code generator. params shall be a hash containing parameters to the code generator, and shall at least contain the keys :architecture and :format, specifying the target architecture and output format, respectively.

Public Instance methods

Adds code to the given section.

Examples:

  add :code, [:return, 0]
  add :data, [:align], [:label, :xyzzy], [:word, 42]

This method implements the required functionality in terms of the following methods, which must be implemented by subclasses:

  • align
  • asr
  • bsr
  • byte
  • call
  • end_if
  • export
  • begin_function
  • block
  • ifelse
  • ifeq
  • ifge
  • ifgt
  • ifle
  • iflt
  • ifne
  • import
  • label
  • let
  • ret
  • rol
  • ror
  • set
  • set_byte
  • set_word
  • shl
  • shr
  • string
  • word

Add function.

Parameters:

formals
an Array of formal parameter names
code
an Array of actions to be used as the function‘s body

Example:

  add_function [:n], [:return, :add, :n, 1]

Processes code in its own block. Local variables can be introduced inside the block. They will be deleted at the end of the block.

Invokes block with each statement in the given list of statements. This iterator also descends into nested statements, calling block first with the outer statement, and then for each inner statement.

Add code to the current section

Returns a hash describing the features supported by this code generator. The keys in this hash are the names of the supported features. The associated values are strings providing additional information about the feature, such as a version number.

Generate a new, unused symbol

Returns true if a feature is supported by this generator, false otherwise.

Given an input file name, returns the canonical output file name for this code generator.

Returns the canonical output file suffix for this code generator

Get the real name of a section. Given a section name which may be an alias, this method returns the real name of the section.

Set the current section

Set up alias_name to refer to the same section as original_name.

[Validate]